mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Jim Cromie <jim.cromie@gmail.com>,
	Lorenzo Stoakes <ljs@kernel.org>, Kees Cook <kees@kernel.org>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Jiri Olsa <olsajiri@gmail.com>,
	linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org,
	bpf@vger.kernel.org, Petr Mladek <pmladek@suse.com>
Subject: Re: [PATCH v6 0/3] kallsyms: Accelerate symbol name lookups by ~7x
Date: Sun, 27 Sep 2026 06:57:28 +0100	[thread overview]
Message-ID: <20260927065728.7f159234@pumpkin> (raw)
In-Reply-To: <20260926133859.c8232c439184dfa17472b020@linux-foundation.org>

On Sat, 26 Sep 2026 13:38:59 -0700
Andrew Morton <akpm@linux-foundation.org> wrote:

> On Sat, 26 Sep 2026 13:40:11 -0600 Jim Cromie <jim.cromie@gmail.com> wrote:
> 
> > As measured by kernel/kallsyms_selftest across ~184k symbols,
> > kallsyms_lookup_names() binary search takes ~6.1 us per lookup due to
> > two inner-loop costs:  
> 
> We don't have a kallsyms maintainer afaik.  Petr is pretty active in
> there so let's give him a hopeful cc.
> 
> > 0. Candidate symbols are fully decompressed into a 512-byte stack buffer
> >    before calling strcmp(), even though non-matching steps could choose on the
> >    first differing character (0..N-1).
> > 
> > 1. Probes scan sequentially from 256:1 markers in kallsyms_names[],
> >    decoding an average of 127.5 symbols per probe (~2,170 hops across a
> >    17-step search).
> > 
> > This 3-patch series addresses both:
> > 
> > 0. Patch 1 introduces kallsyms_strcmp_symbol() to compare ASCII queries
> >    against compressed tokens on the fly, bailing out on first mismatch.
> >    Drops the 512-byte stack buffer and saves ~530 ns.
> > 
> > 1. Patch 2 increases marker density from 256:1 to 16:1, cutting average
> >    scan distance from 127.5 to 7.5 hops and dropping lookup latency from
> >    6,102 ns to 866 ns for +42.2 KiB of .rodata.
> > 
> > 2. Patch 3 inlines and unrolls get_symbol_seq() 24-bit reconstruction.
> > 
> > Results (kernel/kallsyms_selftest across ~184k symbols):
> > - Baseline (256:1):  6,102 ns
> > - Patch 1 (strcmp):  5,572 ns (-530 ns)
> > - Patch 2 (16:1):      866 ns (7.0x faster)
> > - Memory: +42.2 KiB .rodata, 0 bytes dynamic RAM  
> 
> Can you better explain the tradeoffs here?  Increased memory use?  If
> so how much?  Is any change in build time expected?

I've had a thought of a scheme that should give most of the ~19x
improvement of the original patch without increasing the data size and
with only a small increase in code size.
The downside is a slight slow down for sequential access.

The thing to do is replace the 24bit 'symbol number' in the 'sorted by name'
list with the offset of the beginning of the name.
(For very large kernels it may need to be 32bit.)
The binary search for the symbol name then doesn't need a linear scan
and also loses one level of indirection.
You then need to do another binary search over the 'offset of every 256th
entry' table, followed by a linear search to find the correct address.

For sequential access there is a reasonable chance the next symbol is in
the same 256 symbol block (in address order), that can be quickly checked.

I got the code to run in userspace yesterday (with a real kernel symbol
table), I might look at some changes later today.

David

> 
> 
> What isn't addressed in here (afaict) is "who cares".  Is there some
> workload which is kallsyms-intensive?
> 
> This info really should be right in the first para of the [0/N], and in
> detail.  What benefit does this work offer to our users?  Use cases,
> example scenarios, etc.
> 
> Apologies if I missed this in earlier discussions, but if it was in the
> [0/N] this wouldn't matter!


      reply	other threads:[~2026-09-27  5:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-26 19:40 Jim Cromie
2026-09-26 19:40 ` [PATCH v6 1/3] kallsyms: Match compressed tokens on the fly during binary search Jim Cromie
2026-09-26 19:40 ` [PATCH v6 2/3] kallsyms: Increase marker density to 16:1 to accelerate lookups Jim Cromie
2026-09-26 19:40 ` [PATCH v6 3/3] kallsyms: Unroll 24-bit sequence reconstruction in get_symbol_seq() Jim Cromie
2026-09-26 20:38 ` [PATCH v6 0/3] kallsyms: Accelerate symbol name lookups by ~7x Andrew Morton
2026-09-27  5:57   ` David Laight [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=20260927065728.7f159234@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bpf@vger.kernel.org \
    --cc=jim.cromie@gmail.com \
    --cc=kees@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=olsajiri@gmail.com \
    --cc=pmladek@suse.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®