Skip to content

Commit cb6fcef

Browse files
mhiramatakpm00
authored andcommitted
objpool: fix to make percpu slot allocation more robust
Since gfp & GFP_ATOMIC == GFP_ATOMIC is true for GFP_KERNEL | GFP_HIGH, it will use kmalloc if user specifies that combination. Here the reason why combining the __vmalloc_node() and kmalloc_node() is that the vmalloc does not support all GFP flag, especially GFP_ATOMIC. So we should check if gfp & (GFP_ATOMIC | GFP_KERNEL) != GFP_ATOMIC for vmalloc first. This ensures caller can sleep. And for the robustness, even if vmalloc fails, it should retry with kmalloc to allocate it. Link: https://lkml.kernel.org/r/173008598713.1262174.2959179484209897252.stgit@mhiramat.roam.corp.google.com Fixes: aff1871 ("objpool: fix choosing allocation for percpu slots") Signed-off-by: Masami Hiramatsu (Google) <[email protected]> Reported-by: Linus Torvalds <[email protected]> Closes: https://lore.kernel.org/all/CAHk-=whO+vSH+XVRio8byJU8idAWES0SPGVZ7KAVdc4qrV0VUA@mail.gmail.com/ Cc: Leo Yan <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Matt Wu <[email protected]> Cc: Mikel Rychliski <[email protected]> Cc: Steven Rostedt (Google) <[email protected]> Cc: Viktor Malik <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c928807 commit cb6fcef

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/objpool.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,21 @@ objpool_init_percpu_slots(struct objpool_head *pool, int nr_objs,
7474
* warm caches and TLB hits. in default vmalloc is used to
7575
* reduce the pressure of kernel slab system. as we know,
7676
* mimimal size of vmalloc is one page since vmalloc would
77-
* always align the requested size to page size
77+
* always align the requested size to page size.
78+
* but if vmalloc fails or it is not available (e.g. GFP_ATOMIC)
79+
* allocate percpu slot with kmalloc.
7880
*/
79-
if ((pool->gfp & GFP_ATOMIC) == GFP_ATOMIC)
80-
slot = kmalloc_node(size, pool->gfp, cpu_to_node(i));
81-
else
81+
slot = NULL;
82+
83+
if ((pool->gfp & (GFP_ATOMIC | GFP_KERNEL)) != GFP_ATOMIC)
8284
slot = __vmalloc_node(size, sizeof(void *), pool->gfp,
8385
cpu_to_node(i), __builtin_return_address(0));
84-
if (!slot)
85-
return -ENOMEM;
86+
87+
if (!slot) {
88+
slot = kmalloc_node(size, pool->gfp, cpu_to_node(i));
89+
if (!slot)
90+
return -ENOMEM;
91+
}
8692
memset(slot, 0, size);
8793
pool->cpu_slots[i] = slot;
8894

0 commit comments

Comments
 (0)