Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp874215pxb; Wed, 1 Sep 2021 11:50:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyww3tDBR1H1B1vtRo3zh61O0uam7N40RDLnEr0tCPyS8hA7SBhodgQApUMJivSotbDlqbZ X-Received: by 2002:a6b:be02:: with SMTP id o2mr812648iof.103.1630522214061; Wed, 01 Sep 2021 11:50:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630522214; cv=none; d=google.com; s=arc-20160816; b=lbjGme4hKwz3rWivuMwZVAI/Hi8/4g2+9Nc2mmuNBCi3halVeCC+dQSEhopgM2886S Vxg51J1L2ctui5BtM05fKzuC94/5SHXeTne+cA4L3exwMISQbkNGxhyErbno1s2KSACR fQ6+GvTuTmqqRhBR5PL5I/4AVhKqzgYxP8+38WKg2Xqo3Yb5lnG97/6sTbBZMPDPbK8u IyqabMZpptDj9ZkrD1Qm3AnegKC6M4ft88Jtsn1jSEY9sDHkdlVwzeBUwqQCWKAaHgbZ WdYwAnb0m3BMo5Rr/cOIFU3ovQN1lk+8LYyVDjIMWBGBMnyC86JvT99hUNLudzhNHekU Kvxg== 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=vXaY9cqdBM/s+DcZakzPpJkMLZ7iPNrTOtNONxI2M78=; b=qUoYTijkywDiekTW+sPwllNyxIbpRJOxDKQZGXJJJ0zlra7Y7FJqPE3xeekJkHTurz isg5pD+uN6RhL3CoDLz6X1CRky5nop4AzZyvyfpHjgioVFO7KCEkIPG6TiCe95MM+ILe Ya4dNF3iyNKfD1//B1xLJWPs2IUStCT9091FgY+mCA9657og35FQcd3PAd/ma6B8Vb9M sP5vGfaZ2Kgcwfki+9I+ndIh9Otw7XP9mWkLNwsvqePPIt0l1XFPue8ZLTzWgBIidcZ8 bDjmhUFd+kM+NFQxKgCf6D7AmY3dCcXSkyD9UBJKFMyxYv9SLfcErFeMpxq52qFtwrM3 dY6w== 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 k39si187132jav.114.2021.09.01.11.50.01; Wed, 01 Sep 2021 11:50:14 -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 S242915AbhIAISe (ORCPT + 99 others); Wed, 1 Sep 2021 04:18:34 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:18999 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242911AbhIAIS2 (ORCPT ); Wed, 1 Sep 2021 04:18:28 -0400 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 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/9/1 15:46, Oleksandr Natalenko wrote: > Hello. > > On středa 1. září 2021 9:37:49 CEST Miaohe Lin wrote: >> On 2021/8/31 22:19, Oleksandr Natalenko wrote: >>> On úterý 31. srpna 2021 13:08:42 CEST Miaohe Lin wrote: >>>> On 2021/8/31 16:54, Oleksandr Natalenko wrote: >>>>> 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. > > Actually, the comment in this file says: > > ``` > 4 /* > 5 * Generic page.h implementation, for NOMMU architectures. > 6 * This provides the dummy definitions for the memory management. > 7 */ > ``` > > so it seems I was wrong about this being an appropriate place. It's hard to find the appropriate place. > >> Am I supposed to do this when free or will you >> kindly do this? > > Let me just try to cram this into mm.h and send it out, and then we'll see > what comments people suggest. > Many thanks for doing this. :) > Thanks. >