]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
mm: Make page_index() THP-safe next
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 29 Oct 2020 18:07:47 +0000 (14:07 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Wed, 25 Nov 2020 02:03:43 +0000 (21:03 -0500)
You can't dereference page->index for tail pages, so use the head's
index to calculate the offset of this page in the file.  Also move
the function to pagemap.h since it's a pagecache function not used
by the rest of the kernel.  This also makes page_file_offset() work
when called for tail pages.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
include/linux/mm.h
include/linux/pagemap.h

index 0c7959ffc3b6e66153c29deb1ee990a30acb2dbf..63264601cdadfaf187a61232144bf9cb587a4390 100644 (file)
@@ -1555,19 +1555,6 @@ struct address_space *page_file_mapping(struct page *page)
        return page->mapping;
 }
 
-extern pgoff_t __page_file_index(struct page *page);
-
-/*
- * Return the pagecache index of the passed page.  Regular pagecache pages
- * use ->index whereas swapcache pages use swp_offset(->private)
- */
-static inline pgoff_t page_index(struct page *page)
-{
-       if (unlikely(PageSwapCache(page)))
-               return __page_file_index(page);
-       return page->index;
-}
-
 bool page_mapped(struct page *page);
 struct address_space *page_mapping(struct page *page);
 struct address_space *page_mapping_file(struct page *page);
index 3d017559a1ed1ad89fcaceaa2447a592ee3de3df..b46c4d222379f82484630ff3603e8a4d494f0135 100644 (file)
@@ -449,6 +449,20 @@ static inline struct page *grab_cache_page_nowait(struct address_space *mapping,
                        mapping_gfp_mask(mapping));
 }
 
+extern pgoff_t __page_file_index(struct page *page);
+
+/*
+ * Return the pagecache index of the passed page.  Regular pagecache pages
+ * use ->index whereas swapcache pages use swp_offset(->private)
+ */
+static inline pgoff_t page_index(struct page *page)
+{
+       struct page *head = thp_head(page);
+       if (unlikely(PageSwapCache(page)))
+               return __page_file_index(page);
+       return head->index + (page - head);
+}
+
 /* Does this page contain this index? */
 static inline bool thp_contains(struct page *head, pgoff_t index)
 {