On Wed, Oct 30, 2024 at 02:16:51PM +0200, Heikki Linnakangas wrote: > Acquiring the exclusive lock in step 4 is just a way to wait for all the > existing share-lockers to release the lock. You wouldn't need to block new > share-lockers. We have LW_WAIT_UNTIL_FREE, which is almost what we need, but > it currently ignores share-lockers. So doing this "properly" would require > more changes to LWLocks. Briefly acquiring an exclusive lock seems > acceptable though.
The problem is starvation. For this you really want something more like rwlocks that do not have the writer starvation problem. But rwlocks have other problems too, like in this case forcing readers to wait. What you want here is something more like a barrier where readers that did not see that the page has BM_IO_IN_PROGRESS set get to act as though it's not set while readers that did see that the page has BM_IO_IN_PROGRESS set don't, and the process that did set that bit gets to wait for the first set of readers all without blocking the second set of readers. That's something akin to an rwlock, but better -- in fact, it resembles RCU. Nico --