mm: introduce folio_is_pfmemalloc
authorSidhartha Kumar <sidhartha.kumar@oracle.com>
Fri, 6 Jan 2023 21:52:51 +0000 (15:52 -0600)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 19 Jan 2023 01:12:57 +0000 (17:12 -0800)
Add a folio equivalent for page_is_pfmemalloc. This removes two instances
of page_is_pfmemalloc(folio_page(folio, 0)) so the folio can be used
directly.

Link: https://lkml.kernel.org/r/20230106215251.599222-1-sidhartha.kumar@oracle.com
Suggested-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: SeongJae Park <sj@kernel.org>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/mm.h
mm/slab.c
mm/slub.c

index 8a856335994625275f35e2d73c45d8993bde6882..76c97cb8ee9aed6bd25d61f91ae03478c6b3d2c1 100644 (file)
@@ -1926,6 +1926,21 @@ static inline bool page_is_pfmemalloc(const struct page *page)
        return (uintptr_t)page->lru.next & BIT(1);
 }
 
+/*
+ * Return true only if the folio has been allocated with
+ * ALLOC_NO_WATERMARKS and the low watermark was not
+ * met implying that the system is under some pressure.
+ */
+static inline bool folio_is_pfmemalloc(const struct folio *folio)
+{
+       /*
+        * lru.next has bit 1 set if the page is allocated from the
+        * pfmemalloc reserves.  Callers may simply overwrite it if
+        * they do not need to preserve that information.
+        */
+       return (uintptr_t)folio->lru.next & BIT(1);
+}
+
 /*
  * Only to be called by the page allocator on a freshly allocated
  * page.
index 7a269db050eed88b5273d2c3820ff8e453de518b..b77be9c6d6b1b3daec2192e4027b0055a937de58 100644 (file)
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -1373,7 +1373,7 @@ static struct slab *kmem_getpages(struct kmem_cache *cachep, gfp_t flags,
        /* Make the flag visible before any changes to folio->mapping */
        smp_wmb();
        /* Record if ALLOC_NO_WATERMARKS was set when allocating the slab */
-       if (sk_memalloc_socks() && page_is_pfmemalloc(folio_page(folio, 0)))
+       if (sk_memalloc_socks() && folio_is_pfmemalloc(folio))
                slab_set_pfmemalloc(slab);
 
        return slab;
index 13459c69095a25b6a1db8e24472654dca3b9d0d0..67020074ecb4040f4e072e0d9bfadf446e751720 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1859,7 +1859,7 @@ static inline struct slab *alloc_slab_page(gfp_t flags, int node,
        __folio_set_slab(folio);
        /* Make the flag visible before any changes to folio->mapping */
        smp_wmb();
-       if (page_is_pfmemalloc(folio_page(folio, 0)))
+       if (folio_is_pfmemalloc(folio))
                slab_set_pfmemalloc(slab);
 
        return slab;