mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH v3 0/2] binder: split alloc->mutex to improve performance
@ 2026-09-04 11:04 Bo Zhang
  2026-09-04 11:04 ` [RFC PATCH v3 1/2] binder: switch alloc->mutex to spinlock for buffer metadata Bo Zhang
  2026-09-04 11:04 ` [RFC PATCH v3 2/2] binder: add install_mutex to serialize page install and shrinker zap Bo Zhang
  0 siblings, 2 replies; 4+ messages in thread
From: Bo Zhang @ 2026-09-04 11:04 UTC (permalink / raw)
  To: aliceryhl, gregkh, cmllamas
  Cc: arve, tkjos, christian, surenb, baohua, zhanghongru06,
	linux-kernel, Bo Zhang

From: Bo Zhang <zhangbo56@xiaomi.com>

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@xiaomi.com/
v1: https://lore.kernel.org/all/20260805152752.1924434-1-zhangbo56@xiaomi.com/

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-04 16:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-04 11:04 [RFC PATCH v3 0/2] binder: split alloc->mutex to improve performance Bo Zhang
2026-09-04 11:04 ` [RFC PATCH v3 1/2] binder: switch alloc->mutex to spinlock for buffer metadata Bo Zhang
2026-09-04 11:04 ` [RFC PATCH v3 2/2] binder: add install_mutex to serialize page install and shrinker zap Bo Zhang
2026-09-04 16:19   ` Bo Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®