mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: tphilipp@gmail.com,bpf@vger.kernel.org
Cc: tphilipp@gmail.com,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,martin.lau@linux.dev,eddyz87@gmail.com,memxor@gmail.com,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,john.fastabend@gmail.com,sdf@fomichev.me,emil@etsalapatis.com,ihor.solodrai@linux.dev,hawk@kernel.org,davem@davemloft.net,kuba@kernel.org,shuah@kernel.org,nbd@nbd.name,hacks@slashdirt.org,stijn@linux-ipv6.be,daniel@zonque.org,netdev@vger.kernel.org,linux-kselftest@vger.kernel.org,linux-kernel@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v3 2/4] bpf: Align lpm_trie map values to 8 bytes
Date: Thu, 26 Nov 2026 20:33:33 +0000 (UTC)	[thread overview]
Message-ID: <b2b87080b87c640725acc68ec507cf39cc2ed37d2524036c52326923c8d1eb0b@mail.kernel.org> (raw)
In-Reply-To: <20261126194347.42466-3-tphilipp@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2115 bytes --]

> bpf: Align lpm_trie map values to 8 bytes

TL;DR: Commit message only: the claim that lpm_trie nodes don't grow looks
wrong for data sizes with remainder 5-7 mod 8, where nodes get 1-3 bytes
bigger, possibly moving to a larger kmalloc bucket. Code looks correct.

> Place the value at the next 8-byte boundary after the key bytes. So
> that nodes don't grow, shrink prefixlen and flags to u16: prefixlen is
> at most 2048 and flags has one bit. data[] moves to offset 20 (64-bit)
> or 12 (32-bit). Bytes that bpf_mem_alloc asks from kmalloc on 64-bit:
>   data_size  value_size  before  after
>   ---------  ----------  ------  -----
>   4          28          64      60
>   4          60          96      92
>   16         16          64      64
>   20         12          64      60

Is the statement "So that nodes don't grow" accurate for all key sizes?

The bytes in front of the value change from sizeof(struct lpm_trie_node) +
data_size (24 + ds on 64-bit, 16 + ds on 32-bit) to
round_up(offsetof(struct lpm_trie_node, data) + data_size, 8), which is
round_up(20 + ds, 8) or round_up(12 + ds, 8).

The difference is (padding - 4), with padding between 0 and 7.  When
data_size % 8 is 5, 6 or 7, the node becomes 3, 2 or 1 bytes bigger on both
64-bit and 32-bit.  For example, with data_size 6 (an IPv4 address plus a
port), 24 + 6 = 30 becomes round_up(26, 8) = 32.

The growth can also move a node into a larger kmalloc bucket.  On 64-bit
with data_size 5 and value_size 27, the request is 24 + 5 + 27 + 8 = 64
before and 32 + 27 + 8 = 67 after, so the node moves from kmalloc-64 to
kmalloc-96.  The table only lists data_size 4, 16 and 20, where nodes
shrink or stay the same.

The code looks correct, so this is about the rationale.  Could the wording
say that the u16 shrink keeps the alignment padding to at most 3 bytes and
makes IPv4 nodes 4 bytes smaller?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45888065586

  reply	other threads:[~2026-11-26 20:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 19:43 [PATCH bpf-next v3 0/4] bpf: Fix 8-byte alignment of map values Tobias Philipp
2026-11-26 19:43 ` [PATCH bpf-next v3 1/4] bpf: Fix alignment of memory allocator objects on 32-bit archs Tobias Philipp
2026-11-26 19:43 ` [PATCH bpf-next v3 2/4] bpf: Align lpm_trie map values to 8 bytes Tobias Philipp
2026-11-26 20:33   ` bot+bpf-ci [this message]
2026-11-26 19:43 ` [PATCH bpf-next v3 3/4] bpf: Align devmap " Tobias Philipp
2026-11-26 19:43 ` [PATCH bpf-next v3 4/4] selftests/bpf: Check that map values are 8-byte aligned Tobias Philipp

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=b2b87080b87c640725acc68ec507cf39cc2ed37d2524036c52326923c8d1eb0b@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=daniel@zonque.org \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=hacks@slashdirt.org \
    --cc=hawk@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=nbd@nbd.name \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=stijn@linux-ipv6.be \
    --cc=tphilipp@gmail.com \
    --cc=yonghong.song@linux.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

all inboxes | Powered by JetHome®