| From d261cc46e7d42d4a85a45f56a8b0b09a1509769d Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Mon, 2 Feb 2026 21:28:46 +0800 |
| Subject: objpool: fix the overestimation of object pooling metadata size |
| |
| From: zhouwenhao <zhouwenhao7600@gmail.com> |
| |
| [ Upstream commit 5ed4b6b37c647d168ae31035b3f61b705997e043 ] |
| |
| 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: b4edb8d2d464 ("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> |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| lib/objpool.c | 2 +- |
| 1 file changed, 1 insertion(+), 1 deletion(-) |
| |
| diff --git a/lib/objpool.c b/lib/objpool.c |
| index b998b720c7329..d98fadf1de169 100644 |
| --- a/lib/objpool.c |
| +++ b/lib/objpool.c |
| @@ -142,7 +142,7 @@ int objpool_init(struct objpool_head *pool, int nr_objs, int object_size, |
| pool->gfp = gfp & ~__GFP_ZERO; |
| pool->context = context; |
| pool->release = release; |
| - slot_size = nr_cpu_ids * sizeof(struct objpool_slot); |
| + slot_size = nr_cpu_ids * sizeof(struct objpool_slot *); |
| pool->cpu_slots = kzalloc(slot_size, pool->gfp); |
| if (!pool->cpu_slots) |
| return -ENOMEM; |
| -- |
| 2.51.0 |
| |