Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8547243ybl; Wed, 25 Dec 2019 01:06:40 -0800 (PST) X-Google-Smtp-Source: APXvYqwCZMVIE8M0bxX3HGqQeVCmZ6m9fM0IT+9/OzgU1gDxnmKtudNGrAgOuABZXhbKzpxJ2oVn X-Received: by 2002:a05:6830:2097:: with SMTP id y23mr29087816otq.286.1577264800286; Wed, 25 Dec 2019 01:06:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577264800; cv=none; d=google.com; s=arc-20160816; b=LUlS9RkaIWMvoV+nAqhhkx2oHPb8+dlngUDKxcf1IywlxKSzCK3Sp8dbqDSmEwtJxl DgWXiRO+2Ij6ANdWNhgtcfCj9RmIaorbe64NfG4+I1Nzhjn1/v4FvRcoxJMBa7L+JuKO DAGeMd/2vFdEwGQQYihT/3V2zN5q6bBZiVABTQGZHCvmaQbwbyZgS0d7a2R8IITHEc0b n7ww8ss6iHmFPeLtWBgzyjML3+5L/fMjzUzlIoaAZFo/lz0okzDDR+WS6V3fmEFw/npA NaXizB3S1eZ5Hw4qy/3WIG2pOq5vQP61dK2dAPIBVHU7BGtUxPr0l27wFaRI3AJ0u9uk LueQ== 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:to:from; bh=ReGw1gcacz6zC+PoPvov/lFuuAKEZ9F8O3yxu+3I/6s=; b=SgQPHC0NHhjo0Rc2sq0YsWjD5GuZuk17VoABMWn4C4Gj9V1/S6KFaQnwuS7nW3ia1U H/NhngB0PPyGK2uCoFbdBmuhpqRJgPl6L7haKgqjA59E8JUDA0elNxV7ucsmThRg9wN9 y4OKdbB7JqJemXvCV2ER9jtnW+M51xfOGYoeoB6+m9E+WqMEKA3Z8YujIuFwCypXBdSG JUnAXOWU1fyK8GRbf5RlQlXZf4r3SLjIEQWTYf7vxXSyYljlhDfSjnaWajQQuTLyB67D OZzhe1L+MtwXv3PeGD4Nbgn8PBAXhmsLS1V3t4imOgkiMa002blPBHMdLw7xhn91ClND HcLA== 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 e9si13548753otk.318.2019.12.25.01.06.29; Wed, 25 Dec 2019 01:06:40 -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 S1726832AbfLYJEs (ORCPT + 99 others); Wed, 25 Dec 2019 04:04:48 -0500 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]:53127 "EHLO out30-131.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726106AbfLYJEr (ORCPT ); Wed, 25 Dec 2019 04:04:47 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0TltSdOF_1577264682; Received: from localhost(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0TltSdOF_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 Subject: [PATCH v7 05/10] mm/mlock: optimize munlock_pagevec by relocking Date: Wed, 25 Dec 2019 17:04:21 +0800 Message-Id: <1577264666-246071-6-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 pagevec 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 newer. Signed-off-by: Alex Shi Cc: Johannes Weiner Cc: Hugh Dickins Cc: linux-kernel@vger.kernel.org Cc: cgroups@vger.kernel.org Cc: linux-mm@kvack.org Cc: Andrew Morton --- mm/mlock.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mm/mlock.c b/mm/mlock.c index 10d15f58b061..050f999eadb1 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -289,6 +289,7 @@ 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; struct lruvec *lruvec = NULL; int pgrescued = 0; @@ -299,20 +300,19 @@ static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone) for (i = 0; i < nr; i++) { struct page *page = pvec->pages[i]; - lruvec = lock_page_lruvec_irq(page); + lruvec = relock_page_lruvec_irq(page, lruvec); 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, lruvec, false)) { - __mod_zone_page_state(zone, NR_MLOCK, -1); - unlock_page_lruvec_irq(lruvec); + if (__munlock_isolate_lru_page(page, lruvec, false)) continue; - } else + else __munlock_isolation_failed(page); - } + } else + delta_munlocked++; /* * We won't be munlocking this page in the next phase @@ -322,8 +322,10 @@ static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone) */ pagevec_add(&pvec_putback, pvec->pages[i]); pvec->pages[i] = NULL; - unlock_page_lruvec_irq(lruvec); } + __mod_zone_page_state(zone, NR_MLOCK, delta_munlocked); + if (lruvec) + unlock_page_lruvec_irq(lruvec); /* Now we can release pins of pages that we are not munlocking */ pagevec_release(&pvec_putback); -- 1.8.3.1