From: Carlos Llamas <cmllamas@google.com>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Arve Hjønnevåg" <arve@android.com>,
"Todd Kjos" <tkjos@android.com>,
"Martijn Coenen" <maco@android.com>,
"Joel Fernandes" <joelagnelf@nvidia.com>,
"Christian Brauner" <brauner@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] rust_binder: move BC_FREE_BUFFER drop inside if statement
Date: Fri, 7 Nov 2025 22:02:09 +0000 [thread overview]
Message-ID: <aQ5sYW7B9riNRNHI@google.com> (raw)
In-Reply-To: <20251029-binder-bcfreebuf-option-v1-1-4d282be0439f@google.com>
On Wed, Oct 29, 2025 at 11:50:58AM +0000, Alice Ryhl wrote:
> When looking at flamegraphs, there is a pretty large entry for the
> function call drop_in_place::<Option<Allocation>> which in turn calls
> drop_in_place::<Allocation>. Combined with the looper_need_return
> condition, this means that the generated code looks like this:
>
> if let Some(buffer) = buffer {
> if buffer.looper_need_return_on_free() {
> self.inner.lock().looper_need_return = true;
> }
> }
> drop_in_place::<Option<Allocation>>() { // not inlined
> if let Some(buffer) = buffer {
> drop_in_place::<Allocation>(buffer);
> }
> }
>
> This kind of situation where you check X and then check X again is
> normally optimized into a single condition, but in this case due to the
> non-inlined function call to drop_in_place::<Option<Allocation>>, that
> optimization does not happen.
>
> Furthermore, the drop_in_place::<Allocation> call is only two-thirds of
> the drop_in_place::<Option<Allocation>> call in the flamegraph. This
> indicates that this double condition is not performing well. Also, last
> time I looked at Binder perf, I remember finding that the destructor of
> Allocation was involved with many branch mispredictions.
>
> Thus, change this code to look like this:
>
> if let Some(buffer) = buffer {
> if buffer.looper_need_return_on_free() {
> self.inner.lock().looper_need_return = true;
> }
> drop_in_place::<Allocation>(buffer);
> }
>
> by dropping the Allocation directly. Flamegraphs confirm that the
> drop_in_place::<Option<Allocation>> call disappears from this change.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
LGTM,
Acked-by: Carlos Llamas <cmllamas@google.com>
prev parent reply other threads:[~2025-11-07 22:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-29 11:50 Alice Ryhl
2025-11-07 22:02 ` Carlos Llamas [this message]
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=aQ5sYW7B9riNRNHI@google.com \
--to=cmllamas@google.com \
--cc=aliceryhl@google.com \
--cc=arve@android.com \
--cc=brauner@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maco@android.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=surenb@google.com \
--cc=tkjos@android.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®