Skip to content

Commit

Permalink
lib/test_vmalloc.c: add vm_map_ram()/vm_unmap_ram() test case
Browse files Browse the repository at this point in the history
Add vm_map_ram()/vm_unmap_ram() test case to our stress test-suite.

[[email protected]: fix whitespace, per Lorenzo]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Uladzislau Rezki (Sony) <[email protected]>
Reviewed-by: Lorenzo Stoakes <[email protected]>
Reviewed-by: Baoquan He <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Dave Chinner <[email protected]>
Cc: Matthew Wilcox (Oracle) <[email protected]>
Cc: Oleksiy Avramchenko <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
urezki authored and akpm00 committed Apr 18, 2023
1 parent 062eacf commit 869cb29
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/test_vmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ __param(int, run_test_mask, INT_MAX,
"\t\tid: 128, name: pcpu_alloc_test\n"
"\t\tid: 256, name: kvfree_rcu_1_arg_vmalloc_test\n"
"\t\tid: 512, name: kvfree_rcu_2_arg_vmalloc_test\n"
"\t\tid: 1024, name: vm_map_ram_test\n"
/* Add a new test case description here. */
);

Expand Down Expand Up @@ -358,6 +359,41 @@ kvfree_rcu_2_arg_vmalloc_test(void)
return 0;
}

static int
vm_map_ram_test(void)
{
unsigned long nr_allocated;
unsigned int map_nr_pages;
unsigned char *v_ptr;
struct page **pages;
int i;

map_nr_pages = nr_pages > 0 ? nr_pages:1;
pages = kmalloc(map_nr_pages * sizeof(struct page), GFP_KERNEL);
if (!pages)
return -1;

nr_allocated = alloc_pages_bulk_array(GFP_KERNEL, map_nr_pages, pages);
if (nr_allocated != map_nr_pages)
goto cleanup;

/* Run the test loop. */
for (i = 0; i < test_loop_count; i++) {
v_ptr = vm_map_ram(pages, map_nr_pages, NUMA_NO_NODE);
*v_ptr = 'a';
vm_unmap_ram(v_ptr, map_nr_pages);
}

cleanup:
for (i = 0; i < nr_allocated; i++)
__free_page(pages[i]);

kfree(pages);

/* 0 indicates success. */
return nr_allocated != map_nr_pages;
}

struct test_case_desc {
const char *test_name;
int (*test_func)(void);
Expand All @@ -374,6 +410,7 @@ static struct test_case_desc test_case_array[] = {
{ "pcpu_alloc_test", pcpu_alloc_test },
{ "kvfree_rcu_1_arg_vmalloc_test", kvfree_rcu_1_arg_vmalloc_test },
{ "kvfree_rcu_2_arg_vmalloc_test", kvfree_rcu_2_arg_vmalloc_test },
{ "vm_map_ram_test", vm_map_ram_test },
/* Add a new test case here. */
};

Expand Down

0 comments on commit 869cb29

Please sign in to comment.