mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH 1/1] Security : smack : Use kmem_cache for allocation and freeing of inode_smack
  2014-10-15  5:56 [PATCH 1/1] Security : smack : Use kmem_cache for allocation and freeing of inode_smack Rohit Kumar
@ 2014-10-15  5:43 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2014-10-15  5:43 UTC (permalink / raw)
  To: Rohit Kumar
  Cc: casey, james.l.morris, serge, linux-security-module,
	linux-kernel, cpgs, pintu.k, vishnu.ps, iqbal.ams, ed.savinay

On Wed, 15 Oct 2014 11:26:16 +0530 Rohit Kumar <rohit.kr@samsung.com> wrote:

> From: Rohit <rohit.kr@samsung.com>
> 
> Use kmem_cache to allocate/free inode_smack since they are
> alloced in high volumes making it a perfect case for kmem_cache.
> 
> 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
> 
> ...
>
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -53,6 +53,7 @@
>  #define SMK_SENDING	2
>  
>  LIST_HEAD(smk_ipv6_port_list);
> +struct kmem_cache *smack_inode_cache;

static.
  


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 1/1] Security : smack : Use kmem_cache for allocation and freeing of inode_smack
@ 2014-10-15  5:56 Rohit Kumar
  2014-10-15  5:43 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Rohit Kumar @ 2014-10-15  5:56 UTC (permalink / raw)
  To: akpm, casey, james.l.morris, serge, linux-security-module, linux-kernel
  Cc: cpgs, pintu.k, rohit.kr, vishnu.ps, iqbal.ams, ed.savinay

From: Rohit <rohit.kr@samsung.com>

Use kmem_cache to allocate/free inode_smack since they are
alloced in high volumes making it a perfect case for kmem_cache.

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

Signed-off-by: Rohit <rohit.kr@samsung.com>
---
 security/smack/smack_lsm.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index d515ec2..58a5c92 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -53,6 +53,7 @@
 #define SMK_SENDING	2
 
 LIST_HEAD(smk_ipv6_port_list);
+struct kmem_cache *smack_inode_cache;
 
 #ifdef CONFIG_SECURITY_SMACK_BRINGUP
 static void smk_bu_mode(int mode, char *s)
@@ -240,7 +241,7 @@ struct inode_smack *new_inode_smack(struct smack_known *skp)
 {
 	struct inode_smack *isp;
 
-	isp = kzalloc(sizeof(struct inode_smack), GFP_NOFS);
+	isp = kmem_cache_zalloc(smack_inode_cache, GFP_NOFS);
 	if (isp == NULL)
 		return NULL;
 
@@ -767,7 +768,7 @@ static int smack_inode_alloc_security(struct inode *inode)
  */
 static void smack_inode_free_security(struct inode *inode)
 {
-	kfree(inode->i_security);
+	kmem_cache_free(smack_inode_cache, inode->i_security);
 	inode->i_security = NULL;
 }
 
@@ -4264,10 +4265,16 @@ static __init int smack_init(void)
 	if (!security_module_enable(&smack_ops))
 		return 0;
 
+	smack_inode_cache = KMEM_CACHE(inode_smack, 0);
+	if (!smack_inode_cache)
+		return -ENOMEM;
+
 	tsp = new_task_smack(&smack_known_floor, &smack_known_floor,
 				GFP_KERNEL);
-	if (tsp == NULL)
+	if (tsp == NULL) {
+		kmem_cache_destroy(smack_inode_cache);
 		return -ENOMEM;
+	}
 
 	printk(KERN_INFO "Smack:  Initializing.\n");
 
-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-10-15  5:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-15  5:56 [PATCH 1/1] Security : smack : Use kmem_cache for allocation and freeing of inode_smack Rohit Kumar
2014-10-15  5:43 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome