Skip to content

Commit

Permalink
bpf: make preloaded map iterators to display map elements count
Browse files Browse the repository at this point in the history
Add another column to the /sys/fs/bpf/maps.debug iterator to display
cur_entries, the current number of entries in the map as is returned
by the bpf_map_sum_elem_count kfunc. Also fix formatting.

Example:

    # cat /sys/fs/bpf/maps.debug
      id name             max_entries  cur_entries
       2 iterator.rodata            1            0
     125 cilium_auth_map       524288          666
     126 cilium_runtime_          256            0
     127 cilium_signals            32            0
     128 cilium_node_map        16384         1344
     129 cilium_events             32            0
     ...

Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
Link: https://lore.kernel.org/r/20230706133932.45883-5-aspsk@isovalent.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Anton Protopopov authored and Alexei Starovoitov committed Jul 6, 2023
1 parent 9bc421b commit 515ee52
Showing 2 changed files with 275 additions and 260 deletions.
9 changes: 7 additions & 2 deletions kernel/bpf/preload/iterators/iterators.bpf.c
Original file line number Diff line number Diff line change
@@ -73,6 +73,8 @@ static const char *get_name(struct btf *btf, long btf_id, const char *fallback)
return str + name_off;
}

__s64 bpf_map_sum_elem_count(struct bpf_map *map) __ksym;

SEC("iter/bpf_map")
int dump_bpf_map(struct bpf_iter__bpf_map *ctx)
{
@@ -84,9 +86,12 @@ int dump_bpf_map(struct bpf_iter__bpf_map *ctx)
return 0;

if (seq_num == 0)
BPF_SEQ_PRINTF(seq, " id name max_entries\n");
BPF_SEQ_PRINTF(seq, " id name max_entries cur_entries\n");

BPF_SEQ_PRINTF(seq, "%4u %-16s %10d %10lld\n",
map->id, map->name, map->max_entries,
bpf_map_sum_elem_count(map));

BPF_SEQ_PRINTF(seq, "%4u %-16s%6d\n", map->id, map->name, map->max_entries);
return 0;
}

Loading

0 comments on commit 515ee52

Please sign in to comment.