Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rRxdI-00ASOJ-SM for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Jan 2024 16:58:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rRxdH-005Cnr-RD for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Jan 2024 16:58:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rRxdG-005Cnh-WA for pgsql-hackers@lists.postgresql.org; Mon, 22 Jan 2024 16:58:47 +0000 Received: from m12.mail.163.com ([220.181.12.198]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rRxdA-0039Yb-5e for pgsql-hackers@lists.postgresql.org; Mon, 22 Jan 2024 16:58:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=oxdKoU+JpOanry7vSSNM8CH2gG0OOsuULEPb2dyn83k=; b=Hc0g8WZh6Ic/TyoR5p3qD5BGDt936OoPAp4KCCHK8BZJsVbLubWVNMcLubiMsB 5TmNc3uasEQzvTM6ITGxXKtxoRpJQm7mbkS6VvsSVr3bxSS4kLK2biEAY8WY8pYi Rej8/06kY4nBUOzxfFdyXwSRzwkdaIcZaXzHRyfdQqvsM= Received: from b97369165980 (unknown [140.205.118.67]) by zwqz-smtp-mta-g1-0 (Coremail) with SMTP id _____wBXLh+wnq5lQjuHAA--.56834S3; Tue, 23 Jan 2024 00:58:25 +0800 (CST) References: <87plyhvama.fsf@163.com> <20240104225403.dgmbbfffmm3srpgq@awork3.anarazel.de> <871qaso7ub.fsf@163.com> <87sf37mdqq.fsf@163.com> <87o7dum084.fsf@163.com> <87h6jkmucz.fsf@163.com> <8734uz17va.fsf@163.com> <87o7diyf3z.fsf@163.com> <87edeexznn.fsf@163.com> <87a5p2xc2v.fsf@163.com> <871qadygzz.fsf@163.com> <87wms2w9hn.fsf@163.com> <87o7ddx26q.fsf@163.com> User-agent: mu4e 1.10.7; emacs 29.1 From: Andy Fan To: Robert Haas Cc: Matthias van de Meent , Andres Freund , Tom Lane , Thomas Munro , pgsql-hackers@lists.postgresql.org Subject: Re: the s_lock_stuck on perform_spin_delay Date: Tue, 23 Jan 2024 00:16:10 +0800 In-reply-to: Message-ID: <87cyttwbin.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wBXLh+wnq5lQjuHAA--.56834S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxGFW7KFW8WrWxuFWkWrWrGrg_yoW5Kw47pF 9rKasIkr1vqF1xZ3Z2kF18AFWSkws5J3y5Jr9xGrykAwn8ZF9aqrsFqayY9a4UXa4kKw1j qr4jgryrua90vaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRpVbQUUUUU= X-Originating-IP: [140.205.118.67] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/xtbBzxZtU2V4Hg1t8QAAs1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Robert Haas writes: > On Mon, Jan 22, 2024 at 2:22=E2=80=AFAM Andy Fan = wrote: >> I used sigismember(&BlockSig, SIGQUIT) to detect if a process is doing a >> quickdie, however this is bad not only because it doesn't work on >> Windows, but also it has too poor performance even it impacts on >> USE_ASSERT_CHECKING build only. In v8, I introduced a new global >> variable quickDieInProgress to handle this. > > OK, I like the split between 0001 and 0002. I still think 0001 has > cosmetic problems, but if some committer wants to take it forward, > they can decide what to do about that; you and I going back and forth > doesn't seem like the right approach to sorting that out. Whether or > not 0002 is adopted might affect what we do about the cosmetics in > 0001, too. Replacing ASSERT_NO_SPIN_LOCK with VerifyNoSpinLocksHeld or adding more comments to each call of VerifyNoSpinLocksHeld really makes me happy since they make things more cosmetic and practical. So I'd be absolutely willing to do more stuff like this. Thanks for such suggestions! Then I can't understand the left cosmetic problems... since you are saying it may related to 0002, I guess you are talking about the naming of START_SPIN_LOCK and END_SPIN_LOCK? > > 0003 seems ... unfortunate. It seems like an admission that 0001 is > wrong. Yes, that's what I was thinking. I doubted if I should merge 0003 to 0001 directly during this discussion, and finally I made it separate for easier dicussion. > Surely it *isn't* right to ignore the spinlock restrictions in > quickdie() in general. For example, we could self-deadlock if we try > to acquire a spinlock we already hold. If the problem here is merely > the call in errstart() then maybe we need to rethink that particular > call. If it goes any deeper than that, maybe we've got actual bugs we > need to fix. I get your point! Acquiring an already held spinlock in quickdie is unlikely to happen, but since our existing infrastructure can handle it, then there is no reason to bypass it. Since the problem here is just errstart, we can do a if(!quickDieInProgress) VerifyNoSpinLocksHeld(); in errstart only. Another place besides the errstart is the CHECK_FOR_INTERRUPTS in errfinish. I think we can add the same check for the VerifyNoSpinLocksHeld in CHECK_FOR_INTERRUPTS. > > + * It's likely to check the BlockSig to know if it is doing a qui= ckdie > + * with sigismember, but it is too expensive in test, so introduce > + * quickDieInProgress to avoid that. > > This isn't very good English -- I realize that can sometimes be hard > -- but also -- I don't think it likely that a future hacker would > wonder why this isn't done that way. A static variable is normal for > PostgreSQL; checking the signal mask would be a completely novel > approach. So I think this comment is missing the mark topically. I was wrong to think sigismember is a syscall, but now I see it is just a function in glibc. Even I can't get the source code of it, I think it should just be some bit-operation based on the definition of __sigset_t.=20 Another badness of sigismember is it is not avaiable in windows. It is still unclear to me why sigaddset in quickdie can=20 compile in windows. (I have a sigismember version and get a linker error at windows). This should be a blocker for me to submit the next version of patch. > If > this patch is right at all, the comment here should focus on why > disabling these checks in quickdie() is necessary and appropriate, not > why it's coded to match everything else in the system. I agree, and I think the patch 0003 is not right at all:( --=20 Best Regards Andy Fan