]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
mm: Reimplement compound_order()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Sun, 4 Sep 2022 23:27:16 +0000 (19:27 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 3 Jan 2023 04:00:55 +0000 (23:00 -0500)
Make compound_order() use struct folio.  It can't be turned into a wrapper
around folio_order() as a page can be turned into a tail page between
a check in compound_order() and the assertion in folio_test_large().

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

index fca37afa71c83cee7cb34a57d09b3451b6e46e8e..19bdb4b0e00ae6a712d9a0d2b877c90d7c6b396d 100644 (file)
@@ -714,11 +714,20 @@ int vma_is_stack_for_current(struct vm_area_struct *vma);
 struct mmu_gather;
 struct inode;
 
+/*
+ * compound_order() can be called without holding a reference, which means
+ * that niceties like page_folio() don't work.  These callers should be
+ * prepared to handle wild return values.  For example, PG_head may be
+ * set before _folio_order is initialised, or this may be a tail page.
+ * See compaction.c for some good examples.
+ */
 static inline unsigned int compound_order(struct page *page)
 {
-       if (!PageHead(page))
+       struct folio *folio = (struct folio *)page;
+
+       if (!test_bit(PG_head, &folio->flags))
                return 0;
-       return page[1].compound_order;
+       return folio->_folio_order;
 }
 
 /**