From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C720C54FC9 for ; Tue, 21 Apr 2020 14:15:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5C2542070B for ; Tue, 21 Apr 2020 14:15:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C2542070B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F3BBD8E0005; Tue, 21 Apr 2020 10:15:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEAB88E0003; Tue, 21 Apr 2020 10:15:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB2CC8E0005; Tue, 21 Apr 2020 10:15:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0009.hostedemail.com [216.40.44.9]) by kanga.kvack.org (Postfix) with ESMTP id C30BA8E0003 for ; Tue, 21 Apr 2020 10:15:40 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 13ABB180AD82F for ; Tue, 21 Apr 2020 14:15:40 +0000 (UTC) X-FDA: 76732060440.01.line87_4e80a7c94d049 X-HE-Tag: line87_4e80a7c94d049 X-Filterd-Recvd-Size: 2700 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Tue, 21 Apr 2020 14:15:38 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A1E0AAEF7; Tue, 21 Apr 2020 14:15:35 +0000 (UTC) Subject: Re: [PATCH] kmalloc_index optimization(add kmalloc max size check) To: Bernard Zhao , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: kernel@vivo.com References: <1587107376-111722-1-git-send-email-bernard@vivo.com> From: Vlastimil Babka Message-ID: <05bedc84-3672-975c-87ee-f094ca766ee8@suse.cz> Date: Tue, 21 Apr 2020 16:15:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <1587107376-111722-1-git-send-email-bernard@vivo.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 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; > >