Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3824822ybl; Tue, 20 Aug 2019 02:52:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqwE0FviVUIp2MsTrb6yKxuraHLcNVZ3QBX7fmGO1lTvssu44NTqfuRBd2KXTqQAcwnZk5Ra X-Received: by 2002:a17:90a:650c:: with SMTP id i12mr25172659pjj.11.1566294757300; Tue, 20 Aug 2019 02:52:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566294757; cv=none; d=google.com; s=arc-20160816; b=HiLK11bb7sl+SwQ+B1hz5DmYVgGtNWnWZUuft8otBZ0qWvgJIvP2vsfbvkSghas/r2 Kghjj1vDKyI3mPg9Ay/9s5GweYUShzhkutcyYJ9sjQYLDvNaLrR0CtKcVBG03GjeUGne KQwEYkzkitPOqIPGsoLnHWKfi3KqdXzbpvlYNAfaUNmyzxc7FTljyQjn3VgXcA48cCkh G16kmpF2w4Qit204/PQ2VNfrSszKiMujumpfx4o/ESW1/WNFcso9iuCdIkOUv69MpsLo ZqlKc+8wlRGe+ILoxaqc3XTH/IQtLpqZbGas+Cq8B5DvT4kmDrwQGQNK3YhPTUdv9epQ 4HgA== 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=5IBlDLYPAPLo2k97VWQfP2A9PL5/LqClZZkLSuPmnZs=; b=S6+bMymrk86n760n96gzmfQXbaqaiUdiqellq2PnyPy4F8pWTJnJVoHMx8Hovdma6R CCUkUWQdTfbG1xSkWHFfuN+LktN2l3IRHuYOXSbqLOpYUNw82wLkbN4dCth1/rPSAuug lD6t3nImmVXxxJfWuOjZ9VPGW506mUdcWu10n2QOyvcKGaJA9YJ3/cxRV7X7DP0/FSSm NoTTCkuIMJMAQ8FkP8yW4aaOlblZ3QxsyMf7IlN80St2VuI9YYAq6JHzILzLEmUBP7fg XPYOa3ha4G08H6lllO20DV4XbIAz5aht/m0+OBw/P2quCBj+DD/DIMQifVfngII87AhJ R0YA== 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 e9si2846896pjj.66.2019.08.20.02.52.22; Tue, 20 Aug 2019 02:52:37 -0700 (PDT) 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 S1729768AbfHTJtr (ORCPT + 99 others); Tue, 20 Aug 2019 05:49:47 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:48162 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729736AbfHTJtq (ORCPT ); Tue, 20 Aug 2019 05:49:46 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07486;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0TZztT4i_1566294574; Received: from localhost(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0TZztT4i_1566294574) by smtp.aliyun-inc.com(127.0.0.1); Tue, 20 Aug 2019 17:49:34 +0800 From: Alex Shi To: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Mel Gorman , Tejun Heo Cc: Alex Shi , Vlastimil Babka , Michal Hocko , Andrey Ryabinin , swkhack , "Potyra, Stefan" Subject: [PATCH 06/14] lru/mlock: using per lruvec lock in munlock Date: Tue, 20 Aug 2019 17:48:29 +0800 Message-Id: <1566294517-86418-7-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1566294517-86418-1-git-send-email-alex.shi@linux.alibaba.com> References: <1566294517-86418-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 This patch using sperate lruvec lock for each of pages in __munlock_pagevec(). Also this patch pass a lruvec in __munlock_isolate_lru_page() as parameter to reduce a repeat lruvec locating. Signed-off-by: Alex Shi Cc: Andrew Morton Cc: Vlastimil Babka Cc: Michal Hocko Cc: Mel Gorman Cc: Andrey Ryabinin Cc: swkhack Cc: "Potyra, Stefan" Cc: Tejun Heo Cc: cgroups@vger.kernel.org Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/mlock.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/mm/mlock.c b/mm/mlock.c index 1279684bada0..9915968d490a 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -106,12 +106,10 @@ void mlock_vma_page(struct page *page) * Isolate a page from LRU with optional get_page() pin. * Assumes lru_lock already held and page already pinned. */ -static bool __munlock_isolate_lru_page(struct page *page, bool getpage) +static bool __munlock_isolate_lru_page(struct page *page, + struct lruvec *lruvec, bool getpage) { if (PageLRU(page)) { - struct lruvec *lruvec; - - lruvec = mem_cgroup_page_lruvec(page, page_pgdat(page)); if (getpage) get_page(page); ClearPageLRU(page); @@ -183,6 +181,9 @@ unsigned int munlock_vma_page(struct page *page) { int nr_pages; pg_data_t *pgdat = page_pgdat(page); + struct lruvec *lruvec; + + lruvec = mem_cgroup_page_lruvec(page, pgdat); /* For try_to_munlock() and to serialize with page migration */ BUG_ON(!PageLocked(page)); @@ -194,7 +195,8 @@ unsigned int munlock_vma_page(struct page *page) * might otherwise copy PageMlocked to part of the tail pages before * we clear it in the head page. It also stabilizes hpage_nr_pages(). */ - spin_lock_irq(&pgdat->lruvec.lru_lock); + spin_lock_irq(&lruvec->lru_lock); + sync_lruvec_pgdat(lruvec, pgdat); if (!TestClearPageMlocked(page)) { /* Potentially, PTE-mapped THP: do not skip the rest PTEs */ @@ -205,15 +207,15 @@ unsigned int munlock_vma_page(struct page *page) nr_pages = hpage_nr_pages(page); __mod_zone_page_state(page_zone(page), NR_MLOCK, -nr_pages); - if (__munlock_isolate_lru_page(page, true)) { - spin_unlock_irq(&pgdat->lruvec.lru_lock); + if (__munlock_isolate_lru_page(page, lruvec, true)) { + spin_unlock_irq(&lruvec->lru_lock); __munlock_isolated_page(page); goto out; } __munlock_isolation_failed(page); unlock_out: - spin_unlock_irq(&pgdat->lruvec.lru_lock); + spin_unlock_irq(&lruvec->lru_lock); out: return nr_pages - 1; @@ -291,28 +293,30 @@ static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone) { int i; int nr = pagevec_count(pvec); - int delta_munlocked = -nr; struct pagevec pvec_putback; int pgrescued = 0; pagevec_init(&pvec_putback); /* Phase 1: page isolation */ - spin_lock_irq(&zone->zone_pgdat->lruvec.lru_lock); for (i = 0; i < nr; i++) { struct page *page = pvec->pages[i]; + pg_data_t *pgdat = page_pgdat(page); + struct lruvec *lruvec = mem_cgroup_page_lruvec(page, pgdat); + spin_lock_irq(&lruvec->lru_lock); + sync_lruvec_pgdat(lruvec, pgdat); if (TestClearPageMlocked(page)) { /* * We already have pin from follow_page_mask() * so we can spare the get_page() here. */ - if (__munlock_isolate_lru_page(page, false)) + if (__munlock_isolate_lru_page(page, lruvec, false)) { + __mod_zone_page_state(zone, NR_MLOCK, -1); + spin_unlock_irq(&lruvec->lru_lock); continue; - else + } else __munlock_isolation_failed(page); - } else { - delta_munlocked++; } /* @@ -323,9 +327,8 @@ static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone) */ pagevec_add(&pvec_putback, pvec->pages[i]); pvec->pages[i] = NULL; + spin_unlock_irq(&lruvec->lru_lock); } - __mod_zone_page_state(zone, NR_MLOCK, delta_munlocked); - spin_unlock_irq(&zone->zone_pgdat->lruvec.lru_lock); /* Now we can release pins of pages that we are not munlocking */ pagevec_release(&pvec_putback); -- 1.8.3.1