Skip to content

Commit 07588d7

Browse files
hygonitehcaster
authored andcommitted
mm/slab: cleanup slab_alloc() and slab_alloc_node()
Make slab_alloc_node() available even when CONFIG_NUMA=n and make slab_alloc() wrapper of slab_alloc_node(). This is necessary for further cleanup. Signed-off-by: Hyeonggon Yoo <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent c31a910 commit 07588d7

File tree

1 file changed

+13
-36
lines changed

1 file changed

+13
-36
lines changed

mm/slab.c

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,37 +3180,6 @@ 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-
3185-
static __always_inline void *
3186-
slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, size_t orig_size,
3187-
unsigned long caller)
3188-
{
3189-
unsigned long save_flags;
3190-
void *ptr;
3191-
struct obj_cgroup *objcg = NULL;
3192-
bool init = false;
3193-
3194-
flags &= gfp_allowed_mask;
3195-
cachep = slab_pre_alloc_hook(cachep, NULL, &objcg, 1, flags);
3196-
if (unlikely(!cachep))
3197-
return NULL;
3198-
3199-
ptr = kfence_alloc(cachep, orig_size, flags);
3200-
if (unlikely(ptr))
3201-
goto out_hooks;
3202-
3203-
local_irq_save(save_flags);
3204-
ptr = __do_cache_alloc(cachep, flags, nodeid);
3205-
local_irq_restore(save_flags);
3206-
ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
3207-
init = slab_want_init_on_alloc(flags, cachep);
3208-
3209-
out_hooks:
3210-
slab_post_alloc_hook(cachep, objcg, flags, 1, &ptr, init);
3211-
return ptr;
3212-
}
3213-
32143183
static __always_inline void *
32153184
__do_cache_alloc(struct kmem_cache *cachep, gfp_t flags, int nodeid)
32163185
{
@@ -3259,8 +3228,8 @@ __do_cache_alloc(struct kmem_cache *cachep, gfp_t flags, int nodeid __maybe_unus
32593228
#endif /* CONFIG_NUMA */
32603229

32613230
static __always_inline void *
3262-
slab_alloc(struct kmem_cache *cachep, struct list_lru *lru, gfp_t flags,
3263-
size_t orig_size, unsigned long caller)
3231+
slab_alloc_node(struct kmem_cache *cachep, struct list_lru *lru, gfp_t flags,
3232+
int nodeid, size_t orig_size, unsigned long caller)
32643233
{
32653234
unsigned long save_flags;
32663235
void *objp;
@@ -3277,7 +3246,7 @@ slab_alloc(struct kmem_cache *cachep, struct list_lru *lru, gfp_t flags,
32773246
goto out;
32783247

32793248
local_irq_save(save_flags);
3280-
objp = __do_cache_alloc(cachep, flags, NUMA_NO_NODE);
3249+
objp = __do_cache_alloc(cachep, flags, nodeid);
32813250
local_irq_restore(save_flags);
32823251
objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller);
32833252
prefetchw(objp);
@@ -3288,6 +3257,14 @@ slab_alloc(struct kmem_cache *cachep, struct list_lru *lru, gfp_t flags,
32883257
return objp;
32893258
}
32903259

3260+
static __always_inline void *
3261+
slab_alloc(struct kmem_cache *cachep, struct list_lru *lru, gfp_t flags,
3262+
size_t orig_size, unsigned long caller)
3263+
{
3264+
return slab_alloc_node(cachep, lru, flags, NUMA_NO_NODE, orig_size,
3265+
caller);
3266+
}
3267+
32913268
/*
32923269
* Caller needs to acquire correct kmem_cache_node's list_lock
32933270
* @list: List of detached free slabs should be freed by caller
@@ -3574,7 +3551,7 @@ EXPORT_SYMBOL(kmem_cache_alloc_trace);
35743551
*/
35753552
void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid)
35763553
{
3577-
void *ret = slab_alloc_node(cachep, flags, nodeid, cachep->object_size, _RET_IP_);
3554+
void *ret = slab_alloc_node(cachep, NULL, flags, nodeid, cachep->object_size, _RET_IP_);
35783555

35793556
trace_kmem_cache_alloc_node(_RET_IP_, ret, cachep,
35803557
cachep->object_size, cachep->size,
@@ -3592,7 +3569,7 @@ void *kmem_cache_alloc_node_trace(struct kmem_cache *cachep,
35923569
{
35933570
void *ret;
35943571

3595-
ret = slab_alloc_node(cachep, flags, nodeid, size, _RET_IP_);
3572+
ret = slab_alloc_node(cachep, NULL, flags, nodeid, size, _RET_IP_);
35963573

35973574
ret = kasan_kmalloc(cachep, ret, size, flags);
35983575
trace_kmalloc_node(_RET_IP_, ret, cachep,

0 commit comments

Comments
 (0)