From: "Ho-Ren (Jack) Chuang" <horenchuang@bytedance.com>
To: Alexei Starovoitov <ast@kernel.org>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>,
Jiri Olsa <olsajiri@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>,
Quentin Monnet <quentin@isovalent.com>,
Mykola Lysenko <mykolal@fb.com>, Shuah Khan <shuah@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Tom Rix <trix@redhat.com>, Joanne Koong <joannelkoong@gmail.com>,
Kui-Feng Lee <kuifeng@fb.com>,
Lorenzo Bianconi <lorenzo@kernel.org>,
Maxim Mikityanskiy <maximmi@nvidia.com>,
Hao Xiang <hao.xiang@bytedance.com>,
Punit Agrawal <punit.agrawal@bytedance.com>,
Yifei Ma <yifeima@bytedance.com>,
Xiaoning Ding <xiaoning.ding@bytedance.com>,
bpf@vger.kernel.org
Cc: Ho-Ren Chuang <horenc@vt.edu>,
Ho-Ren Chuang <horenchuang@bytedance.com>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
llvm@lists.linux.dev
Subject: [PATCH bpf-next v1 2/4] bpftool: Add tools support to show BPF htab map's used size
Date: Sat, 5 Nov 2022 02:51:44 +0000 [thread overview]
Message-ID: <20221105025146.238209-3-horenchuang@bytedance.com> (raw)
In-Reply-To: <20221105025146.238209-1-horenchuang@bytedance.com>
Add bpftool support for reporting the number of used entries of
htab maps by leveraging the newly added "used_entries" field in
struct bpf_map_info. It works with JSON as well.
To better understand actual used memory size of a htab map,
pre-allocated maps are now marked with "*" behind the "max_entries" size.
Signed-off-by: Ho-Ren (Jack) Chuang <horenchuang@bytedance.com>
---
tools/bpf/bpftool/map.c | 9 +++++++--
tools/include/uapi/linux/bpf.h | 1 +
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index 9a6ca9f31133..0b07abae7309 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -475,6 +475,8 @@ static int show_map_close_json(int fd, struct bpf_map_info *info)
jsonw_uint_field(json_wtr, "bytes_key", info->key_size);
jsonw_uint_field(json_wtr, "bytes_value", info->value_size);
jsonw_uint_field(json_wtr, "max_entries", info->max_entries);
+ if (info->type == BPF_MAP_TYPE_HASH)
+ jsonw_uint_field(json_wtr, "used_entries", info->used_entries);
if (memlock)
jsonw_int_field(json_wtr, "bytes_memlock", atoll(memlock));
@@ -561,8 +563,11 @@ static int show_map_close_plain(int fd, struct bpf_map_info *info)
frozen_str = get_fdinfo(fd, "frozen");
show_map_header_plain(info);
- printf("\tkey %uB value %uB max_entries %u",
- info->key_size, info->value_size, info->max_entries);
+ printf("\tkey %uB value %uB max_entries %u%1s",
+ info->key_size, info->value_size, info->max_entries,
+ !(info->map_flags & BPF_F_NO_PREALLOC) ? "*" : "");
+ if (info->type == BPF_MAP_TYPE_HASH)
+ printf(" used_entries %u", info->used_entries);
if (memlock)
printf(" memlock %sB", memlock);
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 17f61338f8f8..63659368cf0e 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -6215,6 +6215,7 @@ struct bpf_map_info {
__u32 id;
__u32 key_size;
__u32 value_size;
+ __u32 used_entries;
__u32 max_entries;
__u32 map_flags;
char name[BPF_OBJ_NAME_LEN];
--
Ho-Ren (Jack) Chuang
next prev parent reply other threads:[~2022-11-05 2:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-05 2:51 [PATCH bpf-next v1 0/4] Add BPF htab map's used size for monitoring Ho-Ren (Jack) Chuang
2022-11-05 2:51 ` [PATCH bpf-next v1 1/4] bpf: Support reporting " Ho-Ren (Jack) Chuang
2022-11-05 2:51 ` Ho-Ren (Jack) Chuang [this message]
2022-11-05 2:51 ` [PATCH bpf-next v1 3/4] samples/bpf: Add concurrency testing for BPF htab map's used size Ho-Ren (Jack) Chuang
2022-11-05 2:51 ` [PATCH bpf-next v1 4/4] selftests/bpf: Add unit tests " Ho-Ren (Jack) Chuang
2022-11-05 16:20 ` [PATCH bpf-next v1 0/4] Add BPF htab map's used size for monitoring Alexei Starovoitov
2022-11-08 0:30 ` [External] " Hao Xiang .
2022-11-28 23:03 ` Hao Xiang .
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=20221105025146.238209-3-horenchuang@bytedance.com \
--to=horenchuang@bytedance.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=hao.xiang@bytedance.com \
--cc=haoluo@google.com \
--cc=horenc@vt.edu \
--cc=joannelkoong@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuifeng@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=lorenzo@kernel.org \
--cc=martin.lau@linux.dev \
--cc=maximmi@nvidia.com \
--cc=mykolal@fb.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=olsajiri@gmail.com \
--cc=punit.agrawal@bytedance.com \
--cc=quentin@isovalent.com \
--cc=sdf@google.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=trix@redhat.com \
--cc=xiaoning.ding@bytedance.com \
--cc=yhs@fb.com \
--cc=yifeima@bytedance.com \
/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;
as well as URLs for NNTP newsgroup(s).