From patchwork Fri Dec 25 09:59:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 11990087 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 59B84C433E0 for ; Fri, 25 Dec 2020 10:02:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C0D31230FF for ; Fri, 25 Dec 2020 10:02:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C0D31230FF 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 D30638D0083; Fri, 25 Dec 2020 05:02:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CC2D08D0084; Fri, 25 Dec 2020 05:02:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCDCE8D0083; Fri, 25 Dec 2020 05:02:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0018.hostedemail.com [216.40.44.18]) by kanga.kvack.org (Postfix) with ESMTP id A59C08D0080 for ; Fri, 25 Dec 2020 05:02:01 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4B028181AEF1F for ; Fri, 25 Dec 2020 10:02:01 +0000 (UTC) X-FDA: 77631363642.01.print58_01020ce27479 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 2615810054F07 for ; Fri, 25 Dec 2020 10:02:01 +0000 (UTC) X-HE-Tag: print58_01020ce27479 X-Filterd-Recvd-Size: 4659 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Fri, 25 Dec 2020 10:01:59 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0UJjFIVO_1608890514; Received: from aliy80.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0UJjFIVO_1608890514) by smtp.aliyun-inc.com(127.0.0.1); Fri, 25 Dec 2020 18:01:56 +0800 From: Alex Shi To: willy@infradead.org Cc: tim.c.chen@linux.intel.com, Konstantin Khlebnikov , Hugh Dickins , Yu Zhao , Michal Hocko , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/4] mm/swap.c: extend the usage to pagevec_lru_add Date: Fri, 25 Dec 2020 17:59:49 +0800 Message-Id: <1608890390-64305-4-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1608890390-64305-1-git-send-email-alex.shi@linux.alibaba.com> References: <20201126155553.GT4327@casper.infradead.org> <1608890390-64305-1-git-send-email-alex.shi@linux.alibaba.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The only different for __pagevec_lru_add and other page moving between lru lists is page to add lru list has no need to do TestClearPageLRU and set the lru bit back. So we could combound them with a clear lru bit switch in sort function parameter. Than all lru list operation functions could be united. Signed-off-by: Alex Shi Cc: Konstantin Khlebnikov Cc: Hugh Dickins Cc: Yu Zhao Cc: Michal Hocko Cc: Matthew Wilcox (Oracle) Cc: Andrew Morton Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/swap.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index bb5300b7e321..9a2269e5099b 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -12,6 +12,7 @@ * Started 18.12.91 * Swap aging added 23.2.95, Stephen Tweedie. * Buffermem limits added 12.3.98, Rik van Riel. + * Pre-sort pagevec added 12.1.20, Alex Shi. */ #include @@ -227,8 +228,8 @@ static void shell_sort(struct pagevec *pvec, unsigned long *lvaddr) } /* Get lru bit cleared page and their lruvec address, release the others */ -void sort_isopv(struct pagevec *pvec, struct pagevec *isopv, - unsigned long *lvaddr) +static void sort_isopv(struct pagevec *pvec, struct pagevec *isopv, + unsigned long *lvaddr, bool clearlru) { int i, j; struct pagevec busypv; @@ -242,7 +243,7 @@ void sort_isopv(struct pagevec *pvec, struct pagevec *isopv, pvec->pages[i] = NULL; /* block memcg migration during page moving between lru */ - if (!TestClearPageLRU(page)) { + if (clearlru && !TestClearPageLRU(page)) { pagevec_add(&busypv, page); continue; } @@ -266,9 +267,13 @@ static void pagevec_lru_move_fn(struct pagevec *pvec, unsigned long flags = 0; unsigned long lvaddr[PAGEVEC_SIZE]; struct pagevec sortedpv; + bool clearlru; + + /* don't clear lru bit for new page adding to lru */ + clearlru = pvec != this_cpu_ptr(&lru_pvecs.lru_add); pagevec_init(&sortedpv); - sort_isopv(pvec, &sortedpv, lvaddr); + sort_isopv(pvec, &sortedpv, lvaddr, clearlru); n = pagevec_count(&sortedpv); if (!n) @@ -287,7 +292,8 @@ static void pagevec_lru_move_fn(struct pagevec *pvec, (*move_fn)(sortedpv.pages[i], lruvec); - SetPageLRU(sortedpv.pages[i]); + if (clearlru) + SetPageLRU(sortedpv.pages[i]); } spin_unlock_irqrestore(&lruvec->lru_lock, flags); release_pages(sortedpv.pages, sortedpv.nr); @@ -1111,20 +1117,7 @@ static void __pagevec_lru_add_fn(struct page *page, struct lruvec *lruvec) */ void __pagevec_lru_add(struct pagevec *pvec) { - int i; - struct lruvec *lruvec = NULL; - unsigned long flags = 0; - - for (i = 0; i < pagevec_count(pvec); i++) { - struct page *page = pvec->pages[i]; - - lruvec = relock_page_lruvec_irqsave(page, lruvec, &flags); - __pagevec_lru_add_fn(page, lruvec); - } - if (lruvec) - unlock_page_lruvec_irqrestore(lruvec, flags); - release_pages(pvec->pages, pvec->nr); - pagevec_reinit(pvec); + pagevec_lru_move_fn(pvec, __pagevec_lru_add_fn); } /**