lkml.org 
[lkml]   [2020]   [Apr]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] kmalloc_index optimization(add kmalloc max size check)
Date
kmalloc size should never exceed KMALLOC_MAX_SIZE.
kmalloc_index realise if size is exceed KMALLOC_MAX_SIZE, e.g 64M,
kmalloc_index just return index 26, but never check with OS`s max
kmalloc config KMALLOC_MAX_SIZE. This index`s kmalloc caches maybe
not create in function create_kmalloc_caches.
We can throw an warninginfo in kmalloc at the beginning, instead of
being guaranteed by the buddy alloc behind.

Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
include/linux/slab.h | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 6d45488..59b60d2 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -351,6 +351,10 @@ static __always_inline unsigned int kmalloc_index(size_t size)
if (!size)
return 0;

+ /* size should never exceed KMALLOC_MAX_SIZE. */
+ if (size > KMALLOC_MAX_SIZE)
+ WARN(1, "size exceed max kmalloc size!\n");
+
if (size <= KMALLOC_MIN_SIZE)
return KMALLOC_SHIFT_LOW;

--
2.7.4
\
 
 \ /
  Last update: 2020-04-17 09:18    [W:0.095 / U:0.336 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site