From: Liam R. Howlett <Liam.Howlett@Oracle.com>
Date: Wed, 4 Dec 2024 20:23:35 +0000 (-0500)
Subject: mm/slub: Add misc sheaf functions
X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=485642013796bb1c0eb329aa4631b26b63897098;p=users%2Fjedix%2Flinux-maple.git

mm/slub: Add misc sheaf functions

One was needed for the size of the sheaf, one for refilling the sheaf.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---

diff --git a/include/linux/slab.h b/include/linux/slab.h
index a87dc3c6392f..184e00a7ca53 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -823,6 +823,9 @@ void *kmem_cache_alloc_node_noprof(struct kmem_cache *s, gfp_t flags,
 struct slab_sheaf *
 kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int count);
 
+void kmem_cache_refill_sheaf(struct kmem_cache *s, gfp_t gfp,
+		 struct slab_sheaf *sheaf, unsigned long count);
+
 void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp,
 				       struct slab_sheaf *sheaf);
 
@@ -831,6 +834,8 @@ void *kmem_cache_alloc_from_sheaf_noprof(struct kmem_cache *cachep, gfp_t gfp,
 #define kmem_cache_alloc_from_sheaf(...)	\
 			alloc_hooks(kmem_cache_alloc_from_sheaf_noprof(__VA_ARGS__))
 
+unsigned int kmem_cache_sheaf_count(struct slab_sheaf *sheaf);
+
 /*
  * These macros allow declaring a kmem_buckets * parameter alongside size, which
  * can be compiled out with CONFIG_SLAB_BUCKETS=n so that a large number of call
diff --git a/mm/slub.c b/mm/slub.c
index a0e2cb7dfb51..42642c8d88d0 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4962,6 +4962,23 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int count)
 	return sheaf;
 }
 
+void kmem_cache_refill_sheaf(struct kmem_cache *s, gfp_t gfp,
+		 struct slab_sheaf *sheaf, unsigned long count)
+{
+	struct slub_percpu_sheaves *pcs;
+
+	if (!sheaf)
+		return;
+
+	//TODO: handle via oversize sheaf
+	if (count + sheaf->size > s->sheaf_capacity)
+		return;
+
+	//TODO: handle failures
+	refill_sheaf(s, sheaf, gfp);
+	sheaf->size += count;
+}
+
 /*
  * Use this to return a sheaf obtained by kmem_cache_prefill_sheaf()
  * It tries to refill the sheaf back to the cache's sheaf_capacity
@@ -5042,6 +5059,10 @@ out:
 	return ret;
 }
 
+unsigned int kmem_cache_sheaf_count(struct slab_sheaf *sheaf)
+{
+	return sheaf->size;
+}
 /*
  * To avoid unnecessary overhead, we pass through large allocation requests
  * directly to the page allocator. We use __GFP_COMP, because we will need to