]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs: Turn page_offset() into a wrapper around folio_pos()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 21 Feb 2025 20:39:29 +0000 (20:39 +0000)
committerChristian Brauner <brauner@kernel.org>
Mon, 24 Feb 2025 10:41:43 +0000 (11:41 +0100)
This is far less efficient for the lagging filesystems which still
use page_offset(), but it removes an access to page->index.  It also
fixes a bug -- if any filesystem passed a tail page to page_offset(),
it would return garbage which might result in the filesystem choosing
to not writeback a dirty page.  There probably aren't any examples
of this, but I can't be certain.

Signed-off-by: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Link: https://lore.kernel.org/r/20250221203932.3588740-1-willy@infradead.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/pagemap.h

index 47bfc6b1b632dc8812795825a5c1c0554ed10319..f348e7005306aad6974a57f7d0717a2112b9882f 100644 (file)
@@ -1044,21 +1044,23 @@ static inline pgoff_t page_pgoff(const struct folio *folio,
        return folio->index + folio_page_idx(folio, page);
 }
 
-/*
- * Return byte-offset into filesystem object for page.
+/**
+ * folio_pos - Returns the byte position of this folio in its file.
+ * @folio: The folio.
  */
-static inline loff_t page_offset(struct page *page)
+static inline loff_t folio_pos(const struct folio *folio)
 {
-       return ((loff_t)page->index) << PAGE_SHIFT;
+       return ((loff_t)folio->index) * PAGE_SIZE;
 }
 
-/**
- * folio_pos - Returns the byte position of this folio in its file.
- * @folio: The folio.
+/*
+ * Return byte-offset into filesystem object for page.
  */
-static inline loff_t folio_pos(struct folio *folio)
+static inline loff_t page_offset(struct page *page)
 {
-       return page_offset(&folio->page);
+       struct folio *folio = page_folio(page);
+
+       return folio_pos(folio) + folio_page_idx(folio, page) * PAGE_SIZE;
 }
 
 /*