LWLock granular partition lock memory layout

Поиск
Список
Период
Сортировка
Искать

LWLock granular partition lock memory layout

От:
Alexandre 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.


Re: LWLock granular partition lock memory layout

От:
Alexandre Felipe <o.alexandre.felipe@gmail.com>
Дата:
Вложения:
Sorry for the typo

Re: LWLock granular partition lock memory layout

От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
On Tue, Oct 06, 2026 at 08:44:53AM +0100, Alexandre Felipe wrote:
> 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.

Your argument would be greatly improved by showing (with numbers) what
sorts of benefits this provides in realistic workloads.  I briefly looked
at benchmark.txt, but I couldn't quite tell what it was meant to show, and
you characterized it as pointless, anyway.

-- 
nathan


Re: LWLock granular partition lock memory layout

От:
Alexandre Felipe <o.alexandre.felipe@gmail.com>
Дата:


On Wed, Oct 7, 2026 at 7:56 PM Nathan Bossart <nathandbossart@gmail.com> wrote:
On Tue, Oct 06, 2026 at 08:44:53AM +0100, Alexandre Felipe wrote:
> 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.

Your argument would be greatly improved by showing (with numbers) what
sorts of benefits this provides in realistic workloads.  I briefly looked
at benchmark.txt, but I couldn't quite tell what it was meant to show, and
you characterized it as pointless, anyway.

Hi Nathan,

The problem is that on a realistic workload on my lightweight laptop
I can't measure observe the LWLock effect at all. So the best I can do
is to remove the realistic part and test them on a tight loop.

I believe that if you are running on a multi-socket machine that would
be visible.



Re: LWLock granular partition lock memory layout

От:
Alexandre Felipe <o.alexandre.felipe@gmail.com>
Дата:
Вложения:
> 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)

In theory this has benefits with no compromises.

In practice, it is more impactful than I initially expected.

I thought it would be noticeable only in large scale systems, but even on my
lightweight laptop with 8 cores the results are measurable.

With 128 partitions

clients         base      patched

      1      26371.6      26149.2

      8      35659.7      44958.5        +26.1%



Regards,

Alexandre

FAQ