summaryrefslogtreecommitdiffstats
path: root/include/linux/mm.h
diff options
context:
space:
mode:
authorMatthew Wilcox (Oracle) <willy@infradead.org>2023-01-11 14:29:02 +0000
committerAndrew Morton <akpm@linux-foundation.org>2023-02-02 22:32:58 -0800
commit5eb5cea11dcbafaa37685bc4e89e1d4ae9c434ea (patch)
treea1c5833b70e2c14731c73f085b6fb8a3a89586e9 /include/linux/mm.h
parent1aa4d03b60c0f61a8d96d5d633bf7968dbf6841f (diff)
downloadlinux-stable-5eb5cea11dcbafaa37685bc4e89e1d4ae9c434ea.tar.gz
linux-stable-5eb5cea11dcbafaa37685bc4e89e1d4ae9c434ea.tar.bz2
linux-stable-5eb5cea11dcbafaa37685bc4e89e1d4ae9c434ea.zip
mm: reimplement compound_order()
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(). Link: https://lkml.kernel.org/r/20230111142915.1001531-17-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'include/linux/mm.h')
-rw-r--r--include/linux/mm.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 7ff6e2410aa3..3adc37cebe6f 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -719,11 +719,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;
}
/**