From: Vlastimil Babka <vbabka@suse.cz>
To: Bernard Zhao <bernard@vivo.com>, Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: kernel@vivo.com
Subject: Re: [PATCH] kmalloc_index optimization(add kmalloc max size check)
Date: Tue, 21 Apr 2020 16:15:33 +0200 [thread overview]
Message-ID: <05bedc84-3672-975c-87ee-f094ca766ee8@suse.cz> (raw)
In-Reply-To: <1587107376-111722-1-git-send-email-bernard@vivo.com>
On 4/17/20 9:09 AM, Bernard Zhao wrote:
> 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>
kmalloc_index() is only called from kmalloc() and kmalloc_node() for
compile-time constant sizes up to KMALLOC_MAX_CACHE_SIZE, which is smaller
(SLUB, SLOB) or equal (SLAB) than KMALLOC_MAX_SIZE. So your patch is effectively
a no-op and we better shouldn't tease the compiler too much, so that
kmalloc_index() stays fully compile-time evaluated.
> ---
> 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;
>
>
prev parent reply other threads:[~2020-04-21 14:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=05bedc84-3672-975c-87ee-f094ca766ee8@suse.cz \
--to=vbabka@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=bernard@vivo.com \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=kernel@vivo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).