Skip to content

Commit 5ed4b6b

Browse files
zhouwenhaoakpm00
authored andcommitted
objpool: fix the overestimation of object pooling metadata size
objpool uses struct objpool_head to store metadata information, and its cpu_slots member points to an array of pointers that store the addresses of the percpu ring arrays. However, the memory size allocated during the initialization of cpu_slots is nr_cpu_ids * sizeof(struct objpool_slot). On a 64-bit machine, the size of struct objpool_slot is 16 bytes, which is twice the size of the actual pointer required, and the extra memory is never be used, resulting in a waste of memory. Therefore, the memory size required for cpu_slots needs to be corrected. Link: https://lkml.kernel.org/r/20260202132846.68257-1-zhouwenhao7600@gmail.com Fixes: b4edb8d ("lib: objpool added: ring-array based lockless MPMC") Signed-off-by: zhouwenhao <zhouwenhao7600@gmail.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: "Masami Hiramatsu (Google)" <mhiramat@kernel.org> Cc: Matt Wu <wuqiang.matt@bytedance.com> Cc: wuqiang.matt <wuqiang.matt@bytedance.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent b243355 commit 5ed4b6b

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

lib/objpool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int objpool_init(struct objpool_head *pool, int nr_objs, int object_size,
142142
pool->gfp = gfp & ~__GFP_ZERO;
143143
pool->context = context;
144144
pool->release = release;
145-
slot_size = nr_cpu_ids * sizeof(struct objpool_slot);
145+
slot_size = nr_cpu_ids * sizeof(struct objpool_slot *);
146146
pool->cpu_slots = kzalloc(slot_size, pool->gfp);
147147
if (!pool->cpu_slots)
148148
return -ENOMEM;

0 commit comments

Comments
 (0)