linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Alexander Lyakas <alex.bolshoy@gmail.com>
Cc: linux-raid <linux-raid@vger.kernel.org>,
	Yair Hershko <yair@zadarastorage.com>,
	Vladimir Popovski <vladimir@zadarastorage.com>,
	Shyam Kaushik <shyam@zadarastorage.com>
Subject: Re: raid5.c::grow_stripes() kmem_cache_create() race
Date: Thu, 12 Jun 2014 17:37:44 +1000	[thread overview]
Message-ID: <20140612173744.03dd7a70@notabene.brown> (raw)
In-Reply-To: <CAGRgLy5Nz7aVRsqhco1eUB0hTvnYgupaUuGv=wA7ttWg+mdBmQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2012 bytes --]

On Wed, 11 Jun 2014 19:00:42 +0300 Alexander Lyakas <alex.bolshoy@gmail.com>
wrote:

> Hi Neil,
> in your master branch, you have a code like:
> 
> static int grow_stripes(struct r5conf *conf, int num)
> {
>     struct kmem_cache *sc;
>     int devs = max(conf->raid_disks, conf->previous_raid_disks);
>     int hash;
> 
>     if (conf->mddev->gendisk)
>         sprintf(conf->cache_name[0],
>             "raid%d-%s", conf->level, mdname(conf->mddev));
>     else
>         sprintf(conf->cache_name[0],
>             "raid%d-%p", conf->level, conf->mddev);
>     sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
> 
>     conf->active_name = 0;
>     sc = kmem_cache_create(conf->cache_name[conf->active_name],
>                    sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev),
>                    0, 0, NULL);
> 
> In our case what happened was:
> - we were assembling two MDs in parallel: md4 and md5
> - each one tried to create its own kmem_cache: raid5-md4 and raid5-md5
> (each one had valid conf->mmdev->gendisk)
> 
> In our kernel SLUB is configured. So the code went to
> slub.c::__kmem_cache_create(). It called sysfs_slab_add(), which
> eventually tried to do:
> 
> if (unmergeable) {
>     // not here
> } else {
>     // we went here
>     name = create_unique_id(s);
> }
> 
> For both threads calling this, it created the same unique id:
> "t-0001832". And then sysfs freaked out and complained[1]. So md5 was
> unlucky and failed to initialize, and md4 got lucky and came up.
> Later, we retried md5 assembly and it worked alright.
> 
> In this case, both MDs have the same number of disks. That's why
> kernel tried to have a single cache. Problem is that
> __kmem_cache_create unlocks slab_mutex, so that's why the race becomes
> possible.
> 
> I realize that this is not MD-specific, but rather slab-specific
> issue, but do you have any idea how to fix that?:(

no, sorry.

As the slub developers.

NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

  reply	other threads:[~2014-06-12  7:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-11 16:00 raid5.c::grow_stripes() kmem_cache_create() race Alexander Lyakas
2014-06-12  7:37 ` NeilBrown [this message]
2014-06-16 17:25   ` Alexander Lyakas

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=20140612173744.03dd7a70@notabene.brown \
    --to=neilb@suse.de \
    --cc=alex.bolshoy@gmail.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=shyam@zadarastorage.com \
    --cc=vladimir@zadarastorage.com \
    --cc=yair@zadarastorage.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;
as well as URLs for NNTP newsgroup(s).