Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/test_vmalloc: add no_block_alloc_test case

Patch series "__vmalloc()/kvmalloc() and no-block support", v4.


This patch (of 10):

Introduce a new test case "no_block_alloc_test" that verifies non-blocking
allocations using __vmalloc() with GFP_ATOMIC and GFP_NOWAIT flags.

It is recommended to build kernel with CONFIG_DEBUG_ATOMIC_SLEEP enabled
to help catch "sleeping while atomic" issues. This test ensures that
memory allocation logic under atomic constraints does not inadvertently
sleep.

Link: https://lkml.kernel.org/r/20251007122035.56347-2-urezki@gmail.com
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Marco Elver <elver@google.com>
Cc: Michal Hocko <mhocko@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Uladzislau Rezki (Sony) and committed by
Andrew Morton
9ff86ca1 11119b19

+26
+26
lib/test_vmalloc.c
··· 54 54 "\t\tid: 256, name: kvfree_rcu_1_arg_vmalloc_test\n" 55 55 "\t\tid: 512, name: kvfree_rcu_2_arg_vmalloc_test\n" 56 56 "\t\tid: 1024, name: vm_map_ram_test\n" 57 + "\t\tid: 2048, name: no_block_alloc_test\n" 57 58 /* Add a new test case description here. */ 58 59 ); 59 60 ··· 284 283 return 0; 285 284 } 286 285 286 + static int no_block_alloc_test(void) 287 + { 288 + void *ptr; 289 + int i; 290 + 291 + for (i = 0; i < test_loop_count; i++) { 292 + bool use_atomic = !!(get_random_u8() % 2); 293 + gfp_t gfp = use_atomic ? GFP_ATOMIC : GFP_NOWAIT; 294 + unsigned long size = (nr_pages > 0 ? nr_pages : 1) * PAGE_SIZE; 295 + 296 + preempt_disable(); 297 + ptr = __vmalloc(size, gfp); 298 + preempt_enable(); 299 + 300 + if (!ptr) 301 + return -1; 302 + 303 + *((__u8 *)ptr) = 0; 304 + vfree(ptr); 305 + } 306 + 307 + return 0; 308 + } 309 + 287 310 static int 288 311 pcpu_alloc_test(void) 289 312 { ··· 436 411 { "kvfree_rcu_1_arg_vmalloc_test", kvfree_rcu_1_arg_vmalloc_test, }, 437 412 { "kvfree_rcu_2_arg_vmalloc_test", kvfree_rcu_2_arg_vmalloc_test, }, 438 413 { "vm_map_ram_test", vm_map_ram_test, }, 414 + { "no_block_alloc_test", no_block_alloc_test, true }, 439 415 /* Add a new test case here. */ 440 416 }; 441 417