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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 C51BAC433ED for ; Mon, 10 May 2021 14:04:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1EB6D61042 for ; Mon, 10 May 2021 14:04:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1EB6D61042 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 912616B006E; Mon, 10 May 2021 10:04:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C2A66B0071; Mon, 10 May 2021 10:04:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B1606B0072; Mon, 10 May 2021 10:04:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0157.hostedemail.com [216.40.44.157]) by kanga.kvack.org (Postfix) with ESMTP id 5D2116B006E for ; Mon, 10 May 2021 10:04:11 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 0FE1182499B9 for ; Mon, 10 May 2021 14:04:11 +0000 (UTC) X-FDA: 78125490702.31.43BFE40 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf21.hostedemail.com (Postfix) with ESMTP id B36D8E0011FD for ; Mon, 10 May 2021 14:04:04 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 4EA16AFE6; Mon, 10 May 2021 14:04:08 +0000 (UTC) Subject: Re: [PATCH] mm: kmalloc_index: remove case when size is more than 32MB To: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Matthew Wilcox , cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20210508221328.7338-1-42.hyeyoo@gmail.com> <20210510135857.GA3594@hyeyoo> From: Vlastimil Babka Message-ID: <9d0ffe49-a2e2-6c81-377b-4c8d2147dff8@suse.cz> Date: Mon, 10 May 2021 16:04:07 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210510135857.GA3594@hyeyoo> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Stat-Signature: gm5oyeicajunw74e6umco5786seowotr X-Rspamd-Queue-Id: B36D8E0011FD X-Rspamd-Server: rspam05 Received-SPF: none (suse.cz>: No applicable sender policy available) receiver=imf21; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1620655444-945343 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 5/10/21 3:58 PM, Hyeonggon Yoo wrote: > On Mon, May 10, 2021 at 12:09:55PM +0200, Vlastimil Babka wrote: >> On 5/9/21 7:33 AM, Hyeonggon Yoo wrote: >> > On Sun, May 09, 2021 at 12:19:40AM +0100, Matthew Wilcox wrote: >> >> On Sun, May 09, 2021 at 07:13:28AM +0900, Hyeonggon Yoo wrote: >> >> > the return value of kmalloc_index is used as index of kmalloc_caches, >> >> >> >> it doesn't matter. every few weeks somebody posts a patch to "optimise" >> >> kmalloc_index, failing to appreciate that it's only ever run at compile >> >> time because it's all under __builtin_constant_p(). >> > >> > Oh thanks, I didn't know about __builtin_constant_p. >> > >> > But I was not optimizing kmalloc_index. isn't it confusing that >> > kmalloc_caches alllows maximum size of 32MB, and kmalloc_index allows >> > maximum size of 64MB? >> > >> > and even if the code I removed is never reached because 64MB is always >> > bigger than KMALLOC_MAX_CACHE_SIZE, it will cause an error if reached. >> >> KMALLOC_MAX_CACHE_SIZE depends on KMALLOC_SHIFT_HIGH >> size of kmalloc_caches array depends on KMALLOC_SHIFT_HIGH >> >> So I don't an easy way how it could become reachable while causing the index to >> overflow - if someone increased KMALLOC_SHIFT_HIGH from 25 to 26, all should be >> fine, AFAICS. >> >> The problem would be if someone increased it to 27, then we might suddenly get a >> BUG() in kmalloc_index(). We should probably replace that BUG() with >> BUILD_BUG_ON(1) to catch that at compile time. Hopefully no supported compiler >> will break because it's not able to do the proper compile-time evaluation - but >> if it does, at least we would know. >> >> So I would accept the patch if it also changed BUG() to e.g. BUILD_BUG_ON_MSG(1, >> "unexpected size in kmalloc_index()"); >> and expanded the function's comment that this is always compile-time evaluated >> and thus no attempts at "optimizing" the code should be made. >> > > Thank you so much reviewing and replying to my patch. > plecase check if I understood well. > > Okay, I'll do that work. then the following patch will: > - remove case when size is more than 32MB > - change "BUG to BUILD_BUG_ON to let compiler know when the size is not supported" > - add comment that there's no need to optimize it > > is it what you mean. right? Exactly. > and I have a question. in the lin 751 of mm/slab_common.c, > thre's struct kmalloc_info_struct kmalloc_info. and it initializes kmalloc info > up to 64MB, which is currently not supported. should I change it too? in a separate patch? Yeah that could be also changed, in the same patch.