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 D0FC3C433ED for ; Mon, 10 May 2021 10:09:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 55BE5613AF for ; Mon, 10 May 2021 10:09:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 55BE5613AF 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 C64496B0070; Mon, 10 May 2021 06:09:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C3CB26B0071; Mon, 10 May 2021 06:09:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADC7B6B0072; Mon, 10 May 2021 06:09:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0217.hostedemail.com [216.40.44.217]) by kanga.kvack.org (Postfix) with ESMTP id 889A66B0070 for ; Mon, 10 May 2021 06:09:58 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 35484181AF5CA for ; Mon, 10 May 2021 10:09:58 +0000 (UTC) X-FDA: 78124900476.15.AE91070 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf01.hostedemail.com (Postfix) with ESMTP id DD36E5001536 for ; Mon, 10 May 2021 10:09:54 +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 941E8B1B0; Mon, 10 May 2021 10:09:56 +0000 (UTC) To: Hyeonggon Yoo <42.hyeyoo@gmail.com>, Matthew Wilcox Cc: 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> From: Vlastimil Babka Subject: Re: [PATCH] mm: kmalloc_index: remove case when size is more than 32MB Message-ID: Date: Mon, 10 May 2021 12:09:55 +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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.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: fcd7ji6g9q6dq7bcquu8gzmeigihhr89 X-Rspamd-Queue-Id: DD36E5001536 X-Rspamd-Server: rspam05 Received-SPF: none (suse.cz>: No applicable sender policy available) receiver=imf01; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1620641394-311582 Content-Transfer-Encoding: quoted-printable 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/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 "optimis= e" >> kmalloc_index, failing to appreciate that it's only ever run at compil= e >> time because it's all under __builtin_constant_p(). >=20 > Oh thanks, I didn't know about __builtin_constant_p. >=20 > 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? >=20 > 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 in= dex to overflow - if someone increased KMALLOC_SHIFT_HIGH from 25 to 26, all sho= uld be fine, AFAICS. The problem would be if someone increased it to 27, then we might suddenl= y 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 com= piler 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 eval= uated and thus no attempts at "optimizing" the code should be made.