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=-10.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY 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 07CC1C433E0 for ; Tue, 14 Jul 2020 09:50:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C456221D90 for ; Tue, 14 Jul 2020 09:50:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C456221D90 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5C4116B0002; Tue, 14 Jul 2020 05:50:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 576286B0003; Tue, 14 Jul 2020 05:50:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B2F58D0001; Tue, 14 Jul 2020 05:50:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0026.hostedemail.com [216.40.44.26]) by kanga.kvack.org (Postfix) with ESMTP id 367906B0002 for ; Tue, 14 Jul 2020 05:50:40 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F422F8248047 for ; Tue, 14 Jul 2020 09:50:39 +0000 (UTC) X-FDA: 77036211840.07.river42_2e0d79226ef0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id C907D1803F9A0 for ; Tue, 14 Jul 2020 09:50:39 +0000 (UTC) X-HE-Tag: river42_2e0d79226ef0 X-Filterd-Recvd-Size: 3215 Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Jul 2020 09:50:38 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01355;MF=richard.weiyang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0U2iItPC_1594720227; Received: from localhost(mailfrom:richard.weiyang@linux.alibaba.com fp:SMTPD_---0U2iItPC_1594720227) by smtp.aliyun-inc.com(127.0.0.1); Tue, 14 Jul 2020 17:50:27 +0800 Date: Tue, 14 Jul 2020 17:50:27 +0800 From: Wei Yang To: Vlastimil Babka Cc: Wei Yang , mike.kravetz@oracle.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/hugetlb: hide nr_nodes in the internal of for_each_node_mask_to_[alloc|free] Message-ID: <20200714095027.GA86480@L-31X9LVDL-1304.local> Reply-To: Wei Yang References: <20200714073404.84863-1-richard.weiyang@linux.alibaba.com> <807a1e32-926b-2882-740b-6484b8dca2b6@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <807a1e32-926b-2882-740b-6484b8dca2b6@suse.cz> X-Rspamd-Queue-Id: C907D1803F9A0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.009530, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jul 14, 2020 at 11:22:03AM +0200, Vlastimil Babka wrote: >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 Thanks, I haven't notice the problem you mentioned. Let me fix this. -- Wei Yang Help you, Help me