Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mhufr-0000qy-Ib for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Nov 2021 14:22:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mhufq-0002PQ-Fb for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Nov 2021 14:22:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mhufq-0002Mw-77 for pgsql-hackers@lists.postgresql.org; Tue, 02 Nov 2021 14:22:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mhufm-00070W-Hl for pgsql-hackers@postgresql.org; Tue, 02 Nov 2021 14:22:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1A2ELm8l1376385; Tue, 2 Nov 2021 10:21:48 -0400 From: Tom Lane To: Kyotaro Horiguchi cc: bossartn@amazon.com, michael@paquier.xyz, andres@anarazel.de, sulamul@gmail.com, pgsql-hackers@postgresql.org Subject: Re: inefficient loop in StandbyReleaseLockList() In-reply-to: <20211102.114313.713245704579079227.horikyota.ntt@gmail.com> References: <1138901.1635782315@sss.pgh.pa.us> <1311319.1635804078@sss.pgh.pa.us> <20211102.114313.713245704579079227.horikyota.ntt@gmail.com> Comments: In-reply-to Kyotaro Horiguchi message dated "Tue, 02 Nov 2021 11:43:13 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1376383.1635862908.1@sss.pgh.pa.us> Date: Tue, 02 Nov 2021 10:21:48 -0400 Message-ID: <1376384.1635862908@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Kyotaro Horiguchi writes: > At Mon, 01 Nov 2021 18:01:18 -0400, Tom Lane wrote in >> So what I did in the attached is add a "canceled" flag to >> PendingUnlinkEntry, which lets us deal with canceled or finished >> entries without having to delete them from the list right away. >> Then we only need to physically clean up the list once per >> SyncPostCheckpoint call. > We don't loop over so many canceled elements usually so I think it > works well. However, shouldn't we consider canceled before checking > cycle_ctr? Good point. I was thinking that it's best to break out of the loop at the first opportunity. But if the first few entries with the next cycle_ctr value are canceled, it's best to advance over them in the current SyncPostCheckpoint call. It saves nothing to postpone that work to later, and indeed adds a few cycles by leaving more data to be copied by list_delete_first_n. Will change it. > I feel that we might need to wipe_mem for the memmove case as well > (together with list_delete_nth_cell) but that is another thing even if > that's correct. Hm. I made this function by copying-and-modifying list_delete_nth_cell, so if there's something wrong there then this code inherited it. But I don't think it's wrong. The wipe_mem business is only intended to be used when enabling expensive debug options. > Otherwise it looks good to me. Thanks for looking! regards, tom lane