lkml.org 
[lkml]   [2019]   [Mar]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC 2/2] mm, sl[aou]b: test whether kmalloc() alignment works as expected
Date
Quick and dirty init test that kmalloc() alignment works as expected for
power-of-two sizes after the previous patch.

Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
---
mm/slab_common.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

diff --git a/mm/slab_common.c b/mm/slab_common.c
index e591d5688558..de10ca9640e0 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -1621,3 +1621,22 @@ int should_failslab(struct kmem_cache *s, gfp_t gfpflags)
return 0;
}
ALLOW_ERROR_INJECTION(should_failslab, ERRNO);
+
+static int __init slab_kmalloc_test(void)
+{
+ int i;
+
+ for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
+ unsigned int size = 1 << i;
+ void * obj = kmalloc(size, GFP_KERNEL);
+ unsigned long objaddr = (unsigned long) obj;
+
+ printk("Size %u obj %px alignment: %s", size, obj,
+ (((objaddr & (size - 1)) == 0) ? "OK" : "WRONG"));
+ kfree(obj);
+ }
+
+ return 0;
+}
+
+__initcall(slab_kmalloc_test);
--
2.21.0
\
 
 \ /
  Last update: 2019-03-19 22:12    [W:0.164 / U:0.596 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site