From patchwork Fri Apr 22 02:20:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 12822673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45000C433F5 for ; Fri, 22 Apr 2022 02:21:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C80676B0072; Thu, 21 Apr 2022 22:21:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C084A6B0073; Thu, 21 Apr 2022 22:21:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA7C46B0074; Thu, 21 Apr 2022 22:21:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 97D5C6B0072 for ; Thu, 21 Apr 2022 22:21:53 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6C8656002D for ; Fri, 22 Apr 2022 02:21:53 +0000 (UTC) X-FDA: 79382914506.10.3856636 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by imf27.hostedemail.com (Postfix) with ESMTP id 0D7C640018 for ; Fri, 22 Apr 2022 02:21:51 +0000 (UTC) Received: by mail-ej1-f43.google.com with SMTP id g18so13541561ejc.10 for ; Thu, 21 Apr 2022 19:21:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=EfEdNS3ZxtRavEAsNGO2qYEoWtQSKCTCnO6+HagXHoc=; b=P3NpyibODxg1L5T0/UpA9HrUXmmgSWstLNSunCq7hd6Pczw3rAKA2etpLEvkm7fr36 2wG3+DuXT1lTG1M54k5Efs46CxYZSVtsUiSe4VRXCF+kb1Mj6OpKwTI6ksggDPsl/jNw CnGP7VxttorWnliLqKwf/NjfdbE0J09WkG1l2lxQ9ePqvtNa3jyTOYQfZ4hSRpDhnvw+ trlOGCFSU0O9ZY02tpRsWSOmqtJPGGaT9pOk0LL7sK/71Rv0KhTBwteMPelr6eFlYDVJ o5aBFmsPBB2+bNdZup9MqyADugMCY5Lox67cYxybm7j9XHZItqnJD2pFoZDVs0H0ZgNs R8kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=EfEdNS3ZxtRavEAsNGO2qYEoWtQSKCTCnO6+HagXHoc=; b=VEwOTQ2Np1f4RLFRLClkzLnPdxjBeRZa3G9SovZ3rOrkNapSBzSpnXTDnXdnhugclF v49sjVnrPChs1Oh1Zhc3aCaGZZ2gtMi4t340vAlLdtK3IIPTUFNhmUzHUU9+3rZOdzY+ mrY2oBrFFMiu2eoIdLjzLWqjrVDZiTXGdouZotDI7t5Qc0m8F7+qaMEN7BQBMBnJ0OSL TzTznEhxaiaX4jnoZiE3zp1tegi5aFQD5k5AI+8e7eacoDwdJC7djURmPLAZd2QSuWD3 08hf2wE/RAbU/B89nbu7bJ8rHxp0ZIxbFB5dbwlPn2D/OZaIO4NnDzdCGR2d+FxGxJBW Vhbg== X-Gm-Message-State: AOAM530GxooDllFR2TIPebGIc0PW9zfgXjYfLH1Tse40T+6aMB8n4VPk oRNI4yoO+n37wc+aSL1aRP0= X-Google-Smtp-Source: ABdhPJyrWC9elZrWND7HtMP1XblsUCJjyanFVjGFaiy01ZiszFggoGsRiBvNHchG1RltZVMWnTryYQ== X-Received: by 2002:a17:906:2bc5:b0:6cd:e676:3624 with SMTP id n5-20020a1709062bc500b006cde6763624mr2064789ejg.277.1650594111579; Thu, 21 Apr 2022 19:21:51 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 10-20020a170906310a00b006e834953b55sm259171ejx.27.2022.04.21.19.21.51 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Apr 2022 19:21:51 -0700 (PDT) From: Wei Yang To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang , Matthew Wilcox , Hugh Dickins Subject: [PATCH] mm/mlock: abstract a function to decide whether necessary to drain mlock_pvec Date: Fri, 22 Apr 2022 02:20:59 +0000 Message-Id: <20220422022059.31181-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 0D7C640018 X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=P3NpyibO; spf=pass (imf27.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.43 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: p8ksw6wpzhk68ogfuo9et344sdjg4ugc X-HE-Tag: 1650594111-330461 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Just like the function pagevec_add_and_need_flush does, we can abstract a function mlock_add_and_need_flush to decide whether it is necessary to drain mlock_pvec. No functional change is expected. Signed-off-by: Wei Yang CC: Matthew Wilcox (Oracle) CC: Hugh Dickins --- mm/mlock.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/mm/mlock.c b/mm/mlock.c index efd2dd2943de..26125d733934 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -169,6 +169,24 @@ static inline struct page *mlock_new(struct page *page) return (struct page *)((unsigned long)page + NEW_PAGE); } +static inline struct page *mlock_dummy(struct page *page) +{ + return page; +} + +/* return true if mlock_pvec needs to drain */ +static bool mlock_add_and_need_flush(struct pagevec *pvec, struct folio *folio, + struct page *(*mlock)(struct page *page)) +{ + bool ret = false; + + if (!pagevec_add(pvec, mlock(&folio->page)) || + folio_test_large(folio) || lru_cache_disabled()) + ret = true; + + return ret; +} + /* * mlock_pagevec() is derived from pagevec_lru_move_fn(): * perhaps that can make use of such page pointer flags in future, @@ -233,8 +251,7 @@ void mlock_folio(struct folio *folio) } folio_get(folio); - if (!pagevec_add(pvec, mlock_lru(&folio->page)) || - folio_test_large(folio) || lru_cache_disabled()) + if (mlock_add_and_need_flush(pvec, folio, mlock_lru)) mlock_pagevec(pvec); put_cpu_var(mlock_pvec); } @@ -253,8 +270,7 @@ void mlock_new_page(struct page *page) __count_vm_events(UNEVICTABLE_PGMLOCKED, nr_pages); get_page(page); - if (!pagevec_add(pvec, mlock_new(page)) || - PageHead(page) || lru_cache_disabled()) + if (mlock_add_and_need_flush(pvec, page_folio(page), mlock_new)) mlock_pagevec(pvec); put_cpu_var(mlock_pvec); } @@ -273,8 +289,7 @@ void munlock_page(struct page *page) */ get_page(page); - if (!pagevec_add(pvec, page) || - PageHead(page) || lru_cache_disabled()) + if (mlock_add_and_need_flush(pvec, page_folio(page), mlock_dummy)) mlock_pagevec(pvec); put_cpu_var(mlock_pvec); }