linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-mm@kvack.org, Johannes Weiner <hannes@cmpxchg.org>,
	Vlastimil Babka <vbabka@suse.cz>
Subject: [PATCH 2/4] slab: Convert __kmalloc_large_node() and free_large_kmalloc() to use folios
Date: Fri, 22 Dec 2023 20:28:05 +0000	[thread overview]
Message-ID: <20231222202807.2135717-3-willy@infradead.org> (raw)
In-Reply-To: <20231222202807.2135717-1-willy@infradead.org>

Add folio_alloc_node() to replace alloc_pages_node() and then use
folio APIs throughout instead of converting back to pages.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/gfp.h |  9 +++++++++
 mm/slub.c           | 15 +++++++--------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index de292a007138..d56c1d7b5c5a 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -247,6 +247,15 @@ struct folio *__folio_alloc_node(gfp_t gfp, unsigned int order, int nid)
 	return __folio_alloc(gfp, order, nid, NULL);
 }
 
+static inline
+struct folio *folio_alloc_node(gfp_t gfp, unsigned int order, int nid)
+{
+	if (nid == NUMA_NO_NODE)
+		nid = numa_mem_id();
+
+	return __folio_alloc_node(gfp, order, nid);
+}
+
 /*
  * Allocate pages, preferring the node given as nid. When nid == NUMA_NO_NODE,
  * prefer the current CPU's closest node. Otherwise node must be valid and
diff --git a/mm/slub.c b/mm/slub.c
index 35aa706dc318..261f01915d9b 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3919,18 +3919,17 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
  */
 static void *__kmalloc_large_node(size_t size, gfp_t flags, int node)
 {
-	struct page *page;
+	struct folio *folio;
 	void *ptr = NULL;
 	unsigned int order = get_order(size);
 
 	if (unlikely(flags & GFP_SLAB_BUG_MASK))
 		flags = kmalloc_fix_flags(flags);
 
-	flags |= __GFP_COMP;
-	page = alloc_pages_node(node, flags, order);
-	if (page) {
-		ptr = page_address(page);
-		mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B,
+	folio = folio_alloc_node(flags, order, node);
+	if (folio) {
+		ptr = folio_address(folio);
+		lruvec_stat_mod_folio(folio, NR_SLAB_UNRECLAIMABLE_B,
 				      PAGE_SIZE << order);
 	}
 
@@ -4379,9 +4378,9 @@ static void free_large_kmalloc(struct folio *folio, void *object)
 	kasan_kfree_large(object);
 	kmsan_kfree_large(object);
 
-	mod_lruvec_page_state(folio_page(folio, 0), NR_SLAB_UNRECLAIMABLE_B,
+	lruvec_stat_mod_folio(folio, NR_SLAB_UNRECLAIMABLE_B,
 			      -(PAGE_SIZE << order));
-	__free_pages(folio_page(folio, 0), order);
+	folio_put(folio);
 }
 
 /**
-- 
2.43.0



  parent reply	other threads:[~2023-12-22 20:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-22 20:28 [PATCH 0/4] Remove some lruvec page accounting functions Matthew Wilcox (Oracle)
2023-12-22 20:28 ` [PATCH 1/4] mm: Remove inc/dec lruvec page state functions Matthew Wilcox (Oracle)
2023-12-22 20:28 ` Matthew Wilcox (Oracle) [this message]
2023-12-22 23:11   ` [PATCH 2/4] slab: Convert __kmalloc_large_node() and free_large_kmalloc() to use folios Hyeonggon Yoo
2023-12-22 23:13     ` Matthew Wilcox
2023-12-23  6:09     ` Matthew Wilcox
2023-12-27 22:01   ` Andrew Morton
2023-12-28  4:15     ` Hyeonggon Yoo
2024-01-02 15:58     ` Vlastimil Babka
2023-12-22 20:28 ` [PATCH 3/4] mm/khugepaged: Use a folio more in collapse_file() Matthew Wilcox (Oracle)
2023-12-22 20:28 ` [PATCH 4/4] mm/memcontrol: Remove __mod_lruvec_page_state() Matthew Wilcox (Oracle)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231222202807.2135717-3-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-mm@kvack.org \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox