Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4395529pxb; Tue, 31 Aug 2021 04:13:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAboXX4+vJZvBqVXaaYGh9O4Z/4i+28jwWwgsz38HmHHBtz1juej2cgLKj3W//qyDf0hQa X-Received: by 2002:a17:906:4482:: with SMTP id y2mr10970744ejo.484.1630408408990; Tue, 31 Aug 2021 04:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630408408; cv=none; d=google.com; s=arc-20160816; b=Joh1TrIPWSeMBMuLLJpID/U8akFTJT7SjiAznDA4H6CBHEGYSm0yO2OGbVCqSxvCj1 470T6RlnQYqSnBisHndzfjwKZNtBHZWc4RUezd/sCKcMT+Qcpslwx/0w/1DgWjvEPAhU 8paJRmeS05sLZIhicvx1+6UH83Do41pS+rf1KDUo9NJVbwuwwXMyqHLKB418hUcEO3tv 6FULX+X/M+2pXXfrhP+y/qs8McNV1/YxIUKEIzkA6dbSykRZ93NRETp2daH6+5YUNCVI Lpa3jTsfn3OTXQZtHHLYVB7vnFnpik13mLLB+G7Cx2XAXCokQGERo0v1qJFpsCz5/0Ig +HjQ== 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=j40Dod/gCiPem4xQnBmdN/f56WKEfjvL4UFlgJg/in8=; b=s4sj+2zZLnQSHwYVnDsfLXSVINOnIwgqNVmsFAy9OTxtHfQAtSgy/ZGSCbyFFLNH5R rmdDuEzUf3iwXeoOrgsa8Y+OrzHBfm3VsAWLzeVb1Pk9M/6qR+dVA3tB4nCL6VOk4lT7 D2mKDZwLahUTDEk1dxIjc6t3zL1IXwxooDNOaEJoI9GhKHV6xLcMOceYZdAmUdFNiauZ zFeV+Gy8UrS4ziA6+9NJgSoAZU6ImKbvtY8DwYqgj2mbHriHs62V8idkD2pPztU0V+tQ nlQ2kBj1CwpfszzAYtto0T4KlVgL8nwsHC0s6QKVOD3MaxspwgJ656FEGDyY7zx0aoUY ec7w== 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 r21si20863169ejo.47.2021.08.31.04.12.45; Tue, 31 Aug 2021 04:13:28 -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 S241407AbhHaLJl (ORCPT + 99 others); Tue, 31 Aug 2021 07:09:41 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:14441 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241405AbhHaLJk (ORCPT ); Tue, 31 Aug 2021 07:09:40 -0400 Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GzPTr1YqMzbfcG; Tue, 31 Aug 2021 19:04:48 +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; Tue, 31 Aug 2021 19:08:42 +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> <20210830141051.64090-3-linmiaohe@huawei.com> <9161665.bUqNH3lxUD@natalenko.name> From: Miaohe Lin Message-ID: <52bbb8f2-db63-8c56-ea49-d982c13ba541@huawei.com> Date: Tue, 31 Aug 2021 19:08:42 +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: <9161665.bUqNH3lxUD@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: dggems702-chm.china.huawei.com (10.3.19.179) 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 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. > > Thanks. >