mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mahe Tardy <mahe.tardy@gmail.com>
To: bpf@vger.kernel.org
Cc: Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	linux-kernel@vger.kernel.org,
	John Fastabend <john.fastabend@gmail.com>,
	Mahe Tardy <mahe.tardy@gmail.com>
Subject: [PATCH bpf-next v2 1/3] bpf: reuse local storage map link and unlink helpers
Date: Mon, 30 Nov 2026 20:14:02 +0000	[thread overview]
Message-ID: <20261130201404.80321-2-mahe.tardy@gmail.com> (raw)
In-Reply-To: <20261130201404.80321-1-mahe.tardy@gmail.com>

Route map-side insertions and removals through the existing _nolock
helpers. The following commit will use the bpf map elem counters helpers
from the _nolock functions to estimate the memory usage more accurately.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
---
 kernel/bpf/bpf_local_storage.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
index b12fcec47ffa..e470447d6218 100644
--- a/kernel/bpf/bpf_local_storage.c
+++ b/kernel/bpf/bpf_local_storage.c
@@ -240,6 +240,11 @@ void bpf_selem_link_storage_nolock(struct bpf_local_storage *local_storage,
 	hlist_add_head_rcu(&selem->snode, &local_storage->list);
 }

+static void bpf_selem_unlink_map_nolock(struct bpf_local_storage_elem *selem)
+{
+	hlist_del_init_rcu(&selem->map_node);
+}
+
 /* Must be called with the owning local_storage->lock held. */
 static int bpf_selem_unlink_map(struct bpf_local_storage_elem *selem)
 {
@@ -258,15 +263,16 @@ static int bpf_selem_unlink_map(struct bpf_local_storage_elem *selem)
 	if (err)
 		return err;

-	hlist_del_init_rcu(&selem->map_node);
+	bpf_selem_unlink_map_nolock(selem);
 	raw_res_spin_unlock(&b->lock);

 	return 0;
 }

-static void bpf_selem_unlink_map_nolock(struct bpf_local_storage_elem *selem)
+static void bpf_selem_link_map_nolock(struct bpf_local_storage_map_bucket *b,
+				      struct bpf_local_storage_elem *selem)
 {
-	hlist_del_init_rcu(&selem->map_node);
+	hlist_add_head_rcu(&selem->map_node, &b->list);
 }

 int bpf_selem_link_map(struct bpf_local_storage_map *smap,
@@ -283,18 +289,12 @@ int bpf_selem_link_map(struct bpf_local_storage_map *smap,
 	if (err)
 		return err;

-	hlist_add_head_rcu(&selem->map_node, &b->list);
+	bpf_selem_link_map_nolock(b, selem);
 	raw_res_spin_unlock_irqrestore(&b->lock, flags);

 	return 0;
 }

-static void bpf_selem_link_map_nolock(struct bpf_local_storage_map_bucket *b,
-				      struct bpf_local_storage_elem *selem)
-{
-	hlist_add_head_rcu(&selem->map_node, &b->list);
-}
-
 /*
  * Unlink an selem from map and local storage with lock held.
  * This is the common path used by local storages to delete an selem.
@@ -377,7 +377,7 @@ static void bpf_selem_unlink_nofail(struct bpf_local_storage_elem *selem,
 			 * is sleepable: see below.
 			 */
 			if (likely(selem_linked_to_map(selem))) {
-				hlist_del_init_rcu(&selem->map_node);
+				bpf_selem_unlink_map_nolock(selem);
 				if (sleepable_users)
 					keep_fields = true;
 				else
--
2.43.0


  reply	other threads:[~2026-11-30 20:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 20:14 [PATCH bpf-next v2 0/3] bpf: account for local storage map elements memory Mahe Tardy
2026-11-30 20:14 ` Mahe Tardy [this message]
2026-11-30 20:14 ` [PATCH bpf-next v2 2/3] " Mahe Tardy
2026-11-30 20:14 ` [PATCH bpf-next v2 3/3] selftests/bpf: test task storage memory accounting Mahe Tardy

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=20261130201404.80321-2-mahe.tardy@gmail.com \
    --to=mahe.tardy@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@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=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --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®