History

bpf: charge user for creation of BPF maps and programs

since eBPF programs and maps use kernel memory consider it 'locked' memory from user accounting point of view and charge it against RLIMIT_MEMLOCK limit. This limit is typically set to 64Kbytes by distros, so almost all bpf+tracing programs would need to increase it, since they use maps, but kernel charges maximum map size upfront. For example the hash map of 1024 elements will be charged as 64Kbyte. It's inconvenient for current users and changes current behavior for root, but probably worth doing to be consistent root vs non-root. Similar accounting logic is done by mmap of perf_event.

Alexei Starovoitov committed 11 years ago

Commit aaac3ba1 parent 1be7f755 files · +72 −2Browse files

Showing the changes to kernel/bpf/arraymap.c (1 of 5 files). Show all

Unified · Split

kernel/bpf/arraymap.c+1−1
@@ -49,7 +49,7 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr) · 48 unmodified lines
4949 array->map.key_size = attr->key_size;
5050 array->map.value_size = attr->value_size;
5151 array->map.max_entries = attr->max_entries;
52−
52+ array->map.pages = round_up(array_size, PAGE_SIZE) >> PAGE_SHIFT;
5353 array->elem_size = elem_size;
5454
5555 return &array->map;