From patchwork Tue Jul 14 07:34:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 11661885 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA4741392 for ; Tue, 14 Jul 2020 07:34:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C1231207BB for ; Tue, 14 Jul 2020 07:34:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C1231207BB 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 200578D0002; Tue, 14 Jul 2020 03:34:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1B1908D0001; Tue, 14 Jul 2020 03:34:24 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EFC78D0002; Tue, 14 Jul 2020 03:34:24 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id EC3438D0001 for ; Tue, 14 Jul 2020 03:34:23 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id AE2168248D51 for ; Tue, 14 Jul 2020 07:34:23 +0000 (UTC) X-FDA: 77035868406.19.ocean13_280dd8626eef Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 81E4B1AD1B2 for ; Tue, 14 Jul 2020 07:34:23 +0000 (UTC) X-Spam-Summary: 1,0,0,ce28dc0a69195f5a,d41d8cd98f00b204,richard.weiyang@linux.alibaba.com,,RULES_HIT:41:69:355:379:541:960:965:966:968:973:988:989:1260:1261:1311:1314:1345:1437:1515:1535:1544:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3355:3865:3866:3870:3871:4385:4390:4395:5007:6261:8660:10004:11026:11473:11658:11914:12043:12114:12291:12296:12297:12438:12555:12683:12895:13148:13161:13229:13230:13255:13894:14110:14181:14394:14721:21080:21451:21627:21810:21939:21990:30054:30056:30065,0,RBL:115.124.30.42:@linux.alibaba.com:.lbl8.mailshell.net-62.20.2.100 64.201.201.201;04y8aj9ng649yap1y5djijsrexp43opomcbpubibjzn1qzth1mbp9ikaaxc8e98.ga51dz38cw93ybyaf6d18m9f448ctbmg6mo1qwkoruexisztckckac9rsy6gc49.k-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: ocean13_280dd8626eef X-Filterd-Recvd-Size: 5260 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Jul 2020 07:34:22 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R371e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01419;MF=richard.weiyang@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0U2hiN69_1594712046; Received: from localhost(mailfrom:richard.weiyang@linux.alibaba.com fp:SMTPD_---0U2hiN69_1594712046) by smtp.aliyun-inc.com(127.0.0.1); Tue, 14 Jul 2020 15:34:07 +0800 From: Wei Yang To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH] mm/hugetlb: hide nr_nodes in the internal of for_each_node_mask_to_[alloc|free] Date: Tue, 14 Jul 2020 15:34:04 +0800 Message-Id: <20200714073404.84863-1-richard.weiyang@linux.alibaba.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) MIME-Version: 1.0 X-Rspamd-Queue-Id: 81E4B1AD1B2 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000147, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Pankaj Gupta --- 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); \ + __nr_nodes > 0 && \ ((node = hstate_next_node_to_alloc(hs, mask)) || 1); \ - nr_nodes--) + __nr_nodes--) -#define for_each_node_mask_to_free(hs, nr_nodes, node, mask) \ - for (nr_nodes = nodes_weight(*mask); \ - nr_nodes > 0 && \ +#define for_each_node_mask_to_free(hs, node, mask) \ + int __nr_nodes; \ + for (__nr_nodes = nodes_weight(*mask); \ + __nr_nodes > 0 && \ ((node = hstate_next_node_to_free(hs, mask)) || 1); \ - nr_nodes--) + __nr_nodes--) #ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE static void destroy_compound_gigantic_page(struct page *page, @@ -1403,7 +1405,7 @@ static void __free_huge_page(struct page *page) * reservation. If the page was associated with a subpool, there * would have been a page reserved in the subpool before allocation * via hugepage_subpool_get_pages(). Since we are 'restoring' the - * reservtion, do not call hugepage_subpool_put_pages() as this will + * reservation, do not call hugepage_subpool_put_pages() as this will * remove the reserved page from the subpool. */ if (!restore_reserve) { @@ -1760,10 +1762,10 @@ static int alloc_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed, nodemask_t *node_alloc_noretry) { struct page *page; - int nr_nodes, node; + int node; gfp_t gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE; - for_each_node_mask_to_alloc(h, nr_nodes, node, nodes_allowed) { + for_each_node_mask_to_alloc(h, node, nodes_allowed) { page = alloc_fresh_huge_page(h, gfp_mask, node, nodes_allowed, node_alloc_noretry); if (page) @@ -1787,10 +1789,10 @@ static int alloc_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed, static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed, bool acct_surplus) { - int nr_nodes, node; + int node; int ret = 0; - for_each_node_mask_to_free(h, nr_nodes, node, nodes_allowed) { + for_each_node_mask_to_free(h, node, nodes_allowed) { /* * If we're returning unused surplus pages, only examine * nodes with surplus pages. @@ -2481,9 +2483,9 @@ int alloc_bootmem_huge_page(struct hstate *h) int __alloc_bootmem_huge_page(struct hstate *h) { struct huge_bootmem_page *m; - int nr_nodes, node; + int node; - for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) { + for_each_node_mask_to_alloc(h, node, &node_states[N_MEMORY]) { void *addr; addr = memblock_alloc_try_nid_raw( @@ -2662,17 +2664,17 @@ static inline void try_to_free_low(struct hstate *h, unsigned long count, static int adjust_pool_surplus(struct hstate *h, nodemask_t *nodes_allowed, int delta) { - int nr_nodes, node; + int node; VM_BUG_ON(delta != -1 && delta != 1); if (delta < 0) { - for_each_node_mask_to_alloc(h, nr_nodes, node, nodes_allowed) { + for_each_node_mask_to_alloc(h, node, nodes_allowed) { if (h->surplus_huge_pages_node[node]) goto found; } } else { - for_each_node_mask_to_free(h, nr_nodes, node, nodes_allowed) { + for_each_node_mask_to_free(h, node, nodes_allowed) { if (h->surplus_huge_pages_node[node] < h->nr_huge_pages_node[node]) goto found;