Re: Atomics for heap_parallelscan_nextpage()
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: David Rowley <david.rowley@2ndquadrant.com>,
PostgreSQL-development <pgsql-hackers@postgresql.org>
Cc: Amit Khandekar <amitdkhan.pg@gmail.com>,
Andres Freund <andres@anarazel.de>,
Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>,
Robert Haas <robertmhaas@gmail.com>
Date: 2017-08-16T13:20:28Z
Lists: pgsql-hackers
On 05/06/2017 04:57 PM, David Rowley wrote: > Andres mentioned in [2] that it might be worth exploring using atomics > to do the same job. So I went ahead and did that, and came up with the > attached, which is a slight variation on what he mentioned in the > thread. > > To keep things a bit more simple, and streamline, I ended up pulling > out the logic for setting the startblock into another function, which > we only call once before the first call to > heap_parallelscan_nextpage(). I also ended up changing phs_cblock and > replacing it with a counter that always starts at zero. The actual > block is calculated based on that + the startblock modulo nblocks. > This makes things a good bit more simple for detecting when we've > allocated all the blocks to the workers, and also works nicely when > wrapping back to the start of a relation when we started somewhere in > the middle due to piggybacking with a synchronous scan. Looks reasonable. I edited the comments and the variable names a bit, to my liking, and committed. Thanks! - Heikki
Commits
-
Fix pg_atomic_u64 initialization.
- dcd052c8d20c 11.0 landed
-
Fix shm_toc.c to always return buffer-aligned memory.
- ac883ac453e9 11.0 landed
-
Use atomic ops to hand out pages to scan in parallel scan.
- 3cda10f41bfe 11.0 landed
-
Improve 64bit atomics support.
- e8fdbd58fe56 10.0 cited