Re: [Patch] Optimize dropping of relation buffers using dlist
Kyotaro Horiguchi <horikyota.ntt@gmail.com>
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
To: tsunakawa.takay@fujitsu.com
Cc: amit.kapila16@gmail.com, andres@anarazel.de, k.jamison@fujitsu.com,
tgl@sss.pgh.pa.us, thomas.munro@gmail.com, robertmhaas@gmail.com,
tomas.vondra@2ndquadrant.com, pgsql-hackers@postgresql.org
Date: 2020-12-22T02:37:41Z
Lists: pgsql-hackers
At Tue, 22 Dec 2020 01:42:55 +0000, "tsunakawa.takay@fujitsu.com" <tsunakawa.takay@fujitsu.com> wrote in > From: Amit Kapila <amit.kapila16@gmail.com> > > This answers the second part of the question but what about the first > > part (We hold a buffer partition lock, and have done a lookup in th > > mapping table. Why are we then rechecking the > > relfilenode/fork/blocknum?) > > > > I think we don't need such a check, rather we can have an Assert > > corresponding to that if-condition in the patch. I understand it is > > safe to compare relfilenode/fork/blocknum but it might confuse readers > > of the code. > > Hmm, you're right. I thought someone else could steal the found > buffer and use it for another block because the buffer mapping > lwlock is released without pinning the buffer or acquiring the > buffer header spinlock. However, in this case (replay of TRUNCATE > during recovery), nobody steals the buffer: bgwriter or checkpointer > doesn't use a buffer for a new block, and the client backend waits > for AccessExclusive lock. Mmm. If that is true, doesn't the unoptimized path also need the rechecking? The AEL doesn't work for a buffer block. No new block can be allocted for the relation but still BufferAlloc can steal the block for other relations since the AEL doesn't work for each buffer block. Am I still missing something? > > I have started doing minor edits to the patch especially planning to > > write a theory why is this optimization safe and here is what I can > > come up with: > > Thank you, that's fluent and easier to understand. +1 regards. -- Kyotaro Horiguchi NTT Open Source Software Center
Commits
-
Fix size overflow in calculation introduced by commits d6ad34f3 and bea449c6.
- 519e4c9ee21a 14.0 landed
-
Optimize DropRelFileNodesAllBuffers() for recovery.
- bea449c635c0 14.0 landed
-
Optimize DropRelFileNodeBuffers() for recovery.
- d6ad34f3410f 14.0 landed
-
Cache smgrnblocks() results in recovery.
- c5315f4f4484 14.0 cited
-
Add a check to prevent overwriting valid data if smgrnblocks() gives a
- ffae5cc5a602 8.2.0 cited