LWLock granular partition lock memory layout

Started by Alexandre Felipeabout 1 hour ago1 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliesbuild failedCI history

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t254081_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t254081_1 && git checkout t254081_1

Patchset v1 (message #1) is on t254081_1

Jump to latest
#1Alexandre Felipe
o.alexandre.felipe@gmail.com

This time I am not changing LWLock semantics :)

Consider the a hash table partitioned in two different ways.

1. having S partitions, guarded by LWLocks on the same cache line.
2. having a single LWLock.

Which one will give better concurrency?
Which one will cost more to lock/unlock?

I argue that having S partitions is better in several different ways.

a. Concurrency of LW_EXCLUSIVE
b. Reduced contention on LWLockWaitListLock
c. Reduced CAS iterations in LWLockAtttemptLock
d. Reduced waits (that implies wait list access and sleeping)

I included a (pointless) benchmark result.

And you can find a longer discussion in 0002 patch.

Attachments:

t254081_1
benchmark.txttext/plain; charset=US-ASCII; name=benchmark.txtDownload
v1-0002-introduce-LWLockAligned.patchapplication/octet-stream; name=v1-0002-introduce-LWLockAligned.patchDownload+37-12
v1-0001-LWLock-struct-layout.patchapplication/octet-stream; name=v1-0001-LWLock-struct-layout.patchDownload+63-53