Re: [PATCH 21/21] binder: switch alloc->mutex to spinlock_t

From: Alice Ryhl
Date: Tue Nov 07 2023 - 04:10:10 EST


Carlos Llamas <cmllamas@xxxxxxxxxx> writes:
> The alloc->mutex is a highly contended lock that causes performance
> issues on Android devices. When a low-priority task is given this lock
> and it sleeps, it becomes difficult for the task to wakeup and complete
> its work. This delays other tasks that are also waiting on the mutex.

Grammar nit: "to wake up"

> The problem gets worse when there is memory pressure in the system,
> because this increases the contention on the alloc->mutex while the
> shrinker reclaims binder pages.
>
> Switching to a spinlock helps to keep the waiters running and avoids the
> overhead of waking up tasks. This significantly improves the transaction
> latency when the problematic scenario occurs.
>
> [snip]
>
> Note that it is only possible to convert this lock after a series of
> changes made by previous patches. These mainly include refactoring the
> sections that might_sleep() and changing the locking order with the
> mmap_lock amongst others.
>
> Signed-off-by: Carlos Llamas <cmllamas@xxxxxxxxxx>

Nice!

Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>

> * binder_free_buf_locked(). However, that could
> - * increase contention for the alloc mutex if clear_on_free
> - * is used frequently for large buffers. The mutex is not
> + * increase contention for the alloc->lock if clear_on_free
> + * is used frequently for large buffers. This lock is not

Grammar nit: Shouldn't this say "However, that could increase contention
on alloc->lock if clear_on_free is used frequently for large buffers."?

Alice