* [PATCH] lib/test_meminit: optimize do_kmem_cache_rcu_persistent() test
@ 2022-03-23 3:48 xkernel.wang
2022-03-25 21:47 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: xkernel.wang @ 2022-03-23 3:48 UTC (permalink / raw)
To: glider, akpm
Cc: andreyknvl, elver, dvyukov, ryabinin.a.a, kasan-dev, linux-mm,
linux-kernel, Xiaoke Wang
From: Xiaoke Wang <xkernel.wang@foxmail.com>
To make the test more robust, there are the following changes:
1. add a check for the return value of kmem_cache_alloc().
2. properly release the object `buf` on several error paths.
3. release the objects of `used_objects` if we never hit `saved_ptr`.
4. destroy the created cache by default.
Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
lib/test_meminit.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/lib/test_meminit.c b/lib/test_meminit.c
index 2f4c4bc..8d77c3f 100644
--- a/lib/test_meminit.c
+++ b/lib/test_meminit.c
@@ -300,13 +300,18 @@ static int __init do_kmem_cache_rcu_persistent(int size, int *total_failures)
c = kmem_cache_create("test_cache", size, size, SLAB_TYPESAFE_BY_RCU,
NULL);
buf = kmem_cache_alloc(c, GFP_KERNEL);
+ if (!buf)
+ goto out;
saved_ptr = buf;
fill_with_garbage(buf, size);
buf_contents = kmalloc(size, GFP_KERNEL);
- if (!buf_contents)
+ if (!buf_contents) {
+ kmem_cache_free(c, buf);
goto out;
+ }
used_objects = kmalloc_array(maxiter, sizeof(void *), GFP_KERNEL);
if (!used_objects) {
+ kmem_cache_free(c, buf);
kfree(buf_contents);
goto out;
}
@@ -327,11 +332,14 @@ static int __init do_kmem_cache_rcu_persistent(int size, int *total_failures)
}
}
+ for (iter = 0; iter < maxiter; iter++)
+ kmem_cache_free(c, used_objects[iter]);
+
free_out:
- kmem_cache_destroy(c);
kfree(buf_contents);
kfree(used_objects);
out:
+ kmem_cache_destroy(c);
*total_failures += fail;
return 1;
}
--
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] lib/test_meminit: optimize do_kmem_cache_rcu_persistent() test
2022-03-23 3:48 [PATCH] lib/test_meminit: optimize do_kmem_cache_rcu_persistent() test xkernel.wang
@ 2022-03-25 21:47 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2022-03-25 21:47 UTC (permalink / raw)
To: xkernel.wang
Cc: glider, andreyknvl, elver, dvyukov, ryabinin.a.a, kasan-dev,
linux-mm, linux-kernel
On Wed, 23 Mar 2022 11:48:24 +0800 xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
>
> To make the test more robust, there are the following changes:
> 1. add a check for the return value of kmem_cache_alloc().
> 2. properly release the object `buf` on several error paths.
> 3. release the objects of `used_objects` if we never hit `saved_ptr`.
> 4. destroy the created cache by default.
>
> ...
>
> --- a/lib/test_meminit.c
> +++ b/lib/test_meminit.c
> @@ -300,13 +300,18 @@ static int __init do_kmem_cache_rcu_persistent(int size, int *total_failures)
> c = kmem_cache_create("test_cache", size, size, SLAB_TYPESAFE_BY_RCU,
> NULL);
> buf = kmem_cache_alloc(c, GFP_KERNEL);
> + if (!buf)
> + goto out;
OK, Normally we don't bother checking allocation success in __init
code, but this test can run via modprobe, so I guess checking is the
right thing to do.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-03-25 21:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-23 3:48 [PATCH] lib/test_meminit: optimize do_kmem_cache_rcu_persistent() test xkernel.wang
2022-03-25 21:47 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).