linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Matthew Wilcox <willy@infradead.org>,
	linux-mm@kvack.org, Christoph Lameter <cl@linux.com>,
	David Rientjes <rientjes@google.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Pekka Enberg <penberg@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Subject: [RFC PATCH 18/32] mm/slab: Convert kmem_getpages() and kmem_freepages() to struct slab
Date: Tue, 16 Nov 2021 01:16:14 +0100	[thread overview]
Message-ID: <20211116001628.24216-19-vbabka@suse.cz> (raw)
In-Reply-To: <20211116001628.24216-1-vbabka@suse.cz>

These functions sit at the boundary to page allocator. Also use folio
internally to avoid extra compound_head() when dealing with page flags.

Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
---
 mm/slab.c | 52 ++++++++++++++++++++++++++++------------------------
 1 file changed, 28 insertions(+), 24 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index 2a62fb1612ba..975f79cf7de9 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -1367,57 +1367,61 @@ slab_out_of_memory(struct kmem_cache *cachep, gfp_t gfpflags, int nodeid)
  * did not request dmaable memory, we might get it, but that
  * would be relatively rare and ignorable.
  */
-static struct page *kmem_getpages(struct kmem_cache *cachep, gfp_t flags,
+static struct slab *kmem_getpages(struct kmem_cache *cachep, gfp_t flags,
 								int nodeid)
 {
-	struct page *page;
+	struct folio *folio;
+	struct slab *slab;
 
 	flags |= cachep->allocflags;
 
-	page = __alloc_pages_node(nodeid, flags, cachep->gfporder);
-	if (!page) {
+	folio = (struct folio *) __alloc_pages_node(nodeid, flags, cachep->gfporder);
+	if (!folio) {
 		slab_out_of_memory(cachep, flags, nodeid);
 		return NULL;
 	}
 
-	account_slab(page_slab(page), cachep->gfporder, cachep, flags);
-	__SetPageSlab(page);
+	slab = folio_slab(folio);
+
+	account_slab(slab, cachep->gfporder, cachep, flags);
+	__folio_set_slab(folio);
 	/* Record if ALLOC_NO_WATERMARKS was set when allocating the slab */
-	if (sk_memalloc_socks() && page_is_pfmemalloc(page))
-		SetPageSlabPfmemalloc(page);
+	if (sk_memalloc_socks() && page_is_pfmemalloc(folio_page(folio, 0)))
+		slab_set_pfmemalloc(slab);
 
-	return page;
+	return slab;
 }
 
 /*
  * Interface to system's page release.
  */
-static void kmem_freepages(struct kmem_cache *cachep, struct page *page)
+static void kmem_freepages(struct kmem_cache *cachep, struct slab *slab)
 {
 	int order = cachep->gfporder;
+	struct folio *folio = slab_folio(slab);
 
-	BUG_ON(!PageSlab(page));
-	__ClearPageSlabPfmemalloc(page);
-	__ClearPageSlab(page);
-	page_mapcount_reset(page);
+	BUG_ON(!folio_test_slab(folio));
+	__slab_clear_pfmemalloc(slab);
+	__folio_clear_slab(folio);
+	page_mapcount_reset(folio_page(folio, 0));
 	/* In union with page->mapping where page allocator expects NULL */
-	page->slab_cache = NULL;
+	slab->slab_cache = NULL;
 
 	if (current->reclaim_state)
 		current->reclaim_state->reclaimed_slab += 1 << order;
-	unaccount_slab(page_slab(page), order, cachep);
-	__free_pages(page, order);
+	unaccount_slab(slab, order, cachep);
+	__free_pages(folio_page(folio, 0), order);
 }
 
 static void kmem_rcu_free(struct rcu_head *head)
 {
 	struct kmem_cache *cachep;
-	struct page *page;
+	struct slab *slab;
 
-	page = container_of(head, struct page, rcu_head);
-	cachep = page->slab_cache;
+	slab = container_of(head, struct slab, rcu_head);
+	cachep = slab->slab_cache;
 
-	kmem_freepages(cachep, page);
+	kmem_freepages(cachep, slab);
 }
 
 #if DEBUG
@@ -1624,7 +1628,7 @@ static void slab_destroy(struct kmem_cache *cachep, struct page *page)
 	if (unlikely(cachep->flags & SLAB_TYPESAFE_BY_RCU))
 		call_rcu(&page->rcu_head, kmem_rcu_free);
 	else
-		kmem_freepages(cachep, page);
+		kmem_freepages(cachep, page_slab(page));
 
 	/*
 	 * From now on, we don't use freelist
@@ -2578,7 +2582,7 @@ static struct page *cache_grow_begin(struct kmem_cache *cachep,
 	 * Get mem for the objs.  Attempt to allocate a physical page from
 	 * 'nodeid'.
 	 */
-	page = kmem_getpages(cachep, local_flags, nodeid);
+	page = slab_page(kmem_getpages(cachep, local_flags, nodeid));
 	if (!page)
 		goto failed;
 
@@ -2620,7 +2624,7 @@ static struct page *cache_grow_begin(struct kmem_cache *cachep,
 	return page;
 
 opps1:
-	kmem_freepages(cachep, page);
+	kmem_freepages(cachep, page_slab(page));
 failed:
 	if (gfpflags_allow_blocking(local_flags))
 		local_irq_disable();
-- 
2.33.1



  parent reply	other threads:[~2021-11-16  0:17 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16  0:15 [RFC PATCH 00/32] Separate struct slab from struct page Vlastimil Babka
2021-11-16  0:15 ` [RFC PATCH 01/32] mm/slab: Dissolve slab_map_pages() in its caller Vlastimil Babka
2021-11-16  0:15 ` [RFC PATCH 02/32] mm/slub: Make object_err() static Vlastimil Babka
2021-11-16  0:15 ` [RFC PATCH 03/32] mm: Split slab into its own type Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 04/32] mm: Add account_slab() and unaccount_slab() Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 05/32] mm: Convert virt_to_cache() to use struct slab Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 06/32] mm: Convert __ksize() to " Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 07/32] mm: Use struct slab in kmem_obj_info() Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 08/32] mm: Convert check_heap_object() to use struct slab Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 09/32] mm/slub: Convert detached_freelist to use a " Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 10/32] mm/slub: Convert kfree() " Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 11/32] mm/slub: Convert __slab_lock() and __slab_unlock() to " Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 12/32] mm/slub: Convert print_page_info() to print_slab_info() Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 13/32] mm/slub: Convert alloc_slab_page() to return a struct slab Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 14/32] mm/slub: Convert __free_slab() to use " Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 15/32] mm/slub: Convert pfmemalloc_match() to take a " Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 16/32] mm/slub: Convert most struct page to struct slab by spatch Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 17/32] mm/slub: Finish struct page to struct slab conversion Vlastimil Babka
2021-11-16  0:16 ` Vlastimil Babka [this message]
2021-11-16  0:16 ` [RFC PATCH 19/32] mm/slab: Convert most struct page to struct slab by spatch Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 20/32] mm/slab: Finish struct page to struct slab conversion Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 21/32] mm: Convert struct page to struct slab in functions used by other subsystems Vlastimil Babka
2021-11-16 14:02   ` Andrey Konovalov
2021-11-16 16:32     ` Vlastimil Babka
2021-11-16 23:04       ` Andrey Konovalov
2021-11-16 23:37         ` Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 22/32] mm/memcg: Convert slab objcgs from struct page to struct slab Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 23/32] mm/slob: Convert SLOB to use " Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 24/32] mm/kasan: Convert to " Vlastimil Babka
2021-11-16 13:58   ` Andrey Konovalov
2021-11-16 18:17   ` Matthew Wilcox
2021-11-16  0:16 ` [RFC PATCH 25/32] mm/kfence: Convert kfence_guarded_alloc() " Vlastimil Babka
2021-11-17  7:00   ` Marco Elver
2021-11-16  0:16 ` [RFC PATCH 26/32] zsmalloc: Stop using slab fields in struct page Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 27/32] bootmem: Use page->index instead of page->freelist Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 28/32] iommu: Use put_pages_list Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 29/32] mm: Remove slab from struct page Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 30/32] mm/sl*b: Differentiate struct slab fields by sl*b implementations Vlastimil Babka
2021-11-17  7:00   ` Marco Elver
2021-11-16  0:16 ` [RFC PATCH 31/32] mm/slub: Simplify struct slab slabs field definition Vlastimil Babka
2021-11-16  0:16 ` [RFC PATCH 32/32] mm/slub: Define struct slab fields for CONFIG_SLUB_CPU_PARTIAL only when enabled Vlastimil Babka

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=20211116001628.24216-19-vbabka@suse.cz \
    --to=vbabka@suse.cz \
    --cc=cl@linux.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=willy@infradead.org \
    /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