[RFC PATCH v3 0/2] binder: split alloc->mutex to improve performance

From: Bo Zhang

Date: Fri Sep 04 2026 - 08:03:21 EST


From: Bo Zhang <zhangbo56@xxxxxxxxxx>

Hi,

This is v3 of the binder alloc lock optimization. Thanks to the Sashiko
automated review for the feedback on v2, and to Alice Ryhl for the
review on v1.

The series splits the binder allocator lock into two:

- spinlock: protects buffer metadata (rb-trees, free_async_space,
LRU operations) on the hot path (every binder transaction).

- install_mutex: serializes page installation and shrinker zap on
the cold path (only when pages are installed or reclaimed).

Performance (binderThroughputTest, Qualcomm SM8850, 2 workers, 10 runs)
under concurrent drop_caches:

mutex (baseline) spinlock + install_mutex
throughput: 27k-59k iter/s 85k-89k iter/s
average: 0.031-0.068ms 0.021-0.022ms
P99: 0.088-0.148ms 0.046-0.056ms

Changes since v2:
- Fix an ABBA deadlock between install_mutex and mmap_lock: the install
side now uses mmap_read_trylock() and retries on contention without
holding install_mutex, so it never blocks on mmap_lock under
install_mutex (Sashiko).
- Fix a potential infinite retry loop on -EBUSY: an unexpected
already-populated PTE under install_mutex is now treated as an error
instead of being retried (Sashiko).
- Fix a use-after-free of the preallocated buffer on the -EAGAIN retry
path: the split is now rolled back and the preallocated buffer is
reallocated on each attempt (Sashiko).

Changes since v1:
- Dropped the simple spinlock-only approach that had a race between
page installation and shrinker zap (Alice).
- Added install_mutex to serialize page install and shrinker zap.
- Removed binder_page_lookup() (GUP) since install_mutex serializes
concurrent installers.

v2: https://lore.kernel.org/all/20260831123545.3655557-1-zhangbo56@xxxxxxxxxx/
v1: https://lore.kernel.org/all/20260805152752.1924434-1-zhangbo56@xxxxxxxxxx/

Bo Zhang (2):
binder: switch alloc->mutex to spinlock for buffer metadata
binder: add install_mutex to serialize page install and shrinker zap

drivers/android/binder_alloc.c | 144 ++++++++++++++++++++++++---------
drivers/android/binder_alloc.h | 11 ++-
2 files changed, 112 insertions(+), 43 deletions(-)

--
2.34.1