From: Nicholas Giunta <grahalt@google.com>
To: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Carlos Llamas" <cmllamas@google.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Arve Hjønnevåg" <arve@android.com>,
"Todd Kjos" <tkjos@android.com>,
"Christian Brauner" <brauner@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Shuah Khan" <shuah@kernel.org>
Cc: "Lyude Paul" <lyude@redhat.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org,
"Nicholas Giunta" <grahalt@google.com>
Subject: [PATCH 0/4] rust_binder: add support for idle thread timeout
Date: Fri, 04 Dec 2026 00:32:45 +0000 [thread overview]
Message-ID: <20261204-rust-binder-thread-spindown-v1-0-8702c42d4437@google.com> (raw)
This series adds opt-in per-process idle thread timeout support to the
Rust Binder driver using the existing BINDER_SET_IDLE_TIMEOUT ioctl and
BR_FINISHED return command, along with kselftest coverage in
binderfs_test.
Today, extra binder looper threads spawned via BR_SPAWN_LOOPER remain
blocked waiting for work indefinitely even after bursts of IPC traffic
subside, preventing userspace from terminating idle threads and
reclaiming their resources. With Android's libbinder default of 15 max
threads, this can leave up to 15 extra threads per process parked in the
binder driver.
With this series, a process can opt into idle thread spin-down by
configuring a millisecond timeout via BINDER_SET_IDLE_TIMEOUT (defaulting
to disabled, Delta::ZERO). Only registered looper threads spawned via
BR_SPAWN_LOOPER are eligible to time out; main threads registered with
BC_ENTER_LOOPER and polling threads remain exempt. To keep at least one
ready thread warm for incoming work, a thread whose timeout expires while
it is the sole entry in ready_threads defers its timeout until either a
peer joins ready_threads (waking it via notify_if_deferred_timeout() so
it exits with BR_FINISHED, unless timeout was disabled at runtime) or
incoming work arrives (waking it via push_work_inner() to deliver the
transaction instead). On timeout returns, BR_SPAWN_LOOPER is suppressed,
and Process::remove_thread() decrements started_thread_count on
BINDER_THREAD_EXIT so threads can be respawned when demand returns.
Series overview:
1. rust: sync: condvar: add wait_interruptible_freezable_timeout()
Adds a freezable interruptible condvar wait with timeout so Rust
Binder threads can time out while still allowing process freeze.
2. rust_binder: add support for thread timeout
Implements BINDER_SET_IDLE_TIMEOUT, BR_FINISHED spin-down,
sole-ready-thread timeout deferral, started_thread_count accounting
on BC_REGISTER_LOOPER / BINDER_THREAD_EXIT, and UAPI docs in
include/uapi/linux/android/binder.h.
3. selftests/binderfs: extract shared namespace and mount helpers
Factors out duplicated userns, binderfs mount/unmount, and
binder-control device allocation helpers across existing tests.
4. selftests/binderfs: add idle timeout tests
Adds FIXTURE(binderfs_idle) tests covering default-disabled
behavior, ioctl validation and runtime reset, spin-down/respawn
cycles, BC_ENTER_LOOPER immunity, and sole-ready-thread retention
(with automatic SKIP on kernels without idle timeout support).
Base and routing:
This series is based on char-misc-next, commit 86266f137b5c ("rust_binder:
fix process leak on proc file creation failure"). Patch 1 touches
rust/kernel/sync/condvar.rs and Patches 3-4 touch
tools/testing/selftests/filesystems/binderfs/binderfs_test.c; if
acceptable to the Rust sync and kselftest maintainers, Acked-by tags
would allow the full series to go through char-misc-next together.
Testing:
- scripts/checkpatch.pl --strict (clean except for the expected
Assisted-by: tag), make LLVM=1 rustfmtcheck, make LLVM=1 CLIPPY=1,
and make LLVM=1 rusttest (6 passed; 0 failed).
- x86_64 QEMU+KVM with CONFIG_USER_NS=y, lockdep, and KUnit enabled
(CONFIG_PROVE_LOCKING=y, CONFIG_DEBUG_ATOMIC_SLEEP=y, CONFIG_FREEZER=y,
CONFIG_KUNIT=y, CONFIG_RUST_KUNIT_TESTS=y):
- rust_kernel_time KUnit suite passed (2/2, covering
Delta::to_jiffies_timeout()).
- Full tools/testing/selftests/filesystems/binderfs/binderfs_test
(binderfs_stress, binderfs_test_privileged,
binderfs_test_unprivileged, and binderfs_idle.*): 3 consecutive root
runs (6/6 passed each) and 2 consecutive non-root runs (5/6 passed +
1 expected privileged skip each) with zero lockdep or atomic-sleep
warnings.
- Cuttlefish Android GKI runs and Android binder integration test suites
(default-disabled regression coverage).
Tooling disclosure (Documentation/process/generated-content.rst):
An AI coding assistant (Gemini) was used to help review concurrency edge
cases (including sole-ready-thread timeout deferral), refactor and write
the binderfs_test.c selftests, and draft commit messages and this cover
letter. All code and descriptions were reviewed, built, and verified by
the submitter.
Signed-off-by: Nicholas Giunta <grahalt@google.com>
---
Nicholas Giunta (4):
rust: sync: condvar: add wait_interruptible_freezable_timeout()
rust_binder: add support for thread timeout
selftests/binderfs: extract shared namespace and mount helpers
selftests/binderfs: add idle timeout tests
drivers/android/binder/defs.rs | 1 +
drivers/android/binder/process.rs | 110 ++-
drivers/android/binder/thread.rs | 117 ++-
include/uapi/linux/android/binder.h | 14 +-
rust/kernel/sync/condvar.rs | 47 +-
.../selftests/filesystems/binderfs/binderfs_test.c | 862 +++++++++++++++------
6 files changed, 881 insertions(+), 270 deletions(-)
---
base-commit: 86266f137b5c18d477a2df8168149203852b037d
change-id: 20261028-rust-binder-thread-spindown-414875686392
Best regards,
--
Nicholas Giunta <grahalt@google.com>
next reply other threads:[~2026-12-04 0:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 0:32 Nicholas Giunta [this message]
2026-12-04 0:32 ` [PATCH 1/4] rust: sync: condvar: add wait_interruptible_freezable_timeout() Nicholas Giunta
2026-12-04 0:32 ` [PATCH 2/4] rust_binder: add support for thread timeout Nicholas Giunta
2026-12-04 0:32 ` [PATCH 3/4] selftests/binderfs: extract shared namespace and mount helpers Nicholas Giunta
2026-12-04 0:32 ` [PATCH 4/4] selftests/binderfs: add idle timeout tests Nicholas Giunta
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=20261204-rust-binder-thread-spindown-v1-0-8702c42d4437@google.com \
--to=grahalt@google.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=arve@android.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=cmllamas@google.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=tamird@kernel.org \
--cc=tkjos@android.com \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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