aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorRohit <rohit.kr@samsung.com>2014-10-15 08:10:41 -0400
committerCasey Schaufler <casey@schaufler-ca.com>2014-10-31 17:29:32 -0400
commit1a5b472bde752783e0a31b59c61c9ff5b37a0983 (patch)
tree0f2a62d8c5ba00f599b0d816755698490e8276f5 /security
parent6c892df2686c5611979792aaa4ddea9ee9f18749 (diff)
Security: smack: replace kzalloc with kmem_cache for inode_smack
The patch use kmem_cache to allocate/free inode_smack since they are alloced in high volumes making it a perfect case for kmem_cache. As per analysis, 24 bytes of memory is wasted per allocation due to internal fragmentation. With kmem_cache, this can be avoided. Accounting of memory allocation is below : total slack net count-alloc/free caller Before (with kzalloc) 1919872 719952 1919872 29998/0 new_inode_smack+0x14 After (with kmem_cache) 1201680 0 1201680 30042/0 new_inode_smack+0x18 >From above data, we found that 719952 bytes(~700 KB) of memory is saved on allocation of 29998 smack inodes. Signed-off-by: Rohit <rohit.kr@samsung.com>
Diffstat (limited to 'security')
-rw-r--r--security/smack/smack_lsm.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 93dc876734a4..2717cdd7872c 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -53,6 +53,7 @@
53#define SMK_SENDING 2 53#define SMK_SENDING 2
54 54
55LIST_HEAD(smk_ipv6_port_list); 55LIST_HEAD(smk_ipv6_port_list);
56static struct kmem_cache *smack_inode_cache;
56 57
57#ifdef CONFIG_SECURITY_SMACK_BRINGUP 58#ifdef CONFIG_SECURITY_SMACK_BRINGUP
58static void smk_bu_mode(int mode, char *s) 59static void smk_bu_mode(int mode, char *s)
@@ -240,7 +241,7 @@ struct inode_smack *new_inode_smack(struct smack_known *skp)
240{ 241{
241 struct inode_smack *isp; 242 struct inode_smack *isp;
242 243
243 isp = kzalloc(sizeof(struct inode_smack), GFP_NOFS); 244 isp = kmem_cache_zalloc(smack_inode_cache, GFP_NOFS);
244 if (isp == NULL) 245 if (isp == NULL)
245 return NULL; 246 return NULL;
246 247
@@ -767,7 +768,7 @@ static int smack_inode_alloc_security(struct inode *inode)
767 */ 768 */
768static void smack_inode_free_security(struct inode *inode) 769static void smack_inode_free_security(struct inode *inode)
769{ 770{
770 kfree(inode->i_security); 771 kmem_cache_free(smack_inode_cache, inode->i_security);
771 inode->i_security = NULL; 772 inode->i_security = NULL;
772} 773}
773 774
@@ -4265,10 +4266,16 @@ static __init int smack_init(void)
4265 if (!security_module_enable(&smack_ops)) 4266 if (!security_module_enable(&smack_ops))
4266 return 0; 4267 return 0;
4267 4268
4269 smack_inode_cache = KMEM_CACHE(inode_smack, 0);
4270 if (!smack_inode_cache)
4271 return -ENOMEM;
4272
4268 tsp = new_task_smack(&smack_known_floor, &smack_known_floor, 4273 tsp = new_task_smack(&smack_known_floor, &smack_known_floor,
4269 GFP_KERNEL); 4274 GFP_KERNEL);
4270 if (tsp == NULL) 4275 if (tsp == NULL) {
4276 kmem_cache_destroy(smack_inode_cache);
4271 return -ENOMEM; 4277 return -ENOMEM;
4278 }
4272 4279
4273 printk(KERN_INFO "Smack: Initializing.\n"); 4280 printk(KERN_INFO "Smack: Initializing.\n");
4274 4281