From: Harry Yoo <harry.yoo@oracle.com>
To: Vlastimil Babka <vbabka@suse.cz>,
Christoph Lameter <cl@gentwo.org>,
David Rientjes <rientjes@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>,
Mateusz Guzik <mjguzik@gmail.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>,
Cong Wang <xiyou.wangcong@gmail.com>,
Jiri Pirko <jiri@resnulli.us>, Vlad Buslov <vladbu@nvidia.com>,
Yevgeny Kliteynik <kliteyn@nvidia.com>, Jan Kara <jack@suse.cz>,
Byungchul Park <byungchul@sk.com>,
linux-mm@kvack.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, Harry Yoo <harry.yoo@oracle.com>
Subject: [RFC PATCH 1/7] mm/slab: refactor freelist shuffle
Date: Thu, 24 Apr 2025 17:07:49 +0900 [thread overview]
Message-ID: <20250424080755.272925-2-harry.yoo@oracle.com> (raw)
In-Reply-To: <20250424080755.272925-1-harry.yoo@oracle.com>
shuffle_freelist() function returns false when 1) it can't shuffle
the freelist due to lack of a random sequence or,
2) when there is a single object.
In a later patch, I'd like to return an error in shuffle_freelist() when
setup_object() fails. But with current code, it'll be hard to determine
whether it should initialize the objects anyway or let allocate_slab()
return an error.
To address this, decouple the shuffle eligibility checks into
should_shuffle_freelist() function and call it before shuffle_freelist().
Change the return type of shuffle_freelist() to void for now.
Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
---
mm/slub.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index dac149df1be1..95a9f04b5904 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2534,17 +2534,21 @@ static void *next_freelist_entry(struct kmem_cache *s,
return (char *)start + idx;
}
+static bool should_shuffle_freelist(struct kmem_cache *s, struct slab *slab)
+{
+ if (slab->objects < 2 || !s->random_seq)
+ return false;
+ return true;
+}
+
/* Shuffle the single linked freelist based on a random pre-computed sequence */
-static bool shuffle_freelist(struct kmem_cache *s, struct slab *slab)
+static void shuffle_freelist(struct kmem_cache *s, struct slab *slab)
{
void *start;
void *cur;
void *next;
unsigned long idx, pos, page_limit, freelist_count;
- if (slab->objects < 2 || !s->random_seq)
- return false;
-
freelist_count = oo_objects(s->oo);
pos = get_random_u32_below(freelist_count);
@@ -2564,8 +2568,6 @@ static bool shuffle_freelist(struct kmem_cache *s, struct slab *slab)
cur = next;
}
set_freepointer(s, cur, NULL);
-
- return true;
}
#else
static inline int init_cache_random_seq(struct kmem_cache *s)
@@ -2573,10 +2575,13 @@ static inline int init_cache_random_seq(struct kmem_cache *s)
return 0;
}
static inline void init_freelist_randomization(void) { }
-static inline bool shuffle_freelist(struct kmem_cache *s, struct slab *slab)
+static inline bool should_shuffle_freelist(struct kmem_cache *s,
+ struct slab *slab)
{
return false;
}
+static inline void shuffle_freelist(struct kmem_cache *s, struct slab *slab)
+{ }
#endif /* CONFIG_SLAB_FREELIST_RANDOM */
static __always_inline void account_slab(struct slab *slab, int order,
@@ -2606,7 +2611,6 @@ static struct slab *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
gfp_t alloc_gfp;
void *start, *p, *next;
int idx;
- bool shuffle;
flags &= gfp_allowed_mask;
@@ -2648,9 +2652,9 @@ static struct slab *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
setup_slab_debug(s, slab, start);
- shuffle = shuffle_freelist(s, slab);
-
- if (!shuffle) {
+ if (should_shuffle_freelist(s, slab)) {
+ shuffle_freelist(s, slab);
+ } else {
start = fixup_red_left(s, start);
start = setup_object(s, start);
slab->freelist = start;
--
2.43.0
next prev parent reply other threads:[~2025-04-24 8:18 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-24 8:07 [RFC PATCH 0/7] Reviving the slab destructor to tackle the percpu allocator scalability problem Harry Yoo
2025-04-24 8:07 ` Harry Yoo [this message]
2025-04-24 8:07 ` [RFC PATCH 2/7] treewide, slab: allow slab constructor to return an error Harry Yoo
2025-04-24 8:07 ` [RFC PATCH 3/7] mm/slab: revive the destructor feature in slab allocator Harry Yoo
2025-04-24 8:07 ` [RFC PATCH 4/7] net/sched/act_api: use slab ctor/dtor to reduce contention on pcpu alloc Harry Yoo
2025-04-24 8:07 ` [RFC PATCH 5/7] mm/percpu: allow (un)charging objects without alloc/free Harry Yoo
2025-04-24 8:07 ` [RFC PATCH 6/7] lib/percpu_counter: allow (un)charging percpu counters " Harry Yoo
2025-04-24 8:07 ` [RFC PATCH 7/7] kernel/fork: improve exec() throughput with slab ctor/dtor pair Harry Yoo
2025-04-24 9:29 ` [RFC PATCH 0/7] Reviving the slab destructor to tackle the percpu allocator scalability problem Mateusz Guzik
2025-04-24 9:58 ` Harry Yoo
2025-04-24 15:00 ` Mateusz Guzik
2025-04-24 11:28 ` Pedro Falcato
2025-04-24 15:20 ` Mateusz Guzik
2025-04-24 16:11 ` Mateusz Guzik
2025-04-25 7:40 ` Harry Yoo
2025-04-25 10:12 ` Harry Yoo
2025-04-25 10:42 ` Pedro Falcato
2025-04-28 1:18 ` Harry Yoo
2025-04-30 19:49 ` Mateusz Guzik
2025-05-12 11:00 ` Harry Yoo
2025-04-24 15:50 ` Christoph Lameter (Ampere)
2025-04-24 16:03 ` Mateusz Guzik
2025-04-24 16:39 ` Christoph Lameter (Ampere)
2025-04-24 17:26 ` Mateusz Guzik
2025-04-24 18:47 ` Tejun Heo
2025-04-25 10:10 ` Harry Yoo
2025-04-25 19:03 ` Tejun Heo
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=20250424080755.272925-2-harry.yoo@oracle.com \
--to=harry.yoo@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=byungchul@sk.com \
--cc=cl@gentwo.org \
--cc=dennis@kernel.org \
--cc=jack@suse.cz \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kliteyn@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mjguzik@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=rientjes@google.com \
--cc=tj@kernel.org \
--cc=vbabka@suse.cz \
--cc=vladbu@nvidia.com \
--cc=xiyou.wangcong@gmail.com \
/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
all inboxes | Powered by JetHome®