From: David Laight <david.laight.linux@gmail.com>
To: Jim Cromie <jim.cromie@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Lorenzo Stoakes <ljs@kernel.org>, Kees Cook <kees@kernel.org>,
Masahiro Yamada <masahiroy@kernel.org>,
linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org,
bpf@vger.kernel.org
Subject: Re: [PATCH 2/3] kallsyms: Add 3-byte index into compressed symbols to replace marker scans
Date: Mon, 21 Sep 2026 16:25:11 +0100 [thread overview]
Message-ID: <20260921162511.233196a5@pumpkin> (raw)
In-Reply-To: <20260919-ksyms-tune-v1-2-d85c97da1a32@gmail.com>
On Sat, 19 Sep 2026 21:58:56 -0600
Jim Cromie <jim.cromie@gmail.com> wrote:
> From: Jim Cromie <jim.cromie@gmail.com>
> To: Andrew Morton <akpm@linux-foundation.org>
> Cc: Lorenzo Stoakes <ljs@kernel.org>, Kees Cook <kees@kernel.org>, Masahiro Yamada <masahiroy@kernel.org>, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, bpf@vger.kernel.org, Jim Cromie <jim.cromie@gmail.com>
> Subject: [PATCH 2/3] kallsyms: Add 3-byte index into compressed symbols to replace marker scans
> Date: Sat, 19 Sep 2026 21:58:56 -0600
>
> The compressed symbol table (kallsyms_names) packs ~130k kernel symbol
> names, in address order, into variable-length records with format
> [<len>][<tokenized-strings-wo-\0>].
>
> This layout optimizes address-to-name mapping, but name-to-address
> lookups require a linear scan. To accelerate lookups, kallsyms_markers
> was added to record the offset of every 256th entry, cutting the
> worst-case walk from 130k to ~128 hops on average. However, this
> still leaves substantial work: during a 17-step binary search in
> kallsyms_lookup_names(), the marker walk repeats at every step
> (17 * 128), decoding ~2,176 record length headers per lookup.
> Address-to-name resolution (sprint_symbol) pays the same 0..255 hop
> penalty on every call.
>
> Introduce kallsyms_names_offsets, a 3-byte-per-symbol direct index into
> the compressed kallsyms_names table. scripts/kallsyms.c emits this
> table at build-time while writing kallsyms_names, capturing the exact
> byte offset for each symbol. Using 24 bits covers up to 16 MiB of
> compressed symbol names, easily spanning the ~2.3 MiB table while
> saving 25% space compared to u32 entries.
>
> With kallsyms_names_offsets:
>
> 0. get_symbol_offset() performs an O(1) 3-byte table lookup, eliminating
> the ~2,176 header scans per name search.
>
> 1. Drop the legacy kallsyms_markers table, saving ~2 KiB of .rodata.
>
> 2. Unroll the shift loop in get_symbol_seq() to match
> get_symbol_offset() as a direct 3-byte big-endian load.
Why big-endian?
Most cpu are little endian, gcc 16 and clang 10 will replace two of
the 8bit loads with a 16bit one.
I'd also comment that the overhead is 3 bytes/symbol - with a note
about the average symbol size (excluding rust).
The +573kB sounds like a lot - but isn't that much compared to the
size of the table.
You should only need half the table.
The only odd index you need to check is the last one, and you'll have
just read the symbol below it.
David
next prev parent reply other threads:[~2026-09-21 15:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 3:58 [PATCH 0/3] kallsyms: Accelerate symbol name lookups by ~19x Jim Cromie
2026-09-20 3:58 ` [PATCH 1/3] kallsyms: Add test_kallsyms_perf module to benchmark lookup latency Jim Cromie
2026-09-20 3:58 ` [PATCH 2/3] kallsyms: Add 3-byte index into compressed symbols to replace marker scans Jim Cromie
2026-09-21 15:25 ` David Laight [this message]
2026-09-20 3:58 ` [PATCH 3/3] kallsyms: Match compressed tokens on the fly during binary search Jim Cromie
2026-09-21 12:00 ` [PATCH 0/3] kallsyms: Accelerate symbol name lookups by ~19x Jiri Olsa
2026-09-21 14:46 ` Lorenzo Stoakes (ARM)
2026-09-21 23:07 ` Kees Cook
2026-09-22 4:41 ` jim.cromie
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=20260921162511.233196a5@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 \
/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®