From: Hyeonggon Yoo <42.hyeyoo@gmail.com>
To: 42.hyeyoo@gmail.com
Cc: Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@suse.cz>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH] mm: slub: merge get_freelist into ___slab_alloc
Date: Sat, 18 Sep 2021 07:15:51 +0000 [thread overview]
Message-ID: <20210918071552.53171-1-42.hyeyoo@gmail.com> (raw)
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
next reply other threads:[~2021-09-18 7:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-18 7:15 Hyeonggon Yoo [this message]
2021-09-18 7:41 ` Sorry for annoyance. it's buggy Hyeonggon Yoo
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=20210918071552.53171-1-42.hyeyoo@gmail.com \
--to=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--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