mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rohit <rohit.kr@samsung.com>
To: Casey Schaufler <casey@schaufler-ca.com>
Cc: akpm@linux-foundation.org, james.l.morris@oracle.com,
	serge@hallyn.com, linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, cpgs@samsung.com,
	pintu.k@samsung.com, vishnu.ps@samsung.com,
	iqbal.ams@samsung.com, ed.savinay@samsung.com, me.rohit@live.com,
	pintu_agarwal@yahoo.com
Subject: Re: [PATCH v2] Security: smack: replace kzalloc with kmem_cache for inode_smack
Date: Fri, 17 Oct 2014 17:12:29 +0530	[thread overview]
Message-ID: <20141017171229.7c1a113e@rohitk-ubuntu.sisodomain.com> (raw)
In-Reply-To: <543FF121.7000502@schaufler-ca.com>

On Thu, 16 Oct 2014 09:24:01 -0700
Casey Schaufler <casey@schaufler-ca.com> wrote:

> On 10/15/2014 5:10 AM, Rohit wrote:
> > 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.
> 
> What impact does this have on performance? I am much more
> concerned with speed than with small amount of memory.
> 
I think there should not be any performance problem as such.
However, please let me know how to check the performance in this case.

As far as i know, kzalloc first finds the kmalloc_index corresponding to
the size to get the kmem_cache_object and then calls kmem_cache_alloc
with the kmalloc_index(kmem_cache object). Here, we create kmem_cache
object specific for inode_smack and directly calls kmem_cache_alloc()
which should give better performance as compared to kzalloc.

Please let me know your comments.
> >
> > 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>
> > ---
> > Added static in kmem_cache object declaration noted by Andrew
> > Morton <akpm@ linux-foundation.org> . Also updated commit message.
> >  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..15d985c 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);
> > +static 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");
> >  
> 

Thanks,
Rohit

  reply	other threads:[~2014-10-17 11:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-15 12:10 Rohit
2014-10-16  7:07 ` Serge E. Hallyn
2014-10-16 16:24 ` Casey Schaufler
2014-10-17 11:42   ` Rohit [this message]
2014-10-17 14:38     ` Casey Schaufler
     [not found]       ` <1413563667.96709.YahooMailNeo@web160104.mail.bf1.yahoo.com>
2014-10-17 17:37         ` Casey Schaufler
2014-10-27  0:41           ` Casey Schaufler
2014-10-27  6:54             ` Rohit
2014-10-27 16:25               ` Casey Schaufler
2014-10-29  9:11                 ` Rohit
2014-10-29 15:12                   ` Casey Schaufler
2014-10-31  4:03                     ` Rohit
2014-10-31 15:39                       ` Casey Schaufler
2014-10-31 21:32 ` Casey Schaufler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141017171229.7c1a113e@rohitk-ubuntu.sisodomain.com \
    --to=rohit.kr@samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=casey@schaufler-ca.com \
    --cc=cpgs@samsung.com \
    --cc=ed.savinay@samsung.com \
    --cc=iqbal.ams@samsung.com \
    --cc=james.l.morris@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=me.rohit@live.com \
    --cc=pintu.k@samsung.com \
    --cc=pintu_agarwal@yahoo.com \
    --cc=serge@hallyn.com \
    --cc=vishnu.ps@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®