Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp873307pxb; Wed, 1 Sep 2021 11:48:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqtijiN8vBoJFZZR+DxQPzYiENxbgjVwjw5B2jY8XTmZhBWLyQvUMmRd3psJ0+Kq956gUj X-Received: by 2002:a05:6e02:1c08:: with SMTP id l8mr665258ilh.134.1630522131714; Wed, 01 Sep 2021 11:48:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630522131; cv=none; d=google.com; s=arc-20160816; b=n7SP8cUO00fasvQ/2ljk5Z+o7M1xqeo0yLYNqPYwUWW6/8MtK/4p7DvUpsT7dB1lD/ 2SII8bYzgKh81IUnNDbN3jIErytiAkMPYoScGPzNAjhyGZhpBJQQWAh7IxzoJdCu/AuI F372NI0a9bMW4deVi5gWzoqt8erB4RDw1xJEsziCZZb7Et0zZwj5TH3i3IHTaacQ6VTC ErcHuYtkztFF7RC2v6zXfe5QUI/btrkntcV8ndWBiqQ8GnuxH9FCQAGHZXSnhtwQU2av EeaAUlSDi0bU+4Q9ykl/vg/y7Ay50s2eLbyXIgtPh6oUdm/YdUDdTqg/dwNv/pKZaX3O 97vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=BdHOnS1Wfx7DmFu41u5b7b24iqMxUEIg4wnsu1zt6MA=; b=qJiLoP6PE0zubc8YUj+kSOZO7nQoAsEHylwpQPZcRHuw3xKoaYuB47Dug+M1IiYJ3g wvQ+wRYGmIA/nnhrEDXtoJwKah+UiI28g2+tRCMoIRRPjwU/o/xYM+yYaRoZXLZg1XC3 WchnXazMiUhAHU4fzWFAx6T+EywFmPhDJqw6NN0qe95sV5sNTVCNPiEaQJ1hC//P278b w1r3mPpP6n5cXH466nbGZBnOmZzvI5RSAHSJQtkjLYdIZov1Dt3qiVaYF27hEkh0bXQB EgG4d+vwGxub4oRnYX8ilWsgdatUoE6agxkZ+4SoLQnwE9aRvw4gzKhfITjDD8mWJbJ2 Cuog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i12si266996jac.26.2021.09.01.11.48.40; Wed, 01 Sep 2021 11:48:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242627AbhIAHit (ORCPT + 99 others); Wed, 1 Sep 2021 03:38:49 -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. >