Re: [PATCH bpf-next v3 2/4] bpf: Align lpm_trie map values to 8 bytes
From: bot+bpf-ci
Date: Thu Nov 26 2026 - 15:33:47 EST
> 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