From: Ackerley Tng <ackerleytng@google.com>
To: akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
mike.kravetz@oracle.com, muchun.song@linux.dev,
willy@infradead.org, sidhartha.kumar@oracle.com,
jhubbard@nvidia.com
Cc: vannapurve@google.com, erdemaktas@google.com,
Ackerley Tng <ackerleytng@google.com>
Subject: [PATCH 1/2] mm: filemap: Add filemap_has_folio function
Date: Tue, 2 May 2023 23:56:02 +0000 [thread overview]
Message-ID: <98624c2f481966492b4eb8272aef747790229b73.1683069252.git.ackerleytng@google.com> (raw)
In-Reply-To: <cover.1683069252.git.ackerleytng@google.com>
filemap_has_folio() will return whether there is a folio at a given
index in a mapping. This function does not affect the folio refcount.
Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
include/linux/pagemap.h | 1 +
mm/filemap.c | 17 +++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index a56308a9d1a4..e49f07cdbff7 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -508,6 +508,7 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping,
#define FGP_WRITEBEGIN (FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE)
+bool filemap_has_folio(struct address_space *mapping, pgoff_t index);
void *filemap_get_entry(struct address_space *mapping, pgoff_t index);
struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
int fgp_flags, gfp_t gfp);
diff --git a/mm/filemap.c b/mm/filemap.c
index a34abfe8c654..a7a6e229e33d 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1835,6 +1835,23 @@ EXPORT_SYMBOL(page_cache_prev_miss);
* folio_put().
*/
+/**
+ * filemap_has_folio - Check if filemap has a folio at given index
+ * @mapping: The address_space to search.
+ * @index: The page index.
+ *
+ * Unlike filemap_get_entry, this does not increment refcount of the folio.
+ *
+ * Return: true if folio exists else false.
+ */
+bool filemap_has_folio(struct address_space *mapping, pgoff_t index)
+{
+ void *entry = xa_load(&mapping->i_pages, index);
+
+ return entry && !xa_is_value(entry);
+}
+EXPORT_SYMBOL(filemap_has_folio);
+
/*
* filemap_get_entry - Get a page cache entry.
* @mapping: the address_space to search
--
2.40.1.495.gc816e09b53d-goog
next prev parent reply other threads:[~2023-05-02 23:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-02 23:56 [PATCH 0/2] Fix fallocate error in hugetlbfs when fallocating again Ackerley Tng
2023-05-02 23:56 ` Ackerley Tng [this message]
2023-05-02 23:56 ` [PATCH 2/2] fs: hugetlbfs: Fix logic to skip allocation on hit in page cache Ackerley Tng
2023-05-03 3:05 ` Mike Kravetz
2023-05-04 0:14 ` Mike Kravetz
2023-05-08 16:29 ` Ackerley Tng
2023-05-08 20:40 ` Ackerley Tng
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=98624c2f481966492b4eb8272aef747790229b73.1683069252.git.ackerleytng@google.com \
--to=ackerleytng@google.com \
--cc=akpm@linux-foundation.org \
--cc=erdemaktas@google.com \
--cc=jhubbard@nvidia.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=muchun.song@linux.dev \
--cc=sidhartha.kumar@oracle.com \
--cc=vannapurve@google.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox