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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EED42C433F5 for ; Fri, 18 Feb 2022 01:15:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F5B66B0095; Thu, 17 Feb 2022 20:15:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A5046B0096; Thu, 17 Feb 2022 20:15:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56D936B0098; Thu, 17 Feb 2022 20:15:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0001.hostedemail.com [216.40.44.1]) by kanga.kvack.org (Postfix) with ESMTP id 48EB56B0095 for ; Thu, 17 Feb 2022 20:15:19 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id F1785180D0E8C for ; Fri, 18 Feb 2022 01:15:18 +0000 (UTC) X-FDA: 79154132316.11.7267888 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf09.hostedemail.com (Postfix) with ESMTP id B8B93140009 for ; Fri, 18 Feb 2022 01:15:16 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4K0DCW57gwz1FD8j; Fri, 18 Feb 2022 09:10:47 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 18 Feb 2022 09:15:11 +0800 Subject: Re: [PATCH] mm/slab_common: use helper function is_power_of_2() To: Vlastimil Babka CC: , , Andrew Morton , Christoph Lameter , , , References: <20220217091609.8214-1-linmiaohe@huawei.com> <8f307e8a-5f97-cf5d-0a77-1c79b05abd60@suse.cz> <5d904bee-3faf-374a-090c-ce7c99c84ea9@huawei.com> <49a1bc35-7505-bc82-2931-e57f7b959cb3@suse.cz> From: Miaohe Lin Message-ID: <554115ed-3908-c970-aa1a-693b1c768551@huawei.com> Date: Fri, 18 Feb 2022 09:15:10 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <49a1bc35-7505-bc82-2931-e57f7b959cb3@suse.cz> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B8B93140009 X-Stat-Signature: 3ezdg8nc9pzms7m9y7qawhwdxh1yftpg Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf09.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-HE-Tag: 1645146916-296567 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 2022/2/18 1:04, Vlastimil Babka wrote: > On 2/17/22 11:44, Miaohe Lin wrote: >> On 2022/2/17 17:23, Vlastimil Babka wrote: >>> On 2/17/22 10:16, Miaohe Lin wrote: >>>> Use helper function is_power_of_2() to check if KMALLOC_MIN_SIZE is power >>>> of two. Minor readability improvement. >>>> >>>> Signed-off-by: Miaohe Lin >>> >>> We can try, but in case some compiler will no longer able to perform the >>> check at build-time (although is_power_of_2() looks sufficiently trivial >>> too), we'll have to revert it. >> >> I see. I checked the compiler in my env but there might be some compilers can't >> perform the check at build-time. > > I'll add this to the slab tree and linux-next and we'll see if wider testing > uncovers such compilers. Should be unlikely. Many thanks! :) > >> Many thanks for your reply. >> >>> >>>> --- >>>> mm/slab_common.c | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/mm/slab_common.c b/mm/slab_common.c >>>> index 23f2ab0713b7..6ee64d6208b3 100644 >>>> --- a/mm/slab_common.c >>>> +++ b/mm/slab_common.c >>>> @@ -807,7 +807,7 @@ void __init setup_kmalloc_cache_index_table(void) >>>> unsigned int i; >>>> >>>> BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 || >>>> - (KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1))); >>>> + !is_power_of_2(KMALLOC_MIN_SIZE)); >>>> >>>> for (i = 8; i < KMALLOC_MIN_SIZE; i += 8) { >>>> unsigned int elem = size_index_elem(i); >>> >>> . >>> >> > > . >