From: Leon Hwang <leon.hwang@linux.dev>
To: bot+bpf-ci@kernel.org, bpf@vger.kernel.org
Cc: qmo@kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
linux-kernel@vger.kernel.org, martin.lau@kernel.org,
mason@kernel.org
Subject: Re: [PATCH bpf-next v2] bpftool: Compute map size of light skeletons at runtime
Date: Tue, 15 Sep 2026 10:27:25 +0800 [thread overview]
Message-ID: <2c54e00b-a01c-4400-acbd-f614c457cf92@linux.dev> (raw)
In-Reply-To: <c4f9dcfb3827ef826df36d4ed7d12d78694989fd6a6843967c094b8e879b2574@mail.kernel.org>
On 15/9/26 00:39, bot+bpf-ci@kernel.org wrote:
>> diff --git a/tools/lib/bpf/skel_internal.h b/tools/lib/bpf/skel_internal.h
>> index 1f3f332dffbe..6f23ea9410eb 100644
>> --- a/tools/lib/bpf/skel_internal.h
>> +++ b/tools/lib/bpf/skel_internal.h
>> @@ -11,6 +11,7 @@
>> #include <linux/bpf.h>
>> #else
>> #include <unistd.h>
>> +#include <sys/param.h>
>> #include <sys/syscall.h>
>> #include <sys/mman.h>
>> #include <linux/keyctl.h>
>
> [ ... ]
>
>> @@ -193,25 +197,34 @@ static inline void skel_free(void *p)
>> free(p);
>> }
>>
>> -static inline void skel_free_map_data(void *p, __u64 addr, size_t sz)
>> +static inline size_t skel_map_mmap_sz(size_t val_sz, __u32 max_entries)
>> {
>> - munmap(p, sz);
>> + return roundup(roundup(val_sz, 8) * max_entries, sysconf(_SC_PAGE_SIZE));
>> }
>
> This isn't a bug, but would it read closer to array_map_mmap_sz() to hoist
> the page size into a local here? sysconf(_SC_PAGE_SIZE) is passed straight
> into roundup()'s second argument, and roundup() is a macro that expands its
> second argument several times in the non-constant case. The three nearby
> equivalents all hoist it: the bpf_map_mmap_sz() this patch deletes from
> gen.c used 'long page_sz = sysconf(_SC_PAGE_SIZE);', and libbpf's
> array_map_mmap_sz() and bpf_map_mmap_sz() both open with 'const long page_sz
> = sysconf(_SC_PAGE_SIZE);'. Hoisting it here would also make the helper
> independent of which roundup() definition wins, and might let the new
> <sys/param.h> include be dropped.
Good catch.
'sysconf(_SC_PAGE_SIZE)' will be calculated several times in
'roundup(roundup(val_sz, 8) * max_entries, sysconf(_SC_PAGE_SIZE))'.
printf '%s\n' \
'#include <sys/param.h>' \
'roundup(roundup(val_sz, 8) * max_entries, sysconf(_SC_PAGE_SIZE))' |
gcc -E -P -x c - |
tail -n 1
(__builtin_constant_p (sysconf(_SC_PAGESIZE)) &&
((((sysconf(_SC_PAGESIZE)) - 1) & (sysconf(_SC_PAGESIZE))) == 0) ?
((((__builtin_constant_p (8) && ((((8) - 1) & (8)) == 0) ? (((val_sz) +
(8) - 1) & ~((8) - 1)) : ((((val_sz) + ((8) - 1)) / (8)) * (8))) *
max_entries) + (sysconf(_SC_PAGESIZE)) - 1) & ~((sysconf(_SC_PAGESIZE))
- 1)) : (((((__builtin_constant_p (8) && ((((8) - 1) & (8)) == 0) ?
(((val_sz) + (8) - 1) & ~((8) - 1)) : ((((val_sz) + ((8) - 1)) / (8)) *
(8))) * max_entries) + ((sysconf(_SC_PAGESIZE)) - 1)) /
(sysconf(_SC_PAGESIZE))) * (sysconf(_SC_PAGESIZE))))
Will hoist 'sysconf(_SC_PAGE_SIZE);' and 'roundup(val_sz, 8) * max_entries'.
However, the new <sys/param.h> is needed for roundup().
Thanks,
Leon
> [...]
prev parent reply other threads:[~2026-09-15 2:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 15:33 Leon Hwang
2026-09-14 16:39 ` bot+bpf-ci
2026-09-15 2:27 ` Leon Hwang [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=2c54e00b-a01c-4400-acbd-f614c457cf92@linux.dev \
--to=leon.hwang@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--cc=memxor@gmail.com \
--cc=qmo@kernel.org \
--cc=song@kernel.org \
--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®