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 1rN22B-008kpN-6b for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jan 2024 02:40:08 +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 1rN22A-008wq4-6r for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jan 2024 02:40:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rN229-008wps-4s for pgsql-hackers@lists.postgresql.org; Tue, 09 Jan 2024 02:40:05 +0000 Received: from m15.mail.163.com ([45.254.50.220]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rN221-000a2V-Nz for pgsql-hackers@lists.postgresql.org; Tue, 09 Jan 2024 02:40:01 +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=6AKUrnJadZRNFT/pbNc1FZvuqt96hKByPXdFjlQptCE=; b=DHi33g6976fbm+2tBFHe5E3vIOMfQ/DsaCXpvIPxbUpT8uVkkLoMy5g8+cNMbf MghLhSWNjPylAVunKn9XvGpFsnnrds/H/aZExXdBMgY8keQEtSQEyKw+V6fy4dhQ cuFO+gPNdipNwt14pWOBH9VVSPcgL5wpKAhmIaUqvy+ls= Received: from b97369165980 (unknown [140.205.118.37]) by zwqz-smtp-mta-g1-0 (Coremail) with SMTP id _____wDnb8DtsZxlLpWfAg--.1142S3; Tue, 09 Jan 2024 10:39:42 +0800 (CST) References: <87plyhvama.fsf@163.com> <489987.1704381735@sss.pgh.pa.us> <498328.1704386013@sss.pgh.pa.us> <20240104225403.dgmbbfffmm3srpgq@awork3.anarazel.de> <871qaso7ub.fsf@163.com> User-agent: mu4e 1.10.7; emacs 29.1 From: Andy Fan To: Robert Haas Cc: Andres Freund , Tom Lane , Thomas Munro , pgsql-hackers@lists.postgresql.org Subject: Re: the s_lock_stuck on perform_spin_delay Date: Tue, 09 Jan 2024 10:01:59 +0800 In-reply-to: Message-ID: <87sf37mdqq.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDnb8DtsZxlLpWfAg--.1142S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFWUZw18GryxJr18Aw1kKrg_yoW5Grykpr Z3W3sxCr18CF4IvwnrZ3Wjv3sayw4rCas8GrsIkayDAw1YqFy3Kr1qqw45ZFyqkr1kuFyq qr4xtas5uayYvaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zR-o7iUUUUU= X-Originating-IP: [140.205.118.37] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/xtbBzxRgU2V4HPt0eQABse List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, Robert Haas writes: > On Sun, Jan 7, 2024 at 9:52=E2=80=AFPM Andy Fan w= rote: >> > I think we should add cassert-only infrastructure tracking whether we >> > currently hold spinlocks, are in a signal handler and perhaps a few ot= her >> > states. That'd allow us to add assertions like: >> .. >> > - no lwlocks or ... while in signal handlers >> >> I *wish* lwlocks should *not* be held while in signal handlers since it >> inspired me for a direction of a low-frequency internal bug where a >> backend acuqire a LWLock when it has acuqired it before. However when I >> read more document and code, I am thinking this should not be a >> problem. > > It's not safe to acquire an LWLock in a signal handler unless we know > that the code that the signal handler is interrupting can't already be > doing that. Consider this code from LWLockAcquire: Thanks for the explaination! I can follow the sistuation you descirbe here, then I found I asked a bad question because I didn't clarify what "signal handlers" I was refering to, sorry about that! In your statement, I guess you are talking about the signal handler from Linux. However I *assumed* such handlers are doing pretty similar stuff like set a 'GlobalVarialbe=3Dtrue'. If my assumption was right, I think that should not be take cared. For example: spin_or_lwlock_acquire(); ... (linux signal handler may be invovked here no matther what ... code is) spin_or_lwlock_relase() Since the linux signal hander are pretty simply, so it can come back to 'spin_or_lwlock_relase' anyway. (However my assumption may be wrong and thanks for highlight this, and it is helpful for me to debug my internal bug!) The singler handler I was refering to is 'CHECK_FOR_INTERRUPTS', Based on this, spin_lock and lwlock are acted pretty differently.=20 spin_lock_acuqire(); CHECK_FOR_INTERRUPT(); spin_lock_release(); Since CHECK_FOR_INTERRUPT usually goes to the ERROR system which makes it is hard to go back to 'spin_lock_release()', then spin lock leaks! so CHECK_FOR_INTERRUPT is the place I Assert *spin lock* should not be handled in my patch. and I understood what Andres was talking about is the same thing. (Of course I can add the "Assert no spin lock is held" into every linux single handler as well). Based on the above, I asked my question in my previous post, where I am not sure if we should do the same('Assert no-lwlock should be held') for *lwlock* in CHECK_FOR_INTERRUPT since lwlocks can be released no matter where CHECK_FOR_INTERRUPT jump to. --=20 Best Regards Andy Fan