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=-11.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 D8628C433E3 for ; Tue, 14 Jul 2020 09:22:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A1F0A20674 for ; Tue, 14 Jul 2020 09:22:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A1F0A20674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2C2D56B0005; Tue, 14 Jul 2020 05:22:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 272036B0006; Tue, 14 Jul 2020 05:22:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1872A6B0007; Tue, 14 Jul 2020 05:22:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0115.hostedemail.com [216.40.44.115]) by kanga.kvack.org (Postfix) with ESMTP id 037C56B0005 for ; Tue, 14 Jul 2020 05:22:05 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 93D82181AC9BF for ; Tue, 14 Jul 2020 09:22:05 +0000 (UTC) X-FDA: 77036139810.24.badge10_4f0991c26eef Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 64A551A4A7 for ; Tue, 14 Jul 2020 09:22:05 +0000 (UTC) X-HE-Tag: badge10_4f0991c26eef X-Filterd-Recvd-Size: 2721 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Jul 2020 09:22:04 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D7651AC1D; Tue, 14 Jul 2020 09:22:05 +0000 (UTC) Subject: Re: [PATCH] mm/hugetlb: hide nr_nodes in the internal of for_each_node_mask_to_[alloc|free] From: Vlastimil Babka To: Wei Yang , mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20200714073404.84863-1-richard.weiyang@linux.alibaba.com> Message-ID: <807a1e32-926b-2882-740b-6484b8dca2b6@suse.cz> Date: Tue, 14 Jul 2020 11:22:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 64A551A4A7 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 7/14/20 11:13 AM, Vlastimil Babka wrote: > On 7/14/20 9:34 AM, Wei Yang wrote: >> The second parameter of for_each_node_mask_to_[alloc|free] is a loop >> variant, which is not used outside of loop iteration. >> >> Let's hide this. >> >> Signed-off-by: Wei Yang >> --- >> mm/hugetlb.c | 38 ++++++++++++++++++++------------------ >> 1 file changed, 20 insertions(+), 18 deletions(-) >> >> diff --git a/mm/hugetlb.c b/mm/hugetlb.c >> index 57ece74e3aae..9c3d15fb317e 100644 >> --- a/mm/hugetlb.c >> +++ b/mm/hugetlb.c >> @@ -1196,17 +1196,19 @@ static int hstate_next_node_to_free(struct hstate *h, nodemask_t *nodes_allowed) >> return nid; >> } >> >> -#define for_each_node_mask_to_alloc(hs, nr_nodes, node, mask) \ >> - for (nr_nodes = nodes_weight(*mask); \ >> - nr_nodes > 0 && \ >> +#define for_each_node_mask_to_alloc(hs, node, mask) \ >> + int __nr_nodes; \ >> + for (__nr_nodes = nodes_weight(*mask); \ > > The problem with this is that if I use the macro twice in the same block, this > will redefine __nr_nodes and fail to compile, no? > In that case it's better to avoid setting up this trap, IMHO. Ah, and it will also generate the following warning, if the use of for_each* macro is not the first thing after variable declarations, but there's another statement before: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] Instead we should switch to C99 and declare it as "for (int __nr_nodes" :P