Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp473758ybc; Tue, 19 Nov 2019 04:26:45 -0800 (PST) X-Google-Smtp-Source: APXvYqy8ULULSHAaBSx8IGK4xaOmSp1Bi25/1Egd+fIy6oLRzKovg8sM6l6Mwt8mSvDOs1XW8V3T X-Received: by 2002:a17:906:9458:: with SMTP id z24mr34031323ejx.289.1574166404881; Tue, 19 Nov 2019 04:26:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574166404; cv=none; d=google.com; s=arc-20160816; b=b20I9yos2zMtCOFMjzDKXLEILeSFP8K2hEc3V9fHP/pq6g5SN2QkJFUqmDvu1rfRLQ 9LXRtn7sobfdTswTx110KQ2oWt0orhOf9F7qbOS5cJIbGhqR4KbO+ll+7Yfo/IvfvbWW Hxyz5LZUDIaHs+D601KrEF9J++mVi2XWdfCpRMTs45l/y5nwoDd+ciW+0N5OWIrs0FbP 0lEnKBkouKbwlhbg5Cnwn0sTTnxwaB8Ace9oyranFT6ENfBvFUvqg/x98f+0cCa2sf5/ yEecpiU2pinvdYskbL318V/RoCx/JhEDG4aWvpdH+CqMHEMzF22JLpn1vLGG9EEqZruy aItA== 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=dQqG7Ppy/zMZpyHSijoa6rHyHhzItjORExxpWFiUgHw=; b=e3JdTx7kv6Kj6B3P35zo0kOionR1/jCtPVMmeQp7r6hH16fCV6G6zuI7iCi7TRG+Wa oOXfyRtL1bpu6lxtvlcaqv4kHtrSEzdN6qz11Kei8f55SC9yhCDt4bNSqdEtC4wffIcl m3ZM0d9ne4jF8GUuqhLw/YMa/2De8aw9e4/OT6CpOGfRj/VbhMeNAasyMeq55xWjpM0o Vegkh1hoSxjGpxwMN6I9of6a95q4HTVB38BOuGrS8NGqYEeKop1pqtckBQ4My7voquwA wO915+L4tfpwIR8VIhlh9be2pVeZD+959NhnybJHsEidiPQmyHpCwEnVE+5z8ZD4afzd oPvg== 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 z26si13546738ejb.223.2019.11.19.04.26.20; Tue, 19 Nov 2019 04:26:44 -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 S1728035AbfKSMYT (ORCPT + 99 others); Tue, 19 Nov 2019 07:24:19 -0500 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:51831 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727814AbfKSMYQ (ORCPT ); Tue, 19 Nov 2019 07:24:16 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=30;SR=0;TI=SMTPD_---0TiZ7z35_1574166246; Received: from localhost(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0TiZ7z35_1574166246) by smtp.aliyun-inc.com(127.0.0.1); Tue, 19 Nov 2019 20:24:07 +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: Alex Shi , 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 v4 5/9] mm/swap: only change the lru_lock iff page's lruvec is different Date: Tue, 19 Nov 2019 20:23:19 +0800 Message-Id: <1574166203-151975-6-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1574166203-151975-1-git-send-email-alex.shi@linux.alibaba.com> References: <1574166203-151975-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 Since we introduced relock_page_lruvec, we could use it in more place to reduce spin_locks. 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 --- mm/swap.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index 05fee145e382..a023e6095bd9 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -197,11 +197,12 @@ static void pagevec_lru_move_fn(struct pagevec *pvec, for (i = 0; i < pagevec_count(pvec); i++) { struct page *page = pvec->pages[i]; - lruvec = lock_page_lruvec_irqsave(page, page_pgdat(page), &flags); + lruvec = relock_page_lruvec_irqsave(page, lruvec, &flags); (*move_fn)(page, lruvec, arg); - spin_unlock_irqrestore(&lruvec->lru_lock, flags); } + if (lruvec) + spin_unlock_irqrestore(&lruvec->lru_lock, flags); release_pages(pvec->pages, pvec->nr); pagevec_reinit(pvec); @@ -820,15 +821,12 @@ void release_pages(struct page **pages, int nr) } if (PageLRU(page)) { - struct lruvec *new_lruvec = mem_cgroup_page_lruvec(page, page_pgdat(page)); + struct lruvec *pre_lruvec = lruvec; - if (new_lruvec != lruvec) { - if (lruvec) - spin_unlock_irqrestore(&lruvec->lru_lock, flags); + lruvec = relock_page_lruvec_irqsave(page, lruvec, &flags); + if (pre_lruvec != lruvec) lock_batch = 0; - lruvec = lock_page_lruvec_irqsave(page, page_pgdat(page), &flags); - } VM_BUG_ON_PAGE(!PageLRU(page), page); __ClearPageLRU(page); del_page_from_lru_list(page, lruvec, page_off_lru(page)); -- 1.8.3.1