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>
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);
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)
{