Message ID | 20190319211108.15495-3-vbabka@suse.cz (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | guarantee natural alignment for kmalloc() | expand |
On Tue, 19 Mar 2019, Vlastimil Babka wrote: > Quick and dirty init test that kmalloc() alignment works as expected for > power-of-two sizes after the previous patch. There is already an allocator testing function in mm/slub.c. Can you generalize it or portions and put the into mm/slab_common.c?
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);
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(+)