Re: [patch 0/9] mutex subsystem, -V4

From: Paul Mackerras
Date: Thu Dec 22 2005 - 16:42:12 EST


Andrew Morton writes:

> Ingo Molnar <mingo@xxxxxxx> wrote:
> > - 'struct mutex' is smaller: 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.
>
> Because of the .sleepers thing. Perhaps a revamped semaphore wouldn't need
> thsat field?

Note that semaphores on 32-bit PPC are only 16 bytes already, since I
got rid of the sleepers field ages ago. The fast path is just
atomic_dec/inc, and the slow path needs an atomic op that does

x = max(x, 0) + inc

atomically and returns the old value of x. That's easy to do with
lwarx/stwcx (just two more instructions than an atomic inc), and can
also be done quite straightforwardly with cmpxchg. Alpha, mips, s390
and sparc64 also use this scheme.

In fact I would go so far as to say that I cannot see how it would be
possible to do a mutex any smaller or faster than a counting semaphore
on these architectures.

Regards,
Paul.
-
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/