Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1064999ybg; Wed, 10 Jun 2020 23:19:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMFtIuzrtzhh5wmm5Ic8x/x4/C9IsQhOatmB3JQ+HC9RFVZOs3Vp0+hT9efEcUiiBFWA+y X-Received: by 2002:a17:906:899:: with SMTP id n25mr5209159eje.298.1591856389770; Wed, 10 Jun 2020 23:19:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591856389; cv=none; d=google.com; s=arc-20160816; b=ljkXJm7mOBfL38Gpd3YxMgMxUs/9PgMv9Q4OI14esrvStn3YURnlm3jbgKMsXjIIKB GpEzXPwBCSNTXOMYjW4T6ex9iqMipxBg7HAS48Xd6ZFieKC5Adi9nrBccq3Hf7BNugnd SHQvCvYi7iU6N6ruNPBT37UL6f5cB8dN0/8xV3fPtWmjur3px01gsjrNoN1TR7DGyxYZ uuMUSUIFoIqS5yaD1rLYmVEGRkybW6/5bdGncA3jLFR2sr7NIFX8OrvcHq1MIR621QLR oBjkITszldf9N1hh67PwwDwYa52b+a0wmJfngHOhsB3u62tHFgYZIPUN4Snt6nQ/R80L otFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=M3+zu3LVDSYDFLiOFh+T6dpeWv0/CDEC71EfSSB0Kq8=; b=Fqb3reAjXJ1YEotuYUEYFoH55Zf0zpYoBNNq6Va6ZCOfAcY6Eb7GyCn/Z+IFa/kmVI S5k+jMpQkZZ49UN9jCUKZ/7TwH9BLOYNP7+V3I12vJw3KMAo240wQYh3rrqxKRgnvhjS /x3ZxEReq10RazL9qJytPzdMJLCDA2d1FkSUHCiMAVMmFMDICHvuYJrCXkodwgdjgr85 orW7TnZ6F9Y544ubaZQr8AxRAicbnQPzALX8+vUoWGxMltR1bg2Olh6kLSrTfCuOwnNI KuY/awx9Zezd+pfeVRxqoyehxNVNnfJ1lbH6rdO5mSxiATflKrzEuvCtM3CuEe1kGQOB sq2Q== 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 c21si1402294ejx.217.2020.06.10.23.19.27; Wed, 10 Jun 2020 23:19:49 -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 S1726720AbgFKGRZ (ORCPT + 99 others); Thu, 11 Jun 2020 02:17:25 -0400 Received: from out30-43.freemail.mail.aliyun.com ([115.124.30.43]:37391 "EHLO out30-43.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726682AbgFKGRU (ORCPT ); Thu, 11 Jun 2020 02:17:20 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07484;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=18;SR=0;TI=SMTPD_---0U.EnDAz_1591856230; Received: from localhost(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0U.EnDAz_1591856230) by smtp.aliyun-inc.com(127.0.0.1); Thu, 11 Jun 2020 14:17:11 +0800 From: Alex Shi To: akpm@linux-foundation.org, mgorman@techsingularity.net, tj@kernel.org, hughd@google.com, khlebnikov@yandex-team.ru, daniel.m.jordan@oracle.com, yang.shi@linux.alibaba.com, willy@infradead.org, hannes@cmpxchg.org, lkp@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, shakeelb@google.com, iamjoonsoo.kim@lge.com, richard.weiyang@gmail.com Cc: Thomas Gleixner , Andrey Ryabinin Subject: [PATCH v12 13/16] mm/lru: introduce the relock_page_lruvec function Date: Thu, 11 Jun 2020 14:16:46 +0800 Message-Id: <1591856209-166869-14-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1591856209-166869-1-git-send-email-alex.shi@linux.alibaba.com> References: <1591856209-166869-1-git-send-email-alex.shi@linux.alibaba.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use this new function to replace repeated same code. Signed-off-by: Alex Shi Cc: Johannes Weiner Cc: Andrew Morton Cc: Thomas Gleixner Cc: Andrey Ryabinin Cc: Matthew Wilcox Cc: Mel Gorman Cc: Konstantin Khlebnikov Cc: Hugh Dickins Cc: Tejun Heo Cc: linux-kernel@vger.kernel.org Cc: cgroups@vger.kernel.org Cc: linux-mm@kvack.org --- include/linux/memcontrol.h | 36 ++++++++++++++++++++++++++++++++++++ mm/mlock.c | 9 +-------- mm/swap.c | 24 ++++++------------------ mm/vmscan.c | 8 +------- 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 6b821b0c8852..d90643246c77 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1311,6 +1311,42 @@ static inline struct lruvec *parent_lruvec(struct lruvec *lruvec) return mem_cgroup_lruvec(memcg, lruvec_pgdat(lruvec)); } +/* Don't lock again iff page's lruvec locked */ +static inline struct lruvec *relock_page_lruvec_irq(struct page *page, + struct lruvec *locked_lruvec) +{ + struct pglist_data *pgdat = page_pgdat(page); + struct lruvec *lruvec; + + lruvec = mem_cgroup_page_lruvec(page, pgdat); + + if (likely(locked_lruvec == lruvec)) + return lruvec; + + if (unlikely(locked_lruvec)) + unlock_page_lruvec_irq(locked_lruvec); + + return lock_page_lruvec_irq(page); +} + +/* Don't lock again iff page's lruvec locked */ +static inline struct lruvec *relock_page_lruvec_irqsave(struct page *page, + struct lruvec *locked_lruvec, unsigned long *flags) +{ + struct pglist_data *pgdat = page_pgdat(page); + struct lruvec *lruvec; + + lruvec = mem_cgroup_page_lruvec(page, pgdat); + + if (likely(locked_lruvec == lruvec)) + return lruvec; + + if (unlikely(locked_lruvec)) + unlock_page_lruvec_irqrestore(locked_lruvec, *flags); + + return lock_page_lruvec_irqsave(page, flags); +} + #ifdef CONFIG_CGROUP_WRITEBACK struct wb_domain *mem_cgroup_wb_domain(struct bdi_writeback *wb); diff --git a/mm/mlock.c b/mm/mlock.c index 97a8667b4c2c..fa976a5b91c7 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -289,17 +289,10 @@ static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone) /* Phase 1: page isolation */ for (i = 0; i < nr; i++) { struct page *page = pvec->pages[i]; - struct lruvec *new_lruvec; bool clearlru; clearlru = TestClearPageLRU(page); - - new_lruvec = mem_cgroup_page_lruvec(page, page_pgdat(page)); - if (new_lruvec != lruvec) { - if (lruvec) - unlock_page_lruvec_irq(lruvec); - lruvec = lock_page_lruvec_irq(page); - } + lruvec = relock_page_lruvec_irq(page, lruvec); if (!TestClearPageMlocked(page)) { delta_munlocked++; diff --git a/mm/swap.c b/mm/swap.c index c9b86d7e1ab5..eba0c17dffd8 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -209,15 +209,8 @@ static void pagevec_lru_move_fn(struct pagevec *pvec, for (i = 0; i < pagevec_count(pvec); i++) { struct page *page = pvec->pages[i]; - struct lruvec *new_lruvec; - - new_lruvec = mem_cgroup_page_lruvec(page, page_pgdat(page)); - if (lruvec != new_lruvec) { - if (lruvec) - unlock_page_lruvec_irqrestore(lruvec, flags); - lruvec = lock_page_lruvec_irqsave(page, &flags); - } + lruvec = relock_page_lruvec_irqsave(page, lruvec, &flags); (*move_fn)(page, lruvec, arg); } if (lruvec) @@ -875,17 +868,12 @@ void release_pages(struct page **pages, int nr) } if (TestClearPageLRU(page)) { - struct lruvec *new_lruvec; - - new_lruvec = mem_cgroup_page_lruvec(page, - page_pgdat(page)); - if (new_lruvec != lruvec) { - if (lruvec) - unlock_page_lruvec_irqrestore(lruvec, - flags); + struct lruvec *pre_lruvec = lruvec; + + lruvec = relock_page_lruvec_irqsave(page, lruvec, + &flags); + if (pre_lruvec != lruvec) lock_batch = 0; - lruvec = lock_page_lruvec_irqsave(page, &flags); - } del_page_from_lru_list(page, lruvec, page_off_lru(page)); } diff --git a/mm/vmscan.c b/mm/vmscan.c index 4d5a0b660c82..1253cdb16c96 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4291,15 +4291,9 @@ void check_move_unevictable_pages(struct pagevec *pvec) for (i = 0; i < pvec->nr; i++) { struct page *page = pvec->pages[i]; - struct lruvec *new_lruvec; pgscanned++; - new_lruvec = mem_cgroup_page_lruvec(page, page_pgdat(page)); - if (lruvec != new_lruvec) { - if (lruvec) - unlock_page_lruvec_irq(lruvec); - lruvec = lock_page_lruvec_irq(page); - } + lruvec = relock_page_lruvec_irq(page, lruvec); if (!PageLRU(page) || !PageUnevictable(page)) continue; -- 1.8.3.1