Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/slab: move and refactor __kmem_cache_alias()

Move __kmem_cache_alias() to slab_common.c since it's called by
__kmem_cache_create_args() and calls find_mergeable() that both
are in this file. We can remove two slab.h declarations and make
them static. Instead declare sysfs_slab_alias() from slub.c so
that __kmem_cache_alias() can keep calling it.

Add args parameter to __kmem_cache_alias() and find_mergeable() instead
of align and ctor. With that we can also move the checks for usersize
and sheaf_capacity there from __kmem_cache_create_args() and make the
result more symmetric with slab_unmergeable().

No functional changes intended.

Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>

+41 -41
+3 -5
mm/slab.h
··· 281 281 #define SLAB_SUPPORTS_SYSFS 1 282 282 void sysfs_slab_unlink(struct kmem_cache *s); 283 283 void sysfs_slab_release(struct kmem_cache *s); 284 + int sysfs_slab_alias(struct kmem_cache *s, const char *name); 284 285 #else 285 286 static inline void sysfs_slab_unlink(struct kmem_cache *s) { } 286 287 static inline void sysfs_slab_release(struct kmem_cache *s) { } 288 + static inline int sysfs_slab_alias(struct kmem_cache *s, const char *name) 289 + { return 0; } 287 290 #endif 288 291 289 292 void *fixup_red_left(struct kmem_cache *s, void *p); ··· 403 400 unsigned int useroffset, unsigned int usersize); 404 401 405 402 int slab_unmergeable(struct kmem_cache *s); 406 - struct kmem_cache *find_mergeable(unsigned size, unsigned align, 407 - slab_flags_t flags, const char *name, void (*ctor)(void *)); 408 - struct kmem_cache * 409 - __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, 410 - slab_flags_t flags, void (*ctor)(void *)); 411 403 412 404 slab_flags_t kmem_cache_flags(slab_flags_t flags, const char *name); 413 405
+37 -7
mm/slab_common.c
··· 174 174 return 0; 175 175 } 176 176 177 - struct kmem_cache *find_mergeable(unsigned int size, unsigned int align, 178 - slab_flags_t flags, const char *name, void (*ctor)(void *)) 177 + static struct kmem_cache *find_mergeable(unsigned int size, slab_flags_t flags, 178 + const char *name, struct kmem_cache_args *args) 179 179 { 180 180 struct kmem_cache *s; 181 + unsigned int align; 181 182 182 183 if (slab_nomerge) 183 184 return NULL; 184 185 185 - if (ctor) 186 + if (args->ctor) 187 + return NULL; 188 + 189 + if (IS_ENABLED(CONFIG_HARDENED_USERCOPY) && args->usersize) 190 + return NULL; 191 + 192 + if (args->sheaf_capacity) 186 193 return NULL; 187 194 188 195 flags = kmem_cache_flags(flags, name); ··· 198 191 return NULL; 199 192 200 193 size = ALIGN(size, sizeof(void *)); 201 - align = calculate_alignment(flags, align, size); 194 + align = calculate_alignment(flags, args->align, size); 202 195 size = ALIGN(size, align); 203 196 204 197 list_for_each_entry_reverse(s, &slab_caches, list) { ··· 257 250 kmem_cache_free(kmem_cache, s); 258 251 out: 259 252 return ERR_PTR(err); 253 + } 254 + 255 + static struct kmem_cache * 256 + __kmem_cache_alias(const char *name, unsigned int size, slab_flags_t flags, 257 + struct kmem_cache_args *args) 258 + { 259 + struct kmem_cache *s; 260 + 261 + s = find_mergeable(size, flags, name, args); 262 + if (s) { 263 + if (sysfs_slab_alias(s, name)) 264 + pr_err("SLUB: Unable to add cache alias %s to sysfs\n", 265 + name); 266 + 267 + s->refcount++; 268 + 269 + /* 270 + * Adjust the object sizes so that we clear 271 + * the complete object on kzalloc. 272 + */ 273 + s->object_size = max(s->object_size, size); 274 + s->inuse = max(s->inuse, ALIGN(size, sizeof(void *))); 275 + } 276 + 277 + return s; 260 278 } 261 279 262 280 /** ··· 355 323 object_size - args->usersize < args->useroffset)) 356 324 args->usersize = args->useroffset = 0; 357 325 358 - if (!args->usersize && !args->sheaf_capacity) 359 - s = __kmem_cache_alias(name, object_size, args->align, flags, 360 - args->ctor); 326 + s = __kmem_cache_alias(name, object_size, flags, args); 361 327 if (s) 362 328 goto out_unlock; 363 329
+1 -29
mm/slub.c
··· 350 350 351 351 #ifdef SLAB_SUPPORTS_SYSFS 352 352 static int sysfs_slab_add(struct kmem_cache *); 353 - static int sysfs_slab_alias(struct kmem_cache *, const char *); 354 353 #else 355 354 static inline int sysfs_slab_add(struct kmem_cache *s) { return 0; } 356 - static inline int sysfs_slab_alias(struct kmem_cache *s, const char *p) 357 - { return 0; } 358 355 #endif 359 356 360 357 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_SLUB_DEBUG) ··· 8577 8580 WARN_ON(!flushwq); 8578 8581 } 8579 8582 8580 - struct kmem_cache * 8581 - __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, 8582 - slab_flags_t flags, void (*ctor)(void *)) 8583 - { 8584 - struct kmem_cache *s; 8585 - 8586 - s = find_mergeable(size, align, flags, name, ctor); 8587 - if (s) { 8588 - if (sysfs_slab_alias(s, name)) 8589 - pr_err("SLUB: Unable to add cache alias %s to sysfs\n", 8590 - name); 8591 - 8592 - s->refcount++; 8593 - 8594 - /* 8595 - * Adjust the object sizes so that we clear 8596 - * the complete object on kzalloc. 8597 - */ 8598 - s->object_size = max(s->object_size, size); 8599 - s->inuse = max(s->inuse, ALIGN(size, sizeof(void *))); 8600 - } 8601 - 8602 - return s; 8603 - } 8604 - 8605 8583 int do_kmem_cache_create(struct kmem_cache *s, const char *name, 8606 8584 unsigned int size, struct kmem_cache_args *args, 8607 8585 slab_flags_t flags) ··· 9809 9837 9810 9838 static struct saved_alias *alias_list; 9811 9839 9812 - static int sysfs_slab_alias(struct kmem_cache *s, const char *name) 9840 + int sysfs_slab_alias(struct kmem_cache *s, const char *name) 9813 9841 { 9814 9842 struct saved_alias *al; 9815 9843