@@ -1122,6 +1122,9 @@ static inline pgoff_t page_index(struct page *page)
bool page_mapped(struct page *page);
struct address_space *page_mapping(struct page *page);
+/* page->mapping cannot point into the zero page. */
+#define MAPPING_PFMEMALLOC ((struct address_space *)4)
+
/*
* Return true only if the page has been allocated with
* ALLOC_NO_WATERMARKS and the low watermark was not
@@ -1129,11 +1132,7 @@ struct address_space *page_mapping(struct page *page);
*/
static inline bool page_is_pfmemalloc(struct page *page)
{
- /*
- * Page index cannot be this large so this must be
- * a pfmemalloc page.
- */
- return page->index == -1UL;
+ return page->mapping == MAPPING_PFMEMALLOC;
}
/*
@@ -1142,12 +1141,7 @@ static inline bool page_is_pfmemalloc(struct page *page)
*/
static inline void set_page_pfmemalloc(struct page *page)
{
- page->index = -1UL;
-}
-
-static inline void clear_page_pfmemalloc(struct page *page)
-{
- page->index = 0;
+ page->mapping = MAPPING_PFMEMALLOC;
}
/*
@@ -1047,7 +1047,7 @@ static __always_inline bool free_pages_prepare(struct page *page,
(page + i)->flags &= ~PAGE_FLAGS_CHECK_AT_PREP;
}
}
- if (PageMappingFlags(page))
+ if (PageMappingFlags(page) || page_is_pfmemalloc(page))
page->mapping = NULL;
if (memcg_kmem_enabled() && PageKmemcg(page))
memcg_kmem_uncharge(page, order);
@@ -1802,8 +1802,8 @@ inline void post_alloc_hook(struct page *page, unsigned int order,
set_page_owner(page, order, gfp_flags);
}
-static void prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags,
- unsigned int alloc_flags)
+static void prep_new_page(struct page *page, unsigned int order,
+ gfp_t gfp_flags, unsigned int alloc_flags)
{
int i;
@@ -1824,8 +1824,6 @@ static void prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags
*/
if (alloc_flags & ALLOC_NO_WATERMARKS)
set_page_pfmemalloc(page);
- else
- clear_page_pfmemalloc(page);
}
/*