* [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage
@ 2013-09-06 13:47 Sergey Senozhatsky
2013-09-06 14:42 ` Jerome Marchand
0 siblings, 1 reply; 5+ messages in thread
From: Sergey Senozhatsky @ 2013-09-06 13:47 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Minchan Kim, devel, linux-kernel
Calling handle_pending_slot_free() for every RW operation may
cause unneccessary slot_free_lock locking, because most likely
process will see NULL slot_free_rq. handle_pending_slot_free()
only when current detects that slot_free_rq is not NULL.
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
drivers/staging/zram/zram_drv.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index 91d94b5..17386e2 100644
--- a/drivers/staging/zram/zram_drv.c
+++ b/drivers/staging/zram/zram_drv.c
@@ -532,14 +532,15 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
{
int ret;
+ if (zram->slot_free_rq)
+ handle_pending_slot_free(zram);
+
if (rw == READ) {
down_read(&zram->lock);
- handle_pending_slot_free(zram);
ret = zram_bvec_read(zram, bvec, index, offset, bio);
up_read(&zram->lock);
} else {
down_write(&zram->lock);
- handle_pending_slot_free(zram);
ret = zram_bvec_write(zram, bvec, index, offset);
up_write(&zram->lock);
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage
2013-09-06 13:47 [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage Sergey Senozhatsky
@ 2013-09-06 14:42 ` Jerome Marchand
2013-09-06 14:55 ` Sergey Senozhatsky
0 siblings, 1 reply; 5+ messages in thread
From: Jerome Marchand @ 2013-09-06 14:42 UTC (permalink / raw)
To: Sergey Senozhatsky; +Cc: Greg Kroah-Hartman, Minchan Kim, devel, linux-kernel
On 09/06/2013 03:47 PM, Sergey Senozhatsky wrote:
> Calling handle_pending_slot_free() for every RW operation may
> cause unneccessary slot_free_lock locking, because most likely
> process will see NULL slot_free_rq. handle_pending_slot_free()
> only when current detects that slot_free_rq is not NULL.
>
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
>
> ---
>
> drivers/staging/zram/zram_drv.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
> index 91d94b5..17386e2 100644
> --- a/drivers/staging/zram/zram_drv.c
> +++ b/drivers/staging/zram/zram_drv.c
> @@ -532,14 +532,15 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
> {
> int ret;
>
> + if (zram->slot_free_rq)
> + handle_pending_slot_free(zram);
> +
Calling handle_pending_slot_free() without holding zram->lock?
That's racy.
Jerome
> if (rw == READ) {
> down_read(&zram->lock);
> - handle_pending_slot_free(zram);
> ret = zram_bvec_read(zram, bvec, index, offset, bio);
> up_read(&zram->lock);
> } else {
> down_write(&zram->lock);
> - handle_pending_slot_free(zram);
> ret = zram_bvec_write(zram, bvec, index, offset);
> up_write(&zram->lock);
> }
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage
2013-09-06 14:42 ` Jerome Marchand
@ 2013-09-06 14:55 ` Sergey Senozhatsky
2013-09-09 8:33 ` Dan Carpenter
0 siblings, 1 reply; 5+ messages in thread
From: Sergey Senozhatsky @ 2013-09-06 14:55 UTC (permalink / raw)
To: Jerome Marchand; +Cc: Greg Kroah-Hartman, Minchan Kim, devel, linux-kernel
On (09/06/13 16:42), Jerome Marchand wrote:
> On 09/06/2013 03:47 PM, Sergey Senozhatsky wrote:
> > Calling handle_pending_slot_free() for every RW operation may
> > cause unneccessary slot_free_lock locking, because most likely
> > process will see NULL slot_free_rq. handle_pending_slot_free()
> > only when current detects that slot_free_rq is not NULL.
> >
> > Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> >
> > ---
> >
> > drivers/staging/zram/zram_drv.c | 5 +++--
> > 1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
> > index 91d94b5..17386e2 100644
> > --- a/drivers/staging/zram/zram_drv.c
> > +++ b/drivers/staging/zram/zram_drv.c
> > @@ -532,14 +532,15 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
> > {
> > int ret;
> >
> > + if (zram->slot_free_rq)
> > + handle_pending_slot_free(zram);
> > +
>
> Calling handle_pending_slot_free() without holding zram->lock?
> That's racy.
sorry, my bad. it should take down_write() lock.
-ss
> Jerome
>
> > if (rw == READ) {
> > down_read(&zram->lock);
> > - handle_pending_slot_free(zram);
> > ret = zram_bvec_read(zram, bvec, index, offset, bio);
> > up_read(&zram->lock);
> > } else {
> > down_write(&zram->lock);
> > - handle_pending_slot_free(zram);
> > ret = zram_bvec_write(zram, bvec, index, offset);
> > up_write(&zram->lock);
> > }
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at http://www.tux.org/lkml/
> >
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage
2013-09-06 14:55 ` Sergey Senozhatsky
@ 2013-09-09 8:33 ` Dan Carpenter
2013-09-09 9:06 ` Sergey Senozhatsky
0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2013-09-09 8:33 UTC (permalink / raw)
To: Sergey Senozhatsky
Cc: Jerome Marchand, devel, Greg Kroah-Hartman, linux-kernel,
Minchan Kim
On Fri, Sep 06, 2013 at 05:55:45PM +0300, Sergey Senozhatsky wrote:
> On (09/06/13 16:42), Jerome Marchand wrote:
> > On 09/06/2013 03:47 PM, Sergey Senozhatsky wrote:
> > > Calling handle_pending_slot_free() for every RW operation may
> > > cause unneccessary slot_free_lock locking, because most likely
> > > process will see NULL slot_free_rq. handle_pending_slot_free()
> > > only when current detects that slot_free_rq is not NULL.
> > >
> > > Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> > >
> > > ---
> > >
> > > drivers/staging/zram/zram_drv.c | 5 +++--
> > > 1 file changed, 3 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
> > > index 91d94b5..17386e2 100644
> > > --- a/drivers/staging/zram/zram_drv.c
> > > +++ b/drivers/staging/zram/zram_drv.c
> > > @@ -532,14 +532,15 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
> > > {
> > > int ret;
> > >
> > > + if (zram->slot_free_rq)
> > > + handle_pending_slot_free(zram);
> > > +
> >
> > Calling handle_pending_slot_free() without holding zram->lock?
> > That's racy.
>
> sorry, my bad. it should take down_write() lock.
>
Or down_read() on the read path. We leave the original as-is?
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage
2013-09-09 8:33 ` Dan Carpenter
@ 2013-09-09 9:06 ` Sergey Senozhatsky
0 siblings, 0 replies; 5+ messages in thread
From: Sergey Senozhatsky @ 2013-09-09 9:06 UTC (permalink / raw)
To: Dan Carpenter
Cc: Jerome Marchand, devel, Greg Kroah-Hartman, linux-kernel,
Minchan Kim
On (09/09/13 11:33), Dan Carpenter wrote:
> On Fri, Sep 06, 2013 at 05:55:45PM +0300, Sergey Senozhatsky wrote:
> > On (09/06/13 16:42), Jerome Marchand wrote:
> > > On 09/06/2013 03:47 PM, Sergey Senozhatsky wrote:
> > > > Calling handle_pending_slot_free() for every RW operation may
> > > > cause unneccessary slot_free_lock locking, because most likely
> > > > process will see NULL slot_free_rq. handle_pending_slot_free()
> > > > only when current detects that slot_free_rq is not NULL.
> > > >
> > > > Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> > > >
> > > > ---
> > > >
> > > > drivers/staging/zram/zram_drv.c | 5 +++--
> > > > 1 file changed, 3 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
> > > > index 91d94b5..17386e2 100644
> > > > --- a/drivers/staging/zram/zram_drv.c
> > > > +++ b/drivers/staging/zram/zram_drv.c
> > > > @@ -532,14 +532,15 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
> > > > {
> > > > int ret;
> > > >
> > > > + if (zram->slot_free_rq)
> > > > + handle_pending_slot_free(zram);
> > > > +
> > >
> > > Calling handle_pending_slot_free() without holding zram->lock?
> > > That's racy.
> >
> > sorry, my bad. it should take down_write() lock.
> >
>
> Or down_read() on the read path. We leave the original as-is?
>
Hello,
down_write() for both READ and WRITE looks ok to me (+down_write()
for zram_slot_free()). is there something I miss?
down_read() for READ in case of N active readers will force N-1
processes to spin on zram->slot_free_lock in handle_pending_slot_free().
it probably makes sense to add extra zram->slot_free_rq check for
the case when process slept on rw lock while someone was freeing
pages:
static void handle_pending_slot_free(struct zram *zram)
{
struct zram_slot_free *free_rq;
down_write(&zram->lock);
+ if (!zram->slot_free_rq)
+ goto out;
spin_lock(&zram->slot_free_lock);
while (zram->slot_free_rq) {
free_rq = zram->slot_free_rq;
zram->slot_free_rq = free_rq->next;
zram_free_page(zram, free_rq->index);
kfree(free_rq);
}
spin_unlock(&zram->slot_free_lock);
+out:
up_write(&zram->lock);
}
-ss
> regards,
> dan carpenter
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-09-09 9:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-06 13:47 [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage Sergey Senozhatsky
2013-09-06 14:42 ` Jerome Marchand
2013-09-06 14:55 ` Sergey Senozhatsky
2013-09-09 8:33 ` Dan Carpenter
2013-09-09 9:06 ` Sergey Senozhatsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox