[PATCH v3] nptl: Optimize trylock for high cache contention workloads (BZ #33704)

Sunil Pandey skpgkp2@gmail.com
Thu Dec 18 18:02:11 GMT 2025


On Thu, Dec 18, 2025 at 5:01 AM Wilco Dijkstra <Wilco.Dijkstra@arm.com>
wrote:

> Hi Sunil,
>
> > Check lock availability before acquisition to reduce cache line
> > bouncing.  Significantly improves trylock throughput on multi-core
> > systems under heavy contention.
>
> LGTM.
>
> Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>
>
> Cheers,
> Wilco
>
>
> -      if (lll_trylock (mutex->__data.__lock) == 0)
> +      if (atomic_load_relaxed (&(mutex->__data.__lock)) == 0
> +         && lll_trylock (mutex->__data.__lock) == 0)
>
> OK
>         {
>           /* Record the ownership.  */
>           mutex->__data.__owner = id;
> @@ -60,7 +61,10 @@ ___pthread_mutex_trylock (pthread_mutex_t *mutex)
>      case PTHREAD_MUTEX_TIMED_NP:
>      case PTHREAD_MUTEX_ADAPTIVE_NP:
>      case PTHREAD_MUTEX_ERRORCHECK_NP:
> -      if (lll_trylock (mutex->__data.__lock) != 0)
> +      /* Mutex type is already loaded, lock check overhead should
> +         be minimal.  */
> +      if (atomic_load_relaxed (&(mutex->__data.__lock)) != 0
> +         || lll_trylock (mutex->__data.__lock) != 0)
>         break;
>
> OK


I would like to backport this patch to release branches.
Any comments or objections?

--Sunil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20251218/dbc36f6f/attachment-0001.htm>


More information about the Libc-alpha mailing list