History

bpf: stackmap memory usage

A new helper is introduced to get stackmap memory usage. Some small memory allocations are ignored as their memory size is quite small compared to the totol usage. The result as follows, - before 16: stack_trace name count_map flags 0x0 key 4B value 8B max_entries 65536 memlock 1048576B - after 16: stack_trace name count_map flags 0x0 key 4B value 8B max_entries 65536 memlock 2097472B

Yafang Shao committed 3 years ago

Commit cbb9b601 parent 1746d051 file · +14 −0Browse files

Showing the changes to kernel/bpf/stackmap.c (1 of 1 file). Show all

Unified · Split

kernel/bpf/stackmap.c+14−0
@@ -654,6 +654,19 @@ static void stack_map_free(struct bpf_map *map) · 653 unmodified lines
654 put_callchain_buffers();654 put_callchain_buffers();
655}655}
656 656
657static u64 stack_map_mem_usage(const struct bpf_map *map)
658{
659 struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map);
660 u64 value_size = map->value_size;
661 u64 n_buckets = smap->n_buckets;
662 u64 enties = map->max_entries;
663 u64 usage = sizeof(*smap);
664
665 usage += n_buckets * sizeof(struct stack_map_bucket *);
666 usage += enties * (sizeof(struct stack_map_bucket) + value_size);
667 return usage;
668}
669
657BTF_ID_LIST_SINGLE(stack_trace_map_btf_ids, struct, bpf_stack_map)670BTF_ID_LIST_SINGLE(stack_trace_map_btf_ids, struct, bpf_stack_map)
658const struct bpf_map_ops stack_trace_map_ops = {671const struct bpf_map_ops stack_trace_map_ops = {
659 .map_meta_equal = bpf_map_meta_equal,672 .map_meta_equal = bpf_map_meta_equal,
@@ -664,5 +677,6 @@ const struct bpf_map_ops stack_trace_map_ops = { · 4 unmodified lines
664 .map_update_elem = stack_map_update_elem,677 .map_update_elem = stack_map_update_elem,
665 .map_delete_elem = stack_map_delete_elem,678 .map_delete_elem = stack_map_delete_elem,
666 .map_check_btf = map_check_no_btf,679 .map_check_btf = map_check_no_btf,
680 .map_mem_usage = stack_map_mem_usage,
667 .map_btf_id = &stack_trace_map_btf_ids[0],681 .map_btf_id = &stack_trace_map_btf_ids[0],
668};682};

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t