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

kernfs: Allocating memory for kernfs_iattrs with kmem_cache.

Creating a new cache for kernfs_iattrs.
Currently, memory is allocated with kzalloc() which
always gives aligned memory. On ARM, this is 64 byte aligned.
To avoid the wastage of memory in aligning the size requested,
a new cache for kernfs_iattrs is created.

Size of struct kernfs_iattrs is 80 Bytes.
On ARM, it will come in kmalloc-128 slab.
and it will come in kmalloc-192 slab if debug info is enabled.
Extra bytes taken 48 bytes.

Total number of objects created : 4096
Total saving = 48*4096 = 192 KB

After creating new slab(When debug info is enabled) :
sh-3.2# cat /proc/slabinfo
...
kernfs_iattrs_cache 4069 4096 128 32 1 : tunables 0 0 0 : slabdata 128 128 0
...

All testing has been done on ARM target.

Signed-off-by: Ayush Mittal <ayush.m@samsung.com>
Signed-off-by: Vaneet Narang <v.narang@samsung.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ayush Mittal and committed by
Greg Kroah-Hartman
26e28d68 5b2f2bd6

+9 -4
+1 -1
fs/kernfs/dir.c
··· 536 536 security_release_secctx(kn->iattr->ia_secdata, 537 537 kn->iattr->ia_secdata_len); 538 538 simple_xattrs_free(&kn->iattr->xattrs); 539 + kmem_cache_free(kernfs_iattrs_cache, kn->iattr); 539 540 } 540 - kfree(kn->iattr); 541 541 spin_lock(&kernfs_idr_lock); 542 542 idr_remove(&root->ino_idr, kn->id.ino); 543 543 spin_unlock(&kernfs_idr_lock);
+1 -1
fs/kernfs/inode.c
··· 42 42 if (kn->iattr) 43 43 goto out_unlock; 44 44 45 - kn->iattr = kzalloc(sizeof(struct kernfs_iattrs), GFP_KERNEL); 45 + kn->iattr = kmem_cache_zalloc(kernfs_iattrs_cache, GFP_KERNEL); 46 46 if (!kn->iattr) 47 47 goto out_unlock; 48 48 iattrs = &kn->iattr->ia_iattr;
+1 -1
fs/kernfs/kernfs-internal.h
··· 78 78 } 79 79 80 80 extern const struct super_operations kernfs_sops; 81 - extern struct kmem_cache *kernfs_node_cache; 81 + extern struct kmem_cache *kernfs_node_cache, *kernfs_iattrs_cache; 82 82 83 83 /* 84 84 * inode.c
+6 -1
fs/kernfs/mount.c
··· 20 20 21 21 #include "kernfs-internal.h" 22 22 23 - struct kmem_cache *kernfs_node_cache; 23 + struct kmem_cache *kernfs_node_cache, *kernfs_iattrs_cache; 24 24 25 25 static int kernfs_sop_remount_fs(struct super_block *sb, int *flags, char *data) 26 26 { ··· 417 417 0, 418 418 SLAB_PANIC | SLAB_TYPESAFE_BY_RCU, 419 419 NULL); 420 + 421 + /* Creates slab cache for kernfs inode attributes */ 422 + kernfs_iattrs_cache = kmem_cache_create("kernfs_iattrs_cache", 423 + sizeof(struct kernfs_iattrs), 424 + 0, SLAB_PANIC, NULL); 420 425 }