Re: semaphore and mutex in current Linux kernel (3.2.2)

From: Ingo Molnar
Date: Sun Apr 01 2012 - 08:20:13 EST



* Chen, Dennis (SRDC SW) <Dennis1.Chen@xxxxxxx> wrote:

> Documentation/mutex-design.txt:
>
> "- 'struct mutex' is smaller on most architectures: E.g. on x86,
> 'struct semaphore' is 20 bytes, 'struct mutex' is 16 bytes.
> A smaller structure size means less RAM footprint, and better
> CPU-cache utilization."
> ================================================================
>
> Now in my x86-64 32-bit Linux environment, 'struct semaphone'
> is 16 bytes, 'struct mutex' is 20 bytes. So seems the RAM
> footprint advantages are not there...

It got larger due to the adaptive spin-mutex performance
optimization.

> For the performance advantages followed, I don't have the
> ./test-mutex and maybe the testing environment, so haven't the
> 1st hand data for this item...

Well, a way to reproduce that would be to find a lock_mutex
intense workload ('perf top -g', etc.), and then changing back
the underlying mutex to a semaphore, and measure the performance
of the two primitives.

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/