mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bo Zhang <zhangbo0325@gmail.com>
To: aliceryhl@google.com, gregkh@linuxfoundation.org, cmllamas@google.com
Cc: arve@android.com, tkjos@android.com, christian@brauner.io,
	surenb@google.com, baohua@kernel.org, zhanghongru06@gmail.com,
	linux-kernel@vger.kernel.org, Bo Zhang <zhangbo0325@gmail.com>
Subject: [RFC PATCH v4 0/2] binder: split alloc->mutex to improve performance
Date: Mon,  7 Sep 2026 21:00:26 +0800	[thread overview]
Message-ID: <20260907130028.807366-1-zhangbo0325@gmail.com> (raw)

Hi,

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

The series splits the binder allocator lock into two, with distinct
roles:

  - alloc->lock (spinlock): owns the non-sleeping metadata - pages[],
    the LRU list, the rb-trees and free_async_space. This is the hot
    path hit on every binder transaction.

  - install_mutex: only serializes the sleeping PTE operations
    (vm_insert_page vs the shrinker's zap_vma_range) for a given alloc.

pages[] and the LRU are always updated together under alloc->lock, so
the buffer allocation path always observes a consistent state. The
shrinker takes install_mutex with mutex_trylock() (skipping on failure),
which avoids a self-deadlock when install-side reclaim re-enters the
shrinker, and keeps the shrinker out of any blocking cycle with
mmap_lock.

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

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

Changes since v3:
- Fix an AA self-deadlock: the shrinker now uses mutex_trylock() on
  install_mutex, so install-side vm_insert_page() recursing into direct
  reclaim and re-entering the shrinker on the same thread no longer
  deadlocks (Sashiko).
- Fix a use-after-free: pages[index]=NULL is done under alloc->lock
  (together with the LRU isolate) instead of under install_mutex, so
  binder_lru_freelist_del() can no longer read a pointer the shrinker is
  about to free (Sashiko).
- Fix an RT-task livelock: since pages[] and the LRU are now consistent
  under alloc->lock, list_lru_del() never fails and the -EAGAIN retry
  path is removed entirely (Sashiko).
- The mutex_trylock() also removes the ABBA concern with mmap_lock, so
  the install side's mmap_lock fallback returns to a plain blocking
  acquire (no more -EAGAIN/retry).

Changes since v2:
- Fixed the ABBA/-EBUSY/next-buffer issues raised on v2 (superseded by
  the simpler v4 locking above).

Changes since v1:
- Dropped the spinlock-only approach that raced install against shrinker
  zap; added install_mutex to serialize them (Alice).

v3: https://lore.kernel.org/all/20260904110448.23086-1-zhangbo0325@gmail.com/
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 | 95 +++++++++++++++++++---------------
 drivers/android/binder_alloc.h | 11 ++--
 2 files changed, 61 insertions(+), 45 deletions(-)

-- 
2.34.1



             reply	other threads:[~2026-09-07 13:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07 13:00 Bo Zhang [this message]
2026-09-07 13:00 ` [RFC PATCH v4 1/2] binder: switch alloc->mutex to spinlock for buffer metadata Bo Zhang
2026-09-08  6:44   ` Bo Zhang
2026-09-07 13:00 ` [RFC PATCH v4 2/2] binder: add install_mutex to serialize page install and shrinker zap Bo Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260907130028.807366-1-zhangbo0325@gmail.com \
    --to=zhangbo0325@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=arve@android.com \
    --cc=baohua@kernel.org \
    --cc=christian@brauner.io \
    --cc=cmllamas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=tkjos@android.com \
    --cc=zhanghongru06@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®