From: Minchan Kim <minchan@kernel.org>
To: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Nitin Gupta <ngupta@vflare.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCHv2 10/10] zram: add dynamic device add/remove functionality
Date: Thu, 23 Apr 2015 15:20:15 +0900 [thread overview]
Message-ID: <20150423062015.GA6315@blaptop> (raw)
In-Reply-To: <20150423042300.GA724@swordfish>
On Thu, Apr 23, 2015 at 01:23:00PM +0900, Sergey Senozhatsky wrote:
> On (04/23/15 12:06), Minchan Kim wrote:
> > > +Example:
> > > + cat /sys/class/zram-control/zram_add
> >
> > Why do we put zram-contol there rather than /sys/block/zram
>
> that's what clsss_register() does.
>
> [..]
>
> > > @@ -1168,8 +1172,15 @@ static int zram_add(int device_id)
> >
> > Why do zram_add need device_id?
> > We decided to remove option user pass device_id.
>
> will cleanup. it was simpler at that time to support both devices
> created by sysfs request and devices pre-crated for num_devices
> module param.
>
>
> > > +static struct zram *zram_lookup(int dev_id)
> > > +{
> > > + struct zram *zram;
> > > +
> > > + zram = idr_find(&zram_index_idr, dev_id);
> > > + if (zram)
> > > + return zram;
> > > + return ERR_PTR(-ENODEV);
> >
> > Just return NULL which is more simple and readable.
> >
>
> ok.
>
>
> [..]
> > > + /*
> > > + * First, make ->disksize device attr RO, closing
> > > + * zram_remove() vs disksize_store() race window
> >
> > Why don't you use zram->init_lock to protect the race?
>
> zram_reset_device() takes this lock internally. but, it
> unlocks the device upon the return from zram_reset_device():
>
> lock idr_lock
> zram_reset_device()
> lock bd_mutex
> __zam_reset_device()
> lock init_lock
> reset
> unlock init_lock ---\
> unlock bd_mutex |
> |<----- disksize_store() race window
> zram_remove() ---/
> unlock idr_lock
>
>
> until we call zram_remove() (which does sysfs_remove_group()) device has
> sysfs attrs and, thus, disksize_store() can arrive in the middle. the
> simplest things I came up with was that RO bit on sysfs disksize attrs.
> I can factor out another set of __foo function to handle it differently,
> not sure if this worth it.
I believe we should handle it with init_lock more elegantly rather than
RO trick. The init_lock was born to protect race between init and exit
although we didn't need it until now since we don't have dynamic device
feature. So, with refactoring, we should handle it with init_lock.
>
> I'll revisit it.
Thanks. I believe you will find.
--
Kind regards,
Minchan Kim
next prev parent reply other threads:[~2015-04-23 6:20 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-16 11:55 [PATCHv2 00/10] cleaned up on-demand device creation Sergey Senozhatsky
2015-04-16 11:55 ` [PATCHv2 01/10] zram: enable compaction support in zram Sergey Senozhatsky
2015-04-16 11:55 ` [PATCHv2 02/10] zram: cosmetic ZRAM_ATTR_RO code formatting tweak Sergey Senozhatsky
2015-04-23 2:16 ` Minchan Kim
2015-04-16 11:55 ` [PATCHv2 03/10] zram: use idr instead of `zram_devices' array Sergey Senozhatsky
2015-04-23 2:23 ` Minchan Kim
2015-04-23 4:30 ` Sergey Senozhatsky
2015-04-16 11:55 ` [PATCHv2 04/10] zram: factor out device reset from reset_store() Sergey Senozhatsky
2015-04-23 2:29 ` Minchan Kim
2015-04-23 4:26 ` Sergey Senozhatsky
2015-04-16 11:55 ` [PATCHv2 05/10] zram: reorganize code layout Sergey Senozhatsky
2015-04-23 2:32 ` Minchan Kim
2015-04-16 11:55 ` [PATCHv2 06/10] zram: remove max_num_devices limitation Sergey Senozhatsky
2015-04-23 2:36 ` Minchan Kim
2015-04-23 4:24 ` Sergey Senozhatsky
2015-04-16 11:55 ` [PATCHv2 07/10] zram: report every added and removed device Sergey Senozhatsky
2015-04-23 2:38 ` Minchan Kim
2015-04-23 4:23 ` Sergey Senozhatsky
2015-04-16 11:55 ` [PATCHv2 08/10] zram: trivial: correct flag operations comment Sergey Senozhatsky
2015-04-23 2:40 ` Minchan Kim
2015-04-16 11:55 ` [PATCHv2 09/10] zram: return zram device_id value from zram_add() Sergey Senozhatsky
2015-04-23 2:41 ` Minchan Kim
2015-04-16 11:55 ` [PATCHv2 10/10] zram: add dynamic device add/remove functionality Sergey Senozhatsky
2015-04-23 3:06 ` Minchan Kim
2015-04-23 3:12 ` Minchan Kim
2015-04-23 4:23 ` Sergey Senozhatsky
2015-04-23 6:20 ` Minchan Kim [this message]
2015-04-16 23:23 ` [PATCHv2 00/10] cleaned up on-demand device creation Minchan Kim
2015-04-17 0:27 ` Sergey Senozhatsky
2015-04-17 0:39 ` Sergey Senozhatsky
2015-04-17 1:00 ` Sergey Senozhatsky
2015-04-17 1:32 ` Sergey Senozhatsky
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=20150423062015.GA6315@blaptop \
--to=minchan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ngupta@vflare.org \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=sergey.senozhatsky@gmail.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