Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2280593pxa; Fri, 7 Aug 2020 07:34:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+eB5W6W3kH3LQV4CMlNG8O/DKmZBHPxIiPcS0V+Ufs50bZdNUixixe9F2JuXZgQTIUE3u X-Received: by 2002:a17:906:80c:: with SMTP id e12mr9780299ejd.128.1596810846316; Fri, 07 Aug 2020 07:34:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596810846; cv=none; d=google.com; s=arc-20160816; b=vZv8XyKAlRxxY35QyDv7MH63+shrVBn1aXSHjaGrMutXisNzepRAdtUsqNaMc3g5VM t2NhCig34LYtF1DKauyFEWrrx3eR5SYKWTq5UKl7LtC/Tz6x/dE/x0GlRJMajfJ2mj1z y7ZHIc8/NSFPGF5GYF5vqy4airTLR2n4RNHjRtLAQJ8xQ4dSqPEQN/qgTWZfIouWZu38 XiQYHvuwB7eeqf9xPUhQcvxV4KTOAQkcoOez5wQeGuhUoQxKrKoPRfORry2UIjy4oCQ0 /5lY8edAMzPkZ96inWPZQSqa7w7uk+Dafc9mGkR4ZFnRtwCdlTHH2ZUPvzTdiWWRcLa2 N4zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date; bh=VS+cv4MGhZ713C+/S6fW3XmCsToRE05opCibsEwKvr0=; b=HuqukCHQzjLpVhA/hszYDIxfBNOK9LPmSHq4J5JRGkkjroE5S8EvJnzbQN9ZsYtgwg 5TxGfWOGut4CCvpK5JLTXxZyu6qW5kYggkttbqwh6hfV9s6MpFT/TVMAOP/GRvK94EsD GWpIJYq9HAN8c4hqL/55HRcUzmBTDf7lPBrnjEMAi+1P9mI9FuTRxHIXaQNXrb7btpIn Z1Yf7XuI+fosD64zmttyGiVZtyhy7gOvMA1Lc+ynAPGxdN+SsylnBdXb71LvpVsqjSqo Eiti6CDtTuQAhWyFbZWJkUNkc8DfGFVbu++mp2xe4qqnv7G4MNotLMnah0Ut5dl544Lk m7HQ== 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=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pj24si5397075ejb.646.2020.08.07.07.33.42; Fri, 07 Aug 2020 07:34:06 -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=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726066AbgHGOcy (ORCPT + 99 others); Fri, 7 Aug 2020 10:32:54 -0400 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:43742 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbgHGOcy (ORCPT ); Fri, 7 Aug 2020 10:32:54 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R811e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04427;MF=richard.weiyang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0U50nngy_1596810749; Received: from localhost(mailfrom:richard.weiyang@linux.alibaba.com fp:SMTPD_---0U50nngy_1596810749) by smtp.aliyun-inc.com(127.0.0.1); Fri, 07 Aug 2020 22:32:29 +0800 Date: Fri, 7 Aug 2020 22:32:29 +0800 From: Wei Yang To: Baoquan He Cc: Wei Yang , mike.kravetz@oracle.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 08/10] mm/hugetlb: return non-isolated page in the loop instead of break and check Message-ID: <20200807143229.GC14692@L-31X9LVDL-1304.local> Reply-To: Wei Yang References: <20200807091251.12129-1-richard.weiyang@linux.alibaba.com> <20200807091251.12129-9-richard.weiyang@linux.alibaba.com> <20200807130931.GS14854@MiWiFi-R3L-srv> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200807130931.GS14854@MiWiFi-R3L-srv> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 07, 2020 at 09:09:31PM +0800, Baoquan He wrote: >On 08/07/20 at 05:12pm, Wei Yang wrote: >> Function dequeue_huge_page_node_exact() iterates the free list and >> return the first non-isolated one. >> >> Instead of break and check the loop variant, we could return in the loop >> directly. This could reduce some redundant check. >> >> Signed-off-by: Wei Yang >> --- >> mm/hugetlb.c | 26 ++++++++++++-------------- >> 1 file changed, 12 insertions(+), 14 deletions(-) >> >> diff --git a/mm/hugetlb.c b/mm/hugetlb.c >> index b8e844911b5a..9473eb6800e9 100644 >> --- a/mm/hugetlb.c >> +++ b/mm/hugetlb.c >> @@ -1035,20 +1035,18 @@ static struct page *dequeue_huge_page_node_exact(struct hstate *h, int nid) >> { >> struct page *page; >> >> - list_for_each_entry(page, &h->hugepage_freelists[nid], lru) >> - if (!PageHWPoison(page)) >> - break; > >I don't see how it can reduce redundant check, just two different >styles. > list_for_each_entry() stops by checking whether the item reach list head. >> - /* >> - * if 'non-isolated free hugepage' not found on the list, >> - * the allocation fails. > >But the above code comment seems stale, it checks HWPoision page() >directly, but not the old isolated page checking. > >> - */ >> - if (&h->hugepage_freelists[nid] == &page->lru) >> - return NULL; And here the check is done again, if we really iterate the whole list. By take the code in the loop, we can avoid this check. >> - list_move(&page->lru, &h->hugepage_activelist); >> - set_page_refcounted(page); >> - h->free_huge_pages--; >> - h->free_huge_pages_node[nid]--; >> - return page; >> + list_for_each_entry(page, &h->hugepage_freelists[nid], lru) { >> + if (PageHWPoison(page)) >> + continue; >> + >> + list_move(&page->lru, &h->hugepage_activelist); >> + set_page_refcounted(page); >> + h->free_huge_pages--; >> + h->free_huge_pages_node[nid]--; >> + return page; >> + } >> + >> + return NULL; >> } >> >> static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask, int nid, >> -- >> 2.20.1 (Apple Git-117) >> >> -- Wei Yang Help you, Help me