Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp474188ybc; Tue, 19 Nov 2019 04:27:07 -0800 (PST) X-Google-Smtp-Source: APXvYqyoqBcKFojG21X/RGccGfl/0HfJoXXJFnCOqJGI1AH5f2tUHZ2D926+SBeET1e4Rj8rVuta X-Received: by 2002:a17:906:4c8c:: with SMTP id q12mr35365661eju.256.1574166427056; Tue, 19 Nov 2019 04:27:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574166427; cv=none; d=google.com; s=arc-20160816; b=EeWe66Cz0E86mCY7XoBDWsknYHtowwW4oUczIAC+BPY+5Oa6VeH7CwzlBzjm6rJBcL g/Jl1skpSR+xxDWptyfFn31w5Y6rc5FxunCWKeGJ+mGbU5xGyvBsUyBIBFIYbUHsjXf5 AmtEuT5JJBwhevkbrdXt9cL4VpHPf9bxQ8QkfYMaoGuBQ9EPJEQyGhD7DDp/Ha3hckQ0 2uuo+L5evbtLtSnzeP9pO+IrhkABho6yFI+6IzTnkbauxMRJurcnGqeYwEIgYMppNpJF A4WxS8MEVpkUMp2kg0WxXm1jShiO/Di/L+xqpVS7kUe/+mX8rxfu/ALrpVG/BQCX5cKw XXjA== 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=5/8ONs+i2o87caBHQBl5KBT4brzj/D90mcNUBOrpVXw=; b=om2OktrQobDGOvE/UjSl+KNaiCFxWyQyqAGgrD3a/UUldeG4IhuGCa3OhBMbUpLas0 iBEh96qNAKE15iQT8IIdNMccC5uOnwSsyO9lDonkrRgJLpiRea4D9/EqAOVJwQXzqOiH X8JaFMSljKV2VRhsHBp1gLyJ+UD8xIy8M8915xVYD8+TCM7wRUuRNTOvygRBjTsfrB8N 9t0Y8OQFhh20/0QqG2N1rtVq05kKyZiUAxFXEbyhj+gScDv8edEfwZ4avSBGmrSebe4V 6gSdYf+9/st7gXrUF7Kg4N5A+EmDuSyuyATpbNq17x7KUmGUw+O+yIg78tFRAh9ENHM7 5/Ww== 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 me8si13715834ejb.382.2019.11.19.04.26.43; Tue, 19 Nov 2019 04:27:07 -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 S1727919AbfKSMYP (ORCPT + 99 others); Tue, 19 Nov 2019 07:24:15 -0500 Received: from out30-42.freemail.mail.aliyun.com ([115.124.30.42]:33467 "EHLO out30-42.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725798AbfKSMYO (ORCPT ); Tue, 19 Nov 2019 07:24:14 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01422;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=30;SR=0;TI=SMTPD_---0TiZ35.b_1574166247; Received: from localhost(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0TiZ35.b_1574166247) 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 6/9] mm/vmscan: only change the lru_lock iff page's lruvec is different Date: Tue, 19 Nov 2019 20:23:20 +0800 Message-Id: <1574166203-151975-7-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 Used relock_page_lruvec in more places for spin_lock reducing. 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/vmscan.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 3cdf343e7a27..ba57c55a6a41 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1825,22 +1825,25 @@ static int too_many_isolated(struct pglist_data *pgdat, int file, * Returns the number of pages moved to the given lruvec. */ -static unsigned noinline_for_stack move_pages_to_lru(struct lruvec *lruvec, +static unsigned noinline_for_stack move_pages_to_lru(struct lruvec *llvec, struct list_head *list) { int nr_pages, nr_moved = 0; LIST_HEAD(pages_to_free); struct page *page; enum lru_list lru; + struct lruvec *lruvec = llvec; while (!list_empty(list)) { page = lru_to_page(list); + lruvec = relock_page_lruvec_irq(page, lruvec); + VM_BUG_ON_PAGE(PageLRU(page), page); if (unlikely(!page_evictable(page))) { list_del(&page->lru); spin_unlock_irq(&lruvec->lru_lock); + lruvec = NULL; putback_lru_page(page); - spin_lock_irq(&lruvec->lru_lock); continue; } @@ -1858,8 +1861,8 @@ static unsigned noinline_for_stack move_pages_to_lru(struct lruvec *lruvec, if (unlikely(PageCompound(page))) { spin_unlock_irq(&lruvec->lru_lock); + lruvec = NULL; (*get_compound_page_dtor(page))(page); - spin_lock_irq(&lruvec->lru_lock); } else list_add(&page->lru, &pages_to_free); } else { @@ -1867,6 +1870,11 @@ static unsigned noinline_for_stack move_pages_to_lru(struct lruvec *lruvec, } } + if (lruvec != llvec) { + if (lruvec) + spin_unlock_irq(&lruvec->lru_lock); + spin_lock_irq(&llvec->lru_lock); + } /* * To save our caller's stack, now use input list for pages to free. */ @@ -4289,18 +4297,10 @@ void check_move_unevictable_pages(struct pagevec *pvec) for (i = 0; i < pvec->nr; i++) { struct page *page = pvec->pages[i]; - struct pglist_data *pgdat = page_pgdat(page); - struct lruvec *new_lruvec = mem_cgroup_page_lruvec(page, pgdat); - pgscanned++; - if (lruvec != new_lruvec) { - if (lruvec) - spin_unlock_irq(&lruvec->lru_lock); - lruvec = new_lruvec; - spin_lock_irq(&lruvec->lru_lock); - } + lruvec = relock_page_lruvec_irq(page, lruvec); if (!PageLRU(page) || !PageUnevictable(page)) continue; -- 1.8.3.1