slab/slub: adjust kmem_cache_alloc_bulk API
Subsystems (2)
PATCH 1/1 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 extention of the bulk alloc API.
A future extention could be to allow SLUB to stop at a page boundry, 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 boundry. 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.
---
$ bloat-o-meter vmlinux.with_bool_api vmlinux.with_int_api add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-15 (-15) function old new delta __kmem_cache_alloc_bulk 129 124 -5 kmem_cache_alloc_bulk 283 273 -10
include/linux/slab.h | 2 +- mm/slab.c | 8 ++++---- mm/slab.h | 2 +- mm/slab_common.c | 6 +++--- mm/slob.c | 2 +- mm/slub.c | 8 ++++---- 6 files changed, 14 insertions(+), 14 deletions(-)
include/linux/slab.h +1 -1
@@ -316,7 +316,7 @@ void kmem_cache_free(struct kmem_cache *, void *);* Note that interrupts must be enabled when calling these functions. */ void kmem_cache_free_bulk (struct kmem_cache *,size_t ,void **); -bool kmem_cache_alloc_bulk (struct kmem_cache *,gfp_t ,size_t ,void **); +int kmem_cache_alloc_bulk (struct kmem_cache *,gfp_t ,size_t ,void **);#ifdef CONFIG_NUMA void *__kmalloc_node (size_t size,gfp_t flags,int node) __assume_kmalloc_alignment;
mm/slab.c +4 -4
@@ -3419,8 +3419,8 @@ void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags)EXPORT_SYMBOL (kmem_cache_alloc);/* Note that interrupts must be enabled when calling this function. */ -bool kmem_cache_alloc_bulk (struct kmem_cache *s,gfp_t flags,size_t size, -void **p) +int kmem_cache_alloc_bulk (struct kmem_cache *s,gfp_t flags,size_t size, +void **p) {size_t i;
@@ -3430,11 +3430,11 @@ bool kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,if (!x) {__kmem_cache_free_bulk (s, i, p); -return false; +return 0 ; } }local_irq_enable (); -return true; +return i; }EXPORT_SYMBOL (kmem_cache_alloc_bulk);
mm/slab.h +1 -1
@@ -170,7 +170,7 @@ ssize_t slabinfo_write(struct file *file, const char __user *buffer,* may be allocated or freed using these operations. */ void __kmem_cache_free_bulk (struct kmem_cache *,size_t ,void **); -bool __kmem_cache_alloc_bulk (struct kmem_cache *,gfp_t ,size_t ,void **); +int __kmem_cache_alloc_bulk (struct kmem_cache *,gfp_t ,size_t ,void **);#ifdef CONFIG_MEMCG_KMEM /*
mm/slab_common.c +3 -3
@@ -112,7 +112,7 @@ void __kmem_cache_free_bulk(struct kmem_cache *s, size_t nr, void **p)kmem_cache_free (s, p[i]); } -bool __kmem_cache_alloc_bulk (struct kmem_cache *s,gfp_t flags,size_t nr, +int __kmem_cache_alloc_bulk (struct kmem_cache *s,gfp_t flags,size_t nr,void **p) {size_t i;
@@ -121,10 +121,10 @@ bool __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t nr,void *x = p[i] =kmem_cache_alloc (s, flags);if (!x) {__kmem_cache_free_bulk (s, i, p); -return false; +return 0 ; } } -return true; +return i; }#ifdef CONFIG_MEMCG_KMEM
mm/slob.c +1 -1
@@ -617,7 +617,7 @@ void kmem_cache_free_bulk(struct kmem_cache *s, size_t size, void **p) }EXPORT_SYMBOL (kmem_cache_free_bulk); -bool kmem_cache_alloc_bulk (struct kmem_cache *s,gfp_t flags,size_t size, +int kmem_cache_alloc_bulk (struct kmem_cache *s,gfp_t flags,size_t size,void **p) {return __kmem_cache_alloc_bulk (s, flags, size, p);
mm/slub.c +4 -4
@@ -2911,8 +2911,8 @@ void kmem_cache_free_bulk(struct kmem_cache *orig_s, size_t size, void **p)EXPORT_SYMBOL (kmem_cache_free_bulk);/* Note that interrupts must be enabled when calling this function. */ -bool kmem_cache_alloc_bulk (struct kmem_cache *s,gfp_t flags,size_t size, -void **p) +int kmem_cache_alloc_bulk (struct kmem_cache *s,gfp_t flags,size_t size, +void **p) {struct kmem_cache_cpu *c;int i;
@@ -2961,12 +2961,12 @@ bool kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,/* memcg and kmem_cache debug support */ slab_post_alloc_hook (s, flags, size, p); -return true; +return i; error:local_irq_enable ();slab_post_alloc_hook (s, flags, i, p);__kmem_cache_free_bulk (s, i, p); -return false; +return 0 ; }EXPORT_SYMBOL (kmem_cache_alloc_bulk);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 1 line · Jesper Dangaard Brouer
Adjust
kmem_cache_alloc_bulkAPI before we have any real users.
Well yes that is what I initially proposed. There was a concern that the _bulk calls should either return all objects or none.
But if you indicate that with a flag then ok.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>