linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Li Zhong <zhong@linux.vnet.ibm.com>
To: Glauber Costa <glommer@parallels.com>
Cc: Christoph Lameter <cl@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Pekka Enberg <penberg@kernel.org>, linux-mm <linux-mm@kvack.org>,
	Paul Mackerras <paulus@samba.org>, Matt Mackall <mpm@selenic.com>,
	PowerPC email list <linuxppc-dev@lists.ozlabs.org>
Subject: Re: [PATCH SLUB 1/2] duplicate the cache name in saved_alias list
Date: Tue, 26 Jun 2012 10:58:24 +0800	[thread overview]
Message-ID: <1340679504.16381.23.camel@ThinkPad-T420> (raw)
In-Reply-To: <4FE84741.9000703@parallels.com>

On Mon, 2012-06-25 at 15:10 +0400, Glauber Costa wrote:
> On 06/25/2012 01:53 PM, Li Zhong wrote:
> > SLUB duplicates the cache name in kmem_cache_create(). However if the
> > cache could be merged to others during early booting, the name pointer
> > is saved in saved_alias list, and the string needs to be kept valid
> > before slab_sysfs_init() is called.
> >
> > This patch tries to duplicate the cache name in saved_alias list, so
> > that the cache name could be safely kfreed after calling
> > kmem_cache_create(), if that name is kmalloced.
> >
> > Signed-off-by: Li Zhong <zhong@linux.vnet.ibm.com>
> > ---
> >   mm/slub.c |    6 ++++++
> >   1 files changed, 6 insertions(+), 0 deletions(-)
> >
> > diff --git a/mm/slub.c b/mm/slub.c
> > index 8c691fa..3dc8ed5 100644
> > --- a/mm/slub.c
> > +++ b/mm/slub.c
> > @@ -5373,6 +5373,11 @@ static int sysfs_slab_alias(struct kmem_cache *s,
> > const char *name)
> >
> >   	al->s = s;
> >   	al->name = name;
> > +	al->name = kstrdup(name, GFP_KERNEL);
> > +	if (!al->name) {
> > +		kfree(al);
> > +		return -ENOMEM;
> > +	}
> >   	al->next = alias_list;
> >   	alias_list = al;
> >   	return 0;
> > @@ -5409,6 +5414,7 @@ static int __init slab_sysfs_init(void)
> >   		if (err)
> >   			printk(KERN_ERR "SLUB: Unable to add boot slab alias"
> >   					" %s to sysfs\n", s->name);
> > +		kfree(al->name);
> >   		kfree(al);
> >   	}
> >
> >
> 
> What's unsafe about the current state of affairs ?
> Whenever we alias, we'll increase the reference counter.
> kmem_cache_destroy will only actually destroy the structure whenever 
> that refcnt reaches zero.
> 
> This means that kfree shouldn't happen until then. So what is exactly 
> that you are seeing?

Maybe I didn't describe it clearly ... It is only about the name string
passed into kmem_cache_create() during early boot. 

kmem_cache_create() checks whether it is mergeable before creating one.
If not mergeable, the name is duplicated: n = kstrdup(name, GFP_KERNEL);

If it is mergeable, it calls sysfs_slab_alias(). If the sysfs is ready
(slab_state == SYSFS ), then the name is duplicated (or dropped if no
SYSFS support ) in sysfs_create_link() for use. 

For the above cases, we could safely kfree the name string after calling
cache create. 

However, During early boot, before sysfs is ready ( slab_state <
SYSFS ), the sysfs_slab_alias() saves the pointer of name in the
alias_list. And those entries in the list are added to sysfs later after
slab_sysfs_init() is called. So we need to keep the name string valid
until slab_sysfs_init() is called to set up the sysfs stuff. By
duplicating the name string here also, we are able to kfree the name
string after calling the cache create. 

> 
> Now, if you ask me, keeping the name around in user-visible files like 
> /proc/slabinfo for caches that are removed already can be a bit 
> confusing (that is because we don't add aliases to the slab_cache list)
> 
> If you want to touch this, one thing you can do is to keep a list of 
> names bundled in an alias. If an alias is removed, you free that name. 
> If that name is the representative name of the bundle, you move to the 
> next one.
> 

  reply	other threads:[~2012-06-26  2:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-25  9:53 [PATCH SLUB 1/2] duplicate the cache name in saved_alias list Li Zhong
2012-06-25  9:54 ` [PATCH powerpc 2/2] kfree the cache name of pgtable cache if SLUB is used Li Zhong
2012-06-29  0:45   ` Benjamin Herrenschmidt
2012-06-29  1:41     ` Zhong Li
2012-07-03 18:48   ` Christoph Lameter
2012-07-03 20:36     ` Christoph Lameter
2012-07-04  9:00       ` Li Zhong
2012-07-04 12:40         ` Glauber Costa
2012-07-05  1:41           ` Li Zhong
2012-07-05  8:23             ` Glauber Costa
2012-07-05  9:29               ` Li Zhong
2012-07-06 10:13                 ` Glauber Costa
2012-07-09  1:48                   ` Li Zhong
2012-06-25 10:54 ` [PATCH SLUB 1/2] duplicate the cache name in saved_alias list Wanlong Gao
2012-06-26  2:49   ` Li Zhong
2012-06-25 11:10 ` Glauber Costa
2012-06-26  2:58   ` Li Zhong [this message]
2012-06-27  7:53 ` [PATCH SLUB 1/2 v2] " Li Zhong

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=1340679504.16381.23.camel@ThinkPad-T420 \
    --to=zhong@linux.vnet.ibm.com \
    --cc=cl@linux-foundation.org \
    --cc=glommer@parallels.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpm@selenic.com \
    --cc=paulus@samba.org \
    --cc=penberg@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).