Skip to content

Commit c31a910

Browse files
hygonitehcaster
authored andcommitted
mm/slab: move NUMA-related code to __do_cache_alloc()
To implement slab_alloc_node() independent of NUMA configuration, move NUMA fallback/alternate allocation code into __do_cache_alloc(). One functional change here is not to check availability of node when allocating from local node. Signed-off-by: Hyeonggon Yoo <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 1c23f9e commit c31a910

File tree

1 file changed

+31
-37
lines changed

1 file changed

+31
-37
lines changed

mm/slab.c

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,13 +3180,14 @@ static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags,
31803180
return obj ? obj : fallback_alloc(cachep, flags);
31813181
}
31823182

3183+
static void *__do_cache_alloc(struct kmem_cache *cachep, gfp_t flags, int nodeid);
3184+
31833185
static __always_inline void *
31843186
slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, size_t orig_size,
31853187
unsigned long caller)
31863188
{
31873189
unsigned long save_flags;
31883190
void *ptr;
3189-
int slab_node = numa_mem_id();
31903191
struct obj_cgroup *objcg = NULL;
31913192
bool init = false;
31923193

@@ -3200,30 +3201,7 @@ slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, size_t orig_
32003201
goto out_hooks;
32013202

32023203
local_irq_save(save_flags);
3203-
3204-
if (nodeid == NUMA_NO_NODE)
3205-
nodeid = slab_node;
3206-
3207-
if (unlikely(!get_node(cachep, nodeid))) {
3208-
/* Node not bootstrapped yet */
3209-
ptr = fallback_alloc(cachep, flags);
3210-
goto out;
3211-
}
3212-
3213-
if (nodeid == slab_node) {
3214-
/*
3215-
* Use the locally cached objects if possible.
3216-
* However ____cache_alloc does not allow fallback
3217-
* to other nodes. It may fail while we still have
3218-
* objects on other nodes available.
3219-
*/
3220-
ptr = ____cache_alloc(cachep, flags);
3221-
if (ptr)
3222-
goto out;
3223-
}
3224-
/* ___cache_alloc_node can fall back to other nodes */
3225-
ptr = ____cache_alloc_node(cachep, flags, nodeid);
3226-
out:
3204+
ptr = __do_cache_alloc(cachep, flags, nodeid);
32273205
local_irq_restore(save_flags);
32283206
ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
32293207
init = slab_want_init_on_alloc(flags, cachep);
@@ -3234,31 +3212,46 @@ slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, size_t orig_
32343212
}
32353213

32363214
static __always_inline void *
3237-
__do_cache_alloc(struct kmem_cache *cache, gfp_t flags)
3215+
__do_cache_alloc(struct kmem_cache *cachep, gfp_t flags, int nodeid)
32383216
{
3239-
void *objp;
3217+
void *objp = NULL;
3218+
int slab_node = numa_mem_id();
32403219

3241-
if (current->mempolicy || cpuset_do_slab_mem_spread()) {
3242-
objp = alternate_node_alloc(cache, flags);
3243-
if (objp)
3244-
goto out;
3220+
if (nodeid == NUMA_NO_NODE) {
3221+
if (current->mempolicy || cpuset_do_slab_mem_spread()) {
3222+
objp = alternate_node_alloc(cachep, flags);
3223+
if (objp)
3224+
goto out;
3225+
}
3226+
/*
3227+
* Use the locally cached objects if possible.
3228+
* However ____cache_alloc does not allow fallback
3229+
* to other nodes. It may fail while we still have
3230+
* objects on other nodes available.
3231+
*/
3232+
objp = ____cache_alloc(cachep, flags);
3233+
nodeid = slab_node;
3234+
} else if (nodeid == slab_node) {
3235+
objp = ____cache_alloc(cachep, flags);
3236+
} else if (!get_node(cachep, nodeid)) {
3237+
/* Node not bootstrapped yet */
3238+
objp = fallback_alloc(cachep, flags);
3239+
goto out;
32453240
}
3246-
objp = ____cache_alloc(cache, flags);
32473241

32483242
/*
32493243
* We may just have run out of memory on the local node.
32503244
* ____cache_alloc_node() knows how to locate memory on other nodes
32513245
*/
32523246
if (!objp)
3253-
objp = ____cache_alloc_node(cache, flags, numa_mem_id());
3254-
3247+
objp = ____cache_alloc_node(cachep, flags, nodeid);
32553248
out:
32563249
return objp;
32573250
}
32583251
#else
32593252

32603253
static __always_inline void *
3261-
__do_cache_alloc(struct kmem_cache *cachep, gfp_t flags)
3254+
__do_cache_alloc(struct kmem_cache *cachep, gfp_t flags, int nodeid __maybe_unused)
32623255
{
32633256
return ____cache_alloc(cachep, flags);
32643257
}
@@ -3284,7 +3277,7 @@ slab_alloc(struct kmem_cache *cachep, struct list_lru *lru, gfp_t flags,
32843277
goto out;
32853278

32863279
local_irq_save(save_flags);
3287-
objp = __do_cache_alloc(cachep, flags);
3280+
objp = __do_cache_alloc(cachep, flags, NUMA_NO_NODE);
32883281
local_irq_restore(save_flags);
32893282
objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller);
32903283
prefetchw(objp);
@@ -3521,7 +3514,8 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
35213514

35223515
local_irq_disable();
35233516
for (i = 0; i < size; i++) {
3524-
void *objp = kfence_alloc(s, s->object_size, flags) ?: __do_cache_alloc(s, flags);
3517+
void *objp = kfence_alloc(s, s->object_size, flags) ?:
3518+
__do_cache_alloc(s, flags, NUMA_NO_NODE);
35253519

35263520
if (unlikely(!objp))
35273521
goto error;

0 commit comments

Comments
 (0)