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=-16.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,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 A9E19C432BE for ; Wed, 1 Sep 2021 07:37:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F5EB60200 for ; Wed, 1 Sep 2021 07:37:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242652AbhIAHiu (ORCPT ); Wed, 1 Sep 2021 03:38:50 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:18997 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242604AbhIAHit (ORCPT ); Wed, 1 Sep 2021 03:38:49 -0400 Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Gzwm30xNnzblCM; Wed, 1 Sep 2021 15:33:55 +0800 (CST) Received: from [10.174.178.75] (10.174.178.75) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Wed, 1 Sep 2021 15:37:49 +0800 Subject: Re: [PATCH 2/6] mm/page_alloc.c: simplify the code by using macro K() To: Oleksandr Natalenko CC: , , , , , , Andrew Morton References: <20210830141051.64090-1-linmiaohe@huawei.com> <9161665.bUqNH3lxUD@natalenko.name> <52bbb8f2-db63-8c56-ea49-d982c13ba541@huawei.com> <9426505.MgecbftzqH@natalenko.name> From: Miaohe Lin Message-ID: <03653d41-abe0-46f0-9eee-28cad9f5edea@huawei.com> Date: Wed, 1 Sep 2021 15:37:49 +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: <9426505.MgecbftzqH@natalenko.name> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.75] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/8/31 22:19, Oleksandr Natalenko wrote: > Hello. > > On úterý 31. srpna 2021 13:08:42 CEST Miaohe Lin wrote: >> On 2021/8/31 16:54, Oleksandr Natalenko wrote: >>> Hello. >>> >>> On pondělí 30. srpna 2021 16:10:47 CEST Miaohe Lin wrote: >>>> Use helper macro K() to convert the pages to the corresponding size. >>>> Minor readability improvement. >>>> >>>> Signed-off-by: Miaohe Lin >>>> --- >>>> >>>> mm/page_alloc.c | 12 +++++------- >>>> 1 file changed, 5 insertions(+), 7 deletions(-) >>>> >>>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >>>> index dbb3338d9287..d3983244f56f 100644 >>>> --- a/mm/page_alloc.c >>>> +++ b/mm/page_alloc.c >>>> @@ -8134,8 +8134,7 @@ unsigned long free_reserved_area(void *start, void >>>> *end, int poison, const char } >>>> >>>> if (pages && s) >>>> >>>> - pr_info("Freeing %s memory: %ldK\n", >>>> - s, pages << (PAGE_SHIFT - 10)); >>>> + pr_info("Freeing %s memory: %ldK\n", s, K(pages)); >>>> >>>> return pages; >>>> >>>> } >>>> >>>> @@ -8180,14 +8179,13 @@ void __init mem_init_print_info(void) >>>> >>>> ", %luK highmem" >>>> >>>> #endif >>>> >>>> ")\n", >>>> >>>> - nr_free_pages() << (PAGE_SHIFT - 10), >>>> - physpages << (PAGE_SHIFT - 10), >>>> + K(nr_free_pages()), K(physpages), >>>> >>>> codesize >> 10, datasize >> 10, rosize >> 10, >>>> (init_data_size + init_code_size) >> 10, bss_size >> 10, >>>> >>>> - (physpages - totalram_pages() - totalcma_pages) << (PAGE_SHIFT >>> >>> - 10), >>> >>>> - totalcma_pages << (PAGE_SHIFT - 10) >>>> + K(physpages - totalram_pages() - totalcma_pages), >>>> + K(totalcma_pages) >>>> >>>> #ifdef CONFIG_HIGHMEM >>>> >>>> - , totalhigh_pages() << (PAGE_SHIFT - 10) >>>> + , K(totalhigh_pages()) >>>> >>>> #endif >>>> >>>> ); >>>> >>>> } >>> >>> (my concern is not quite within the scope of this submission, but I'll ask >>> anyway) >>> >>> Given we have this: >>> >>> ``` >>> git grep '#define K(x)' v5.14 >>> v5.14:drivers/base/node.c:#define K(x) ((x) << (PAGE_SHIFT - 10)) >>> v5.14:drivers/net/hamradio/scc.c:#define K(x) kiss->x >>> v5.14:kernel/debug/kdb/kdb_main.c:#define K(x) ((x) << (PAGE_SHIFT - 10)) >>> v5.14:mm/backing-dev.c:#define K(x) ((x) << (PAGE_SHIFT - 10)) >>> v5.14:mm/memcontrol.c:#define K(x) ((x) << (PAGE_SHIFT-10)) >>> v5.14:mm/oom_kill.c:#define K(x) ((x) << (PAGE_SHIFT-10)) >>> v5.14:mm/page_alloc.c:#define K(x) ((x) << (PAGE_SHIFT-10)) >>> ``` >>> >>> Shouldn't this macro go to some header file instead to get rid of define >>> repetitions? >> >> Many thanks for figuring this out. I think we should get rid of these >> repetitions too. But I'am not sure where this definition should be. Any >> suggestion? Thanks. > > I'm not sure what place suits best. At first I thought maybe linux/mm.h or > linux/mm_inline.h, but since PAGE_SHIFT is declared in asm-generic/page.h, > probably K(x) can also go there as well? K(x) is relevant with PAGE_SHIFT. So I think K(x) can also go asm-generic/page.h too. Am I supposed to do this when free or will you kindly do this? Many thanks. >