All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: akpm@linux-foundation.org
Cc: linux-mm@kvack.org, Wei Yang <richard.weiyang@gmail.com>,
	Matthew Wilcox <willy@infradead.org>,
	Hugh Dickins <hughd@google.com>
Subject: [PATCH] mm/mlock: abstract a function to decide whether necessary to drain mlock_pvec
Date: Fri, 22 Apr 2022 02:20:59 +0000	[thread overview]
Message-ID: <20220422022059.31181-1-richard.weiyang@gmail.com> (raw)

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 <richard.weiyang@gmail.com>
CC: Matthew Wilcox (Oracle) <willy@infradead.org>
CC: Hugh Dickins <hughd@google.com>
---
 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);
 }
-- 
2.33.1



             reply	other threads:[~2022-04-22  2:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-22  2:20 Wei Yang [this message]
2022-04-22  2:39 ` [PATCH] mm/mlock: abstract a function to decide whether necessary to drain mlock_pvec Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220422022059.31181-1-richard.weiyang@gmail.com \
    --to=richard.weiyang@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.