From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Randy Dunlap <rdunlap@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Linux-Sparse <linux-sparse@vger.kernel.org>,
Martin KaFai Lau <kafai@fb.com>,
Arthur Fabre <afabre@cloudflare.com>
Subject: Re: sparse problem with Linux kernel v5.5
Date: Thu, 6 Feb 2020 21:06:10 +0100 [thread overview]
Message-ID: <20200206200610.7ktqp2yzriw7zurx@ltop.local> (raw)
In-Reply-To: <3b68ba4b-f16a-8404-4e07-27788ebbfce3@infradead.org>
On Thu, Feb 06, 2020 at 10:25:39AM -0800, Randy Dunlap wrote:
>
> All of the oom-killer instances list sphinx-build as running, and I often
> have OOM problems using it (make htmldocs), so that may be a factor.
>
> This morning sparse is handling bpf_sk_storage.c OK (no sphinx-build running).
OK, make sense.
However, I thought that the 5+seconds of runtime with 2.9Gb of memory
consumption I reported earlier was somehow excessive. So, I looked
at the preprocessed file and my editor (and several other tools) chocked
near the end ... It appears that one line is 2.8Mb on a total of 6.2MB
and contains 28968 times the expression for num_possible_cpus().
The origin of this is situted at line 647:
smap->bucket_log = max_t(u32, 1, ilog2(roundup_pow_of_two(...));
because ilog2() is an 'interesting' macro which is already expanded
inside roundup_pow_of_two().
This exists since the introduction of this file in commit
6ac99e8f23d4 bpf: Introduce bpf sk local storage
but back then it made sparse consume only about 500Mb of memory on it.
Use of the macro max_t make things even worse in commit
85749218e3a6 ("bpf: Fix out of bounds memory access in bpf_sk_storage")
To illustrate the situation, the following patch cuts sparse memory consumption
down to 109Mb in 0.3s:
diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c
index 458be6b3eda9..bdf4a1a256c3 100644
--- a/net/core/bpf_sk_storage.c
+++ b/net/core/bpf_sk_storage.c
@@ -644,7 +644,7 @@ static struct bpf_map *bpf_sk_storage_map_alloc(union bpf_attr *attr)
bpf_map_init_from_attr(&smap->map, attr);
/* Use at least 2 buckets, select_bucket() is undefined behavior with 1 bucket */
- smap->bucket_log = max_t(u32, 1, ilog2(roundup_pow_of_two(num_possible_cpus())));
+ smap->bucket_log = max_t(u32, 1, ilog2(__roundup_pow_of_two(num_possible_cpus())));
nbuckets = 1U << smap->bucket_log;
cost = sizeof(*smap->buckets) * nbuckets + sizeof(*smap);
but a better patch should, I think, directly use ilog2() and avoid the roundup.
Cheers,
-- Luc
next prev parent reply other threads:[~2020-02-06 20:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-06 4:49 sparse problem with Linux kernel v5.5 Randy Dunlap
2020-02-06 4:58 ` Randy Dunlap
2020-02-06 7:18 ` Linus Torvalds
2020-02-06 11:46 ` Luc Van Oostenryck
2020-02-06 18:25 ` Randy Dunlap
2020-02-06 20:06 ` Luc Van Oostenryck [this message]
2020-02-06 23:47 ` Linus Torvalds
2020-02-07 0:34 ` Martin KaFai Lau
2020-02-07 10:35 ` Luc Van Oostenryck
2020-02-07 6:34 ` Uwe Kleine-König
2020-02-07 8:29 ` Martin KaFai Lau
2020-02-07 11:34 ` Uwe Kleine-König
2020-02-07 12:43 ` Luc Van Oostenryck
2020-02-07 10:31 ` Luc Van Oostenryck
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=20200206200610.7ktqp2yzriw7zurx@ltop.local \
--to=luc.vanoostenryck@gmail.com \
--cc=afabre@cloudflare.com \
--cc=kafai@fb.com \
--cc=linux-sparse@vger.kernel.org \
--cc=rdunlap@infradead.org \
--cc=torvalds@linux-foundation.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