linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kmalloc_index optimization(add kmalloc max size check)
@ 2020-04-17  7:09 Bernard Zhao
  2020-04-17 11:39 ` Michal Hocko
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Bernard Zhao @ 2020-04-17  7:09 UTC (permalink / raw)
  To: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, linux-mm, linux-kernel
  Cc: kernel, Bernard Zhao

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



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-04-21 15:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-17  7:09 [PATCH] kmalloc_index optimization(add kmalloc max size check) Bernard Zhao
2020-04-17 11:39 ` Michal Hocko
2020-04-17 12:17   ` 赵军奎
2020-04-17 13:42     ` Michal Hocko
2020-04-17 15:59 ` Christopher Lameter
2020-04-18  1:32   ` 赵军奎
2020-04-19 16:42     ` Christopher Lameter
2020-04-21  2:53       ` 赵军奎
2020-04-21 15:57         ` Christopher Lameter
2020-04-21 14:15 ` Vlastimil Babka

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).