Re: [PATCH] Futexes IV (Fast Lightweight Userspace Semaphores)

Linus Torvalds
2002-03-08T20:58:23Z

On Fri, 8 Mar 2002, Alan Cox wrote:
>
> Can we go to cache line alignment - for an array of locks thats clearly
> advantageous

I disagree about the "clearly". Firstly, the cacheline alignment is CPU
dependent, so on some CPU's it's 32 bytes (or even 16), on others it is
128 bytes.

Secondly, a lot of locking is actually done inside a single thread, and
false sharing doesn't happen much - so keeping the locks dense can be
quite advantageous.

The cases where false sharing _does_ happen and are a problem should be
for the application writer to worry about, not for the kernel to force.

So I think 8 bytes is plenty fine enough - with 16 bytes a remote
possibility (I don't think it is needed, but it gives you som epadding for
future expansion). And people who have arrays and find false sharing to be
a problem can fix it themselves.

I personally don't find arrays of locks very common. It's much more common
to have arrays of data structures that _contain_ locks (eg things like
having hash tables etc with a per-hashchain lock) and then those container
structures may want to be cacheline aligned, but the locks themselves
should not need to be.

Linus