LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: John Hubbard <jhubbard@nvidia.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Matthew Wilcox <willy@infradead.org>
Cc: LKML <linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
John Hubbard <jhubbard@nvidia.com>
Subject: [PATCH 3/3] mm/gup: refactor and simplify try_get_page()
Date: Sun, 8 Aug 2021 16:50:18 -0700 [thread overview]
Message-ID: <20210808235018.1924918-4-jhubbard@nvidia.com> (raw)
In-Reply-To: <20210808235018.1924918-1-jhubbard@nvidia.com>
try_get_page() is very similar to try_get_compound_head(), and in fact
try_get_page() has fallen a little behind in terms of maintenance:
try_get_compound_head() handles speculative page references more
thoroughly.
Change try_get_page() so that it is implemented in terms of
try_get_compound_head(), but without changing try_get_page()'s API
contract.
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
include/linux/mm.h | 11 ++++++-----
mm/gup.c | 2 +-
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index ce8fc0fd6d6e..92d3b37357d5 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1207,14 +1207,15 @@ bool __must_check try_grab_page(struct page *page, unsigned int flags);
__maybe_unused struct page *try_grab_compound_head(struct page *page, int refs,
unsigned int flags);
+struct page *try_get_compound_head(struct page *page, int refs);
+/*
+ * This has the same functionality as try_get_compound_head(), just with a
+ * slightly different API.
+ */
static inline __must_check bool try_get_page(struct page *page)
{
- page = compound_head(page);
- if (WARN_ON_ONCE(page_ref_count(page) <= 0))
- return false;
- page_ref_inc(page);
- return true;
+ return try_get_compound_head(page, 1) != NULL;
}
/**
diff --git a/mm/gup.c b/mm/gup.c
index 4be6f060fa0b..ba75906ba7f7 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -66,7 +66,7 @@ static void put_page_refs(struct page *page, int refs)
* Return the compound head page with ref appropriately incremented,
* or NULL if that failed.
*/
-static inline struct page *try_get_compound_head(struct page *page, int refs)
+struct page *try_get_compound_head(struct page *page, int refs)
{
struct page *head = compound_head(page);
--
2.32.0
next prev parent reply other threads:[~2021-08-08 23:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-08 23:50 [PATCH 0/3] A few gup refactorings and documentation updates John Hubbard
2021-08-08 23:50 ` [PATCH 1/3] mm/gup: documentation corrections for gup/pup John Hubbard
2021-08-09 1:39 ` Matthew Wilcox
2021-08-09 6:46 ` John Hubbard
2021-08-10 21:19 ` John Hubbard
2021-08-08 23:50 ` [PATCH 2/3] mm/gup: small refactoring: simplify try_grab_page() John Hubbard
2021-08-09 6:38 ` Christoph Hellwig
2021-08-09 6:46 ` John Hubbard
2021-08-08 23:50 ` John Hubbard [this message]
2021-08-09 6:29 ` [PATCH 3/3] mm/gup: refactor and simplify try_get_page() Christoph Hellwig
2021-08-09 6:36 ` John Hubbard
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=20210808235018.1924918-4-jhubbard@nvidia.com \
--to=jhubbard@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.org \
--subject='Re: [PATCH 3/3] mm/gup: refactor and simplify try_get_page()' \
/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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).