public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Minchan Kim <minchan@kernel.org>
Cc: Weijie Yang <weijie.yang@samsung.com>,
	"'Andrew Morton'" <akpm@linux-foundation.org>,
	"'Nitin Gupta'" <ngupta@vflare.org>,
	iamjoonsoo.kim@lge.com,
	"'Sergey Senozhatsky'" <sergey.senozhatsky@gmail.com>,
	"'Bob Liu'" <bob.liu@oracle.com>,
	weijie.yang.kh@gmail.com,
	"'linux-kernel'" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH RESEND] zram: correct offset usage in zram_bio_discard
Date: Thu, 24 Apr 2014 10:31:31 +0300	[thread overview]
Message-ID: <20140424073131.GA1098@swordfish> (raw)
In-Reply-To: <20140424020632.GA863@bbox>

Hello Minchan,

On (04/24/14 11:06), Minchan Kim wrote:
> Hello,
> 
> On Wed, Apr 23, 2014 at 04:41:15PM +0800, Weijie Yang wrote:
> > We want to skip the physical block(PAGE_SIZE) which is partially
> > covered by the discard bio, so we check the remaining size and
> > subtract it if there is a need to goto the next physical block.
> > 
> > The current offset usage in zram_bio_discard is incorrect, it will
> > cause its upper filesystem breakdown.
> > Consider the following scenario:
> > on some architecture or config, PAGE_SIZE is 64K for example,
> > filesystem is set up on zram disk without PAGE_SIZE aligned,
> > a discard bio leads to a offset = 4K and size=72K,
> > normally, it should not really discard any physical block as it
> > partially cover two physical blocks.
> > However, with the current offset usage, it will discard the second
> > physical block and free its memory, which will cause filesystem breakdown.
> > 
> > This patch corrects the offset usage in zram_bio_discard.
> 
> Nice catch.
> Surely we need fix but I'd like to go further. Let's think.
> How do you find that? Real problem or code review?
> I'd like to know how much that happens in real practice because if it's
> a lot, it means discard support is just an overhead without any benefit.
> 
> If you just found it with code review(ie, don't have any data),
> would you mind adding some stat like 'num_discard/failed_discard' so
> we can keep an eye on that. Although it's for rare case, I think it's worth.
> Because someone would do swapon zram with --discard,
> it could make same problem due to early page freeing of zram-swap to
> avoid duplicating VM-owned memory and ZRAM-owned memory.
> 
> We can guide to zram-swap user not to use swapon with --discard but
> I don't want it because swap_slot_free_notify is really mess which
> violates layering so I hope replace it with discard finally so such
> statistics really help us to drive that way more quickly.
> 

I second this. if we could drop swap_slot_free_notify that'd be nice.

	-ss

> > 
> > Signed-off-by: Weijie Yang <weijie.yang@samsung.com>
> > Acked-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> > ---
> >  drivers/block/zram/zram_drv.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> > index 9849b52..48eccb3 100644
> > --- a/drivers/block/zram/zram_drv.c
> > +++ b/drivers/block/zram/zram_drv.c
> > @@ -572,10 +572,10 @@ static void zram_bio_discard(struct zram *zram, u32 index,
> >  	 * skipping this logical block is appropriate here.
> >  	 */
> >  	if (offset) {
> > -		if (n < offset)
> > +		if (n <= (PAGE_SIZE - offset))
> >  			return;
> >  
> > -		n -= offset;
> > +		n -= (PAGE_SIZE - offset);
> >  		index++;
> >  	}
> >  
> > -- 
> > 1.7.10.4
> > 
> > 
> > --
> > 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/
> 
> -- 
> Kind regards,
> Minchan Kim
> 

  reply	other threads:[~2014-04-24  7:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-23  8:41 [PATCH RESEND] zram: correct offset usage in zram_bio_discard Weijie Yang
2014-04-24  2:06 ` Minchan Kim
2014-04-24  7:31   ` Sergey Senozhatsky [this message]
2014-04-25  3:39     ` Weijie Yang

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=20140424073131.GA1098@swordfish \
    --to=sergey.senozhatsky@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bob.liu@oracle.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=ngupta@vflare.org \
    --cc=weijie.yang.kh@gmail.com \
    --cc=weijie.yang@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