From: Matthew Wilcox <mawil...@microsoft.com> I want to use page->index for a different purpose, so move the pfmemalloc indicator from page->index to page->mapping.
Signed-off-by: Matthew Wilcox <mawil...@microsoft.com> --- include/linux/mm.h | 16 +++++----------- mm/page_alloc.c | 8 +++----- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 4ef7fb1726ab..06ea71358bda 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -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; } /* diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 796ce1b3e0a1..7a9c14214ed2 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -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); } /* -- 2.16.2