Skip to content

Commit 5b95e63

Browse files
Yonghong SongAlexei Starovoitov
authored andcommitted
bpf: Refill only one percpu element in memalloc
Typically for percpu map element or data structure, once allocated, most operations are lookup or in-place update. Deletion are really rare. Currently, for percpu data strcture, 4 elements will be refilled if the size is <= 256. Let us just do with one element for percpu data. For example, for size 256 and 128 cpus, the potential saving will be 3 * 256 * 128 * 128 = 12MB. Acked-by: Hou Tao <[email protected]> Signed-off-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent c39aa3b commit 5b95e63

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

kernel/bpf/memalloc.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,16 @@ static void init_refill_work(struct bpf_mem_cache *c)
485485

486486
static void prefill_mem_cache(struct bpf_mem_cache *c, int cpu)
487487
{
488-
/* To avoid consuming memory assume that 1st run of bpf
489-
* prog won't be doing more than 4 map_update_elem from
490-
* irq disabled region
488+
int cnt = 1;
489+
490+
/* To avoid consuming memory, for non-percpu allocation, assume that
491+
* 1st run of bpf prog won't be doing more than 4 map_update_elem from
492+
* irq disabled region if unit size is less than or equal to 256.
493+
* For all other cases, let us just do one allocation.
491494
*/
492-
alloc_bulk(c, c->unit_size <= 256 ? 4 : 1, cpu_to_node(cpu), false);
495+
if (!c->percpu_size && c->unit_size <= 256)
496+
cnt = 4;
497+
alloc_bulk(c, cnt, cpu_to_node(cpu), false);
493498
}
494499

495500
/* When size != 0 bpf_mem_cache for each cpu.

0 commit comments

Comments
 (0)