2023-09-15 11:08:52

by Matteo Rizzo

[permalink] [raw]
Subject: [RFC PATCH 06/14] mm/slub: pass additional args to alloc_slab_page

From: Jann Horn <[email protected]>

This is refactoring in preparation for SLAB_VIRTUAL.

The implementation of SLAB_VIRTUAL needs access to struct kmem_cache in
alloc_slab_page in order to take unused slabs from the slab freelist,
which is per-cache.

In addition to that it passes two different sets of GFP flags.
meta_gfp_flags is used for the memory backing the metadata region and
page tables, and gfp_flags for the data memory.

Signed-off-by: Jann Horn <[email protected]>
Co-developed-by: Matteo Rizzo <[email protected]>
Signed-off-by: Matteo Rizzo <[email protected]>
---
mm/slub.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 9b87afade125..eaa1256aff89 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1869,7 +1869,8 @@ static void folio_clear_slab(struct folio *folio, struct slab *slab)
__folio_clear_slab(folio);
}

-static inline struct slab *alloc_slab_page(gfp_t flags, int node,
+static inline struct slab *alloc_slab_page(struct kmem_cache *s,
+ gfp_t meta_flags, gfp_t flags, int node,
struct kmem_cache_order_objects oo)
{
struct folio *folio;
@@ -2020,7 +2021,7 @@ static struct slab *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
if ((alloc_gfp & __GFP_DIRECT_RECLAIM) && oo_order(oo) > oo_order(s->min))
alloc_gfp = (alloc_gfp | __GFP_NOMEMALLOC) & ~__GFP_RECLAIM;

- slab = alloc_slab_page(alloc_gfp, node, oo);
+ slab = alloc_slab_page(s, flags, alloc_gfp, node, oo);
if (unlikely(!slab)) {
oo = s->min;
alloc_gfp = flags;
@@ -2028,7 +2029,7 @@ static struct slab *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
* Allocation may have failed due to fragmentation.
* Try a lower order alloc if possible
*/
- slab = alloc_slab_page(alloc_gfp, node, oo);
+ slab = alloc_slab_page(s, flags, alloc_gfp, node, oo);
if (unlikely(!slab))
return NULL;
stat(s, ORDER_FALLBACK);
--
2.42.0.459.ge4e396fd5e-goog


2023-09-15 23:07:42

by Kees Cook

[permalink] [raw]
Subject: Re: [RFC PATCH 06/14] mm/slub: pass additional args to alloc_slab_page

On Fri, Sep 15, 2023 at 10:59:25AM +0000, Matteo Rizzo wrote:
> From: Jann Horn <[email protected]>
>
> This is refactoring in preparation for SLAB_VIRTUAL.
>
> The implementation of SLAB_VIRTUAL needs access to struct kmem_cache in
> alloc_slab_page in order to take unused slabs from the slab freelist,
> which is per-cache.
>
> In addition to that it passes two different sets of GFP flags.
> meta_gfp_flags is used for the memory backing the metadata region and
> page tables, and gfp_flags for the data memory.
>
> Signed-off-by: Jann Horn <[email protected]>

Reviewed-by: Kees Cook <[email protected]>

--
Kees Cook