From: Caleb Sander Mateos <csander@purestorage.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, Eric Biggers <ebiggers@kernel.org>
Subject: Re: [PATCH] scatterlist: inline sg_next()
Date: Wed, 16 Apr 2025 15:30:15 -0700 [thread overview]
Message-ID: <CADUfDZpH5v8jxphVRGvD5o-jLXiDbTw0SsAxzTSCLGyua9erjQ@mail.gmail.com> (raw)
In-Reply-To: <20250416150529.1e24677e3798cd783f4adb8f@linux-foundation.org>
On Wed, Apr 16, 2025 at 3:05 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Wed, 16 Apr 2025 10:06:13 -0600 Caleb Sander Mateos <csander@purestorage.com> wrote:
>
> > sg_next() is a short function called frequently in I/O paths. Define it
> > in the header file so it can be inlined into its callers.
>
> Does this actually make anything faster?
>
> net/ceph/messenger_v2.c has four calls to sg_next(). x86_64 defconfig:
Hmm, I count 7 calls in the source code. And that excludes possible
functions defined in included header files that also call sg_next().
And the functions which call sg_next() could themselves be inlined,
resulting in even more calls. The object file looks to have 7 calls to
sg_next():
$ readelf -r net/ceph/messenger_v2.o | grep -c sg_next
7
>
> x1:/usr/src/25> size net/ceph/messenger_v2.o
> text data bss dec hex filename
> 31486 2212 0 33698 83a2 net/ceph/messenger_v2.o
>
> after:
>
> 31742 2212 0 33954 84a2 net/ceph/messenger_v2.o
>
> More text means more cache misses. Possibly the patch slows things down??
Yes, it's true that inlining doesn't necessarily improve performance.
For reference, the workload I am looking at is issuing 32 KB NVMe
reads, which results in calling sg_next() from nvme_pci_setup_prps().
About 0.5% of the CPU time is spent in sg_next() itself (not counting
the cost of calling into it).
Inlining the function could help save the cost of the call + return,
as well as improve branch prediction rates for the if (sg_is_last(sg))
check by creating a separate copy of the branch in each caller.
My guess is that most workloads (like mine) don't call sg_next() from
all that many places. So even though inlining would duplicate the code
into all callers, not all the callers are hot. The number of locations
actually loaded into the instruction cache are likely to be relatively
few, so the increase in cached instructions wouldn't be as steep as
the text size suggests.
That's all to say: the costs and benefits are workload-dependent. And
in all likelihood, they will be pretty small either way.
Best,
Caleb
prev parent reply other threads:[~2025-04-16 22:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-16 16:06 Caleb Sander Mateos
2025-04-16 17:00 ` Eric Biggers
2025-04-16 22:05 ` Andrew Morton
2025-04-16 22:30 ` Caleb Sander Mateos [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=CADUfDZpH5v8jxphVRGvD5o-jLXiDbTw0SsAxzTSCLGyua9erjQ@mail.gmail.com \
--to=csander@purestorage.com \
--cc=akpm@linux-foundation.org \
--cc=ebiggers@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/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