Message ID | 20221221013036.3427431-1-martin.lau@linux.dev (mailing list archive) |
---|---|
State | Accepted |
Commit | 552d42a356ebf78df9d2f4b73e077d2459966fac |
Delegated to: | BPF |
Headers | show |
Series | [v3,bpf-next] bpf: Reduce smap->elem_size | expand |
Hello: This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <daniel@iogearbox.net>: On Tue, 20 Dec 2022 17:30:36 -0800 you wrote: > From: Martin KaFai Lau <martin.lau@kernel.org> > > 'struct bpf_local_storage_elem' has an unused 56 byte padding at the > end due to struct's cache-line alignment requirement. This padding > space is overlapped by storage value contents, so if we use sizeof() > to calculate the total size, we overinflate it by 56 bytes. Use > offsetof() instead to calculate more exact memory use. > > [...] Here is the summary with links: - [v3,bpf-next] bpf: Reduce smap->elem_size https://git.kernel.org/bpf/bpf-next/c/552d42a356eb You are awesome, thank you!
diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c index b39a46e8fb08..373c3c2c75bc 100644 --- a/kernel/bpf/bpf_local_storage.c +++ b/kernel/bpf/bpf_local_storage.c @@ -580,8 +580,8 @@ static struct bpf_local_storage_map *__bpf_local_storage_map_alloc(union bpf_att raw_spin_lock_init(&smap->buckets[i].lock); } - smap->elem_size = - sizeof(struct bpf_local_storage_elem) + attr->value_size; + smap->elem_size = offsetof(struct bpf_local_storage_elem, + sdata.data[attr->value_size]); return smap; }