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 DF3D5C432BE for ; Wed, 1 Sep 2021 08:17:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6DF9C6103A for ; Wed, 1 Sep 2021 08:17:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6DF9C6103A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id F39C46B006C; Wed, 1 Sep 2021 04:17:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE8FD6B0071; Wed, 1 Sep 2021 04:17:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD8916B0072; Wed, 1 Sep 2021 04:17:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0208.hostedemail.com [216.40.44.208]) by kanga.kvack.org (Postfix) with ESMTP id CE02E6B006C for ; Wed, 1 Sep 2021 04:17:33 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8407B231D6 for ; Wed, 1 Sep 2021 08:17:33 +0000 (UTC) X-FDA: 78538300386.01.A677BC8 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf28.hostedemail.com (Postfix) with ESMTP id 9002C90000A1 for ; Wed, 1 Sep 2021 08:17:32 +0000 (UTC) Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Gzxdp3S6NzbkWg; Wed, 1 Sep 2021 16:13:34 +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 16:17:29 +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> <9426505.MgecbftzqH@natalenko.name> <03653d41-abe0-46f0-9eee-28cad9f5edea@huawei.com> <5931202.uRb02ylMo7@natalenko.name> From: Miaohe Lin Message-ID: Date: Wed, 1 Sep 2021 16:17:28 +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: <5931202.uRb02ylMo7@natalenko.name> Content-Type: text/plain; charset="utf-8" Content-Language: en-US X-Originating-IP: [10.174.178.75] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=none) header.from=huawei.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9002C90000A1 X-Stat-Signature: msoaeioxgzeatkhkof7h7m5thzq34rx5 X-HE-Tag: 1630484252-197551 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 2021/9/1 15:46, Oleksandr Natalenko wrote: > Hello. >=20 > On st=C5=99eda 1. z=C3=A1=C5=99=C3=AD 2021 9:37:49 CEST Miaohe Lin wrot= e: >> On 2021/8/31 22:19, Oleksandr Natalenko wrote: >>> On =C3=BAter=C3=BD 31. srpna 2021 13:08:42 CEST Miaohe Lin wrote: >>>> On 2021/8/31 16:54, Oleksandr Natalenko wrote: >>>>> On pond=C4=9Bl=C3=AD 30. srpna 2021 16:10:47 CEST Miaohe Lin wrote: >>>>>> Use helper macro K() to convert the pages to the corresponding siz= e. >>>>>> 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; >>>>>> =20 >>>>>> } >>>>>> >>>>>> @@ -8180,14 +8179,13 @@ void __init mem_init_print_info(void) >>>>>> >>>>>> ", %luK highmem" >>>>>> =20 >>>>>> #endif >>>>>> =20 >>>>>> ")\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) <<=20 > (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 >>>>>> =20 >>>>>> ); >>>>>> =20 >>>>>> } >>>>> >>>>> (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 d= efine >>>>> repetitions? >>>> >>>> Many thanks for figuring this out. I think we should get rid of thes= e >>>> 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/pa= ge.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. >=20 > Actually, the comment in this file says: >=20 > ``` > 4 /* > 5 * Generic page.h implementation, for NOMMU architectures. > 6 * This provides the dummy definitions for the memory management. > 7 */ > ``` >=20 > so it seems I was wrong about this being an appropriate place. It's hard to find the appropriate place. >=20 >> Am I supposed to do this when free or will you >> kindly do this? >=20 > Let me just try to cram this into mm.h and send it out, and then we'll = see=20 > what comments people suggest. >=20 Many thanks for doing this. :) > Thanks. >=20