Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8547081ybl; Wed, 25 Dec 2019 01:06:28 -0800 (PST) X-Google-Smtp-Source: APXvYqxeNy7Y7tFKrBbhARF28g/Flwz17kCWErcUlcTYXhdt254o/eRqa4ZNYFtwYR3kuHlhCvR/ X-Received: by 2002:a9d:6c99:: with SMTP id c25mr25050107otr.178.1577264788546; Wed, 25 Dec 2019 01:06:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577264788; cv=none; d=google.com; s=arc-20160816; b=I6RF7ovRAP4DUlrNspRfDCaoDt580GwmduFfh3jsebbjn00tbzF09yr/MRf8yd7sVh 6FChwQ0kAjtVUsghRNPwtBscW+GAJQ49Gz430owqlJW4Gn/cEI1YXHtY1+i60+E9T1BO QSd8KzMUg2nQYUdrvzzej6+Y4T9O06EKqijK0Mqn0RtVxl7TSM2nH0PXUWDQvzm8NyiB jI81gGMqn8L7IyJzipyAEXj78+Vs4gjPg+TJ/93EvngXfUc+vesbCIXzc0OvSP4Hv+B2 xf+yd0Gr0TJNpH47FXxIMr4mONCMapOs2P1XYR2nNsUUpr7IqNYixVXrSrSxgQzKCFIp vTnA== 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=ue9vyGKSmrIKAMI1xeXtIaw65L+c8RX/wog3/crxRnQ=; b=ApL7Hv32k5BiOia0A9GsvWCdK5UbNm51tKXIcyn9qL28KuaUTR5/yEgPAUIVcm8VE6 2cJNR2cNSsvtN5mSydzAHs0LtRldM/TvzpUhFquS1R3jKcKSvxxivnLWX0hezSrkgBj1 nVzEXwaaIBighdTIThRwb14Ozig7jImfStZCop/4JZ71jIEhTweGFoIL0LmJ8vScSpD0 vWDxFxr/xpovQ8UqdP8V4npZHaJbYSuqxpdvscfXRsNGrKaDkSDvTEFhVJtbZrsXyesI qjHhvbj8fWhHXHmhSXfmQBTXiO9kMW8xcVUFBDPwjYaO1am1OF00yRf1h5BYHPI2Dsr6 ht1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id z4si11732318oix.48.2019.12.25.01.06.17; Wed, 25 Dec 2019 01:06:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727100AbfLYJFK (ORCPT + 99 others); Wed, 25 Dec 2019 04:05:10 -0500 Received: from out30-54.freemail.mail.aliyun.com ([115.124.30.54]:36181 "EHLO out30-54.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726879AbfLYJFH (ORCPT ); Wed, 25 Dec 2019 04:05:07 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R711e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=29;SR=0;TI=SMTPD_---0TltG7cg_1577264682; Received: from localhost(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0TltG7cg_1577264682) by smtp.aliyun-inc.com(127.0.0.1); Wed, 25 Dec 2019 17:04:42 +0800 From: Alex Shi To: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, 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, shakeelb@google.com, hannes@cmpxchg.org Cc: Michal Hocko , Vladimir Davydov , Roman Gushchin , Chris Down , Thomas Gleixner , Vlastimil Babka , Andrey Ryabinin , swkhack , "Potyra, Stefan" , Jason Gunthorpe , Mauro Carvalho Chehab , Peng Fan , Nikolay Borisov , Ira Weiny , Kirill Tkhai , Yafang Shao Subject: [PATCH v7 04/10] mm/lru: introduce the relock_page_lruvec function Date: Wed, 25 Dec 2019 17:04:20 +0800 Message-Id: <1577264666-246071-5-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1577264666-246071-1-git-send-email-alex.shi@linux.alibaba.com> References: <1577264666-246071-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 During the lruvec locking, a new page's lruvec is may same as previous one. Thus we could save a re-locking, and only change lock iff lruvec is new. Function named relock_page_lruvec following Hugh Dickins' patch. Signed-off-by: Alex Shi Cc: Johannes Weiner Cc: Michal Hocko Cc: Vladimir Davydov Cc: Andrew Morton Cc: Roman Gushchin Cc: Shakeel Butt Cc: Chris Down Cc: Thomas Gleixner Cc: Vlastimil Babka Cc: Andrey Ryabinin Cc: swkhack Cc: "Potyra, Stefan" Cc: Jason Gunthorpe Cc: Matthew Wilcox Cc: Mauro Carvalho Chehab Cc: Peng Fan Cc: Nikolay Borisov Cc: Ira Weiny Cc: Kirill Tkhai Cc: Yang Shi Cc: Yafang Shao 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/vmscan.c | 8 ++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 8389b9b927ef..09e861df48e8 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1299,6 +1299,42 @@ static inline void dec_lruvec_page_state(struct page *page, mod_lruvec_page_state(page, idx, -1); } +/* 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/vmscan.c b/mm/vmscan.c index a97e35675286..a1d34ca1505e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4342,14 +4342,10 @@ 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 = mem_cgroup_page_lruvec(page, page_pgdat(page)); pgscanned++; - 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