lkml.org 
[lkml]   [2021]   [Sep]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH] mm: slub: merge get_freelist into ___slab_alloc
Date
get_freelist was introduced commit 213eeb9fd9d6 ("slub: Extract
get_freelist from __slab_alloc") and its comment says this function
transfers freelist to the per cpu freelist or deactivate page.

But what it actually does is just deactivating page and returning
its freelist. And the code working with variable 'new' is confusing
because it does nothing.

This function have been unmaintained for a long time and is confusing
reader. So simplify it for better readability.

Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
---
mm/slub.c | 46 +++++++++++-----------------------------------
1 file changed, 11 insertions(+), 35 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 3d2025f7163b..26fe1eb50d88 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2815,40 +2815,6 @@ static inline bool pfmemalloc_match_unsafe(struct page *page, gfp_t gfpflags)
return true;
}

-/*
- * Check the page->freelist of a page and either transfer the freelist to the
- * per cpu freelist or deactivate the page.
- *
- * The page is still frozen if the return value is not NULL.
- *
- * If this function returns NULL then the page has been unfrozen.
- */
-static inline void *get_freelist(struct kmem_cache *s, struct page *page)
-{
- struct page new;
- unsigned long counters;
- void *freelist;
-
- lockdep_assert_held(this_cpu_ptr(&s->cpu_slab->lock));
-
- do {
- freelist = page->freelist;
- counters = page->counters;
-
- new.counters = counters;
- VM_BUG_ON(!new.frozen);
-
- new.inuse = page->objects;
- new.frozen = freelist != NULL;
-
- } while (!__cmpxchg_double_slab(s, page,
- freelist, counters,
- NULL, new.counters,
- "get_freelist"));
-
- return freelist;
-}
-
/*
* Slow path. The lockless freelist is empty or we need to perform
* debugging duties.
@@ -2874,6 +2840,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
void *freelist;
struct page *page;
unsigned long flags;
+ unsigned long counters;

stat(s, ALLOC_SLOWPATH);

@@ -2920,12 +2887,21 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
local_unlock_irqrestore(&s->cpu_slab->lock, flags);
goto reread_page;
}
+
freelist = c->freelist;
if (freelist)
goto load_freelist;

- freelist = get_freelist(s, page);
+ /* deactivate page */
+ do {
+ freelist = page->freelist;
+ counters = page->counters;
+ } while (!__cmpxchg_double_slab(s, page,
+ freelist, counters,
+ NULL, counters,
+ "deactivate_page"));

+ /* there was no free objects in that page */
if (!freelist) {
c->page = NULL;
local_unlock_irqrestore(&s->cpu_slab->lock, flags);
--
2.27.0
\
 
 \ /
  Last update: 2021-09-18 09:17    [W:0.034 / U:0.216 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site