Skip to content

Commit 865762a

Browse files
netoptimizertorvalds
authored andcommitted
slab/slub: adjust kmem_cache_alloc_bulk API
Adjust kmem_cache_alloc_bulk API before we have any real users. Adjust API to return type 'int' instead of previously type 'bool'. This is done to allow future extension of the bulk alloc API. A future extension could be to allow SLUB to stop at a page boundary, when specified by a flag, and then return the number of objects. The advantage of this approach, would make it easier to make bulk alloc run without local IRQs disabled. With an approach of cmpxchg "stealing" the entire c->freelist or page->freelist. To avoid overshooting we would stop processing at a slab-page boundary. Else we always end up returning some objects at the cost of another cmpxchg. To keep compatible with future users of this API linking against an older kernel when using the new flag, we need to return the number of allocated objects with this API change. Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Cc: Vladimir Davydov <vdavydov@virtuozzo.com> Acked-by: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: David Rientjes <rientjes@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0337451 commit 865762a

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

include/linux/slab.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ void kmem_cache_free(struct kmem_cache *, void *);
316316
* Note that interrupts must be enabled when calling these functions.
317317
*/
318318
void kmem_cache_free_bulk(struct kmem_cache *, size_t, void **);
319-
bool kmem_cache_alloc_bulk(struct kmem_cache *, gfp_t, size_t, void **);
319+
int kmem_cache_alloc_bulk(struct kmem_cache *, gfp_t, size_t, void **);
320320

321321
#ifdef CONFIG_NUMA
322322
void *__kmalloc_node(size_t size, gfp_t flags, int node) __assume_kmalloc_alignment;

mm/slab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3419,7 +3419,7 @@ void kmem_cache_free_bulk(struct kmem_cache *s, size_t size, void **p)
34193419
}
34203420
EXPORT_SYMBOL(kmem_cache_free_bulk);
34213421

3422-
bool kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
3422+
int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
34233423
void **p)
34243424
{
34253425
return __kmem_cache_alloc_bulk(s, flags, size, p);

mm/slab.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ ssize_t slabinfo_write(struct file *file, const char __user *buffer,
170170
* may be allocated or freed using these operations.
171171
*/
172172
void __kmem_cache_free_bulk(struct kmem_cache *, size_t, void **);
173-
bool __kmem_cache_alloc_bulk(struct kmem_cache *, gfp_t, size_t, void **);
173+
int __kmem_cache_alloc_bulk(struct kmem_cache *, gfp_t, size_t, void **);
174174

175175
#ifdef CONFIG_MEMCG_KMEM
176176
/*

mm/slab_common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void __kmem_cache_free_bulk(struct kmem_cache *s, size_t nr, void **p)
112112
kmem_cache_free(s, p[i]);
113113
}
114114

115-
bool __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t nr,
115+
int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t nr,
116116
void **p)
117117
{
118118
size_t i;
@@ -121,10 +121,10 @@ bool __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t nr,
121121
void *x = p[i] = kmem_cache_alloc(s, flags);
122122
if (!x) {
123123
__kmem_cache_free_bulk(s, i, p);
124-
return false;
124+
return 0;
125125
}
126126
}
127-
return true;
127+
return i;
128128
}
129129

130130
#ifdef CONFIG_MEMCG_KMEM

mm/slob.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ void kmem_cache_free_bulk(struct kmem_cache *s, size_t size, void **p)
617617
}
618618
EXPORT_SYMBOL(kmem_cache_free_bulk);
619619

620-
bool kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
620+
int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
621621
void **p)
622622
{
623623
return __kmem_cache_alloc_bulk(s, flags, size, p);

mm/slub.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,8 +2909,8 @@ void kmem_cache_free_bulk(struct kmem_cache *orig_s, size_t size, void **p)
29092909
EXPORT_SYMBOL(kmem_cache_free_bulk);
29102910

29112911
/* Note that interrupts must be enabled when calling this function. */
2912-
bool kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
2913-
void **p)
2912+
int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
2913+
void **p)
29142914
{
29152915
struct kmem_cache_cpu *c;
29162916
int i;
@@ -2959,12 +2959,12 @@ bool kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
29592959

29602960
/* memcg and kmem_cache debug support */
29612961
slab_post_alloc_hook(s, flags, size, p);
2962-
return true;
2962+
return i;
29632963
error:
29642964
local_irq_enable();
29652965
slab_post_alloc_hook(s, flags, i, p);
29662966
__kmem_cache_free_bulk(s, i, p);
2967-
return false;
2967+
return 0;
29682968
}
29692969
EXPORT_SYMBOL(kmem_cache_alloc_bulk);
29702970

0 commit comments

Comments
 (0)