public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: Nikolay Borisov <nborisov@suse.com>,
	David Sterba <dsterba@suse.com>,
	linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/3] btrfs: simplify counting number of eb pages
Date: Tue, 24 Apr 2018 12:29:12 +0200	[thread overview]
Message-ID: <20180424102912.GA21272@twin.jikos.cz> (raw)
In-Reply-To: <8d6068cc-c383-393c-2776-55851093b7a2@gmx.com>

On Tue, Apr 24, 2018 at 02:22:15PM +0800, Qu Wenruo wrote:
> 
> 
> On 2018年04月24日 13:59, Nikolay Borisov wrote:
> > 
> > 
> > On 24.04.2018 02:03, David Sterba wrote:
> >> The eb length is nodesize, as initialized in __alloc_extent_buffer.
> >> Regardless of start, we should always get the same number of pages, so
> >> use that fact.
> >>
> >> Signed-off-by: David Sterba <dsterba@suse.com>
> >> ---
> >>  fs/btrfs/extent_io.h | 3 +--
> >>  1 file changed, 1 insertion(+), 2 deletions(-)
> >>
> >> diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
> >> index a53009694b16..ee92c1289edd 100644
> >> --- a/fs/btrfs/extent_io.h
> >> +++ b/fs/btrfs/extent_io.h
> >> @@ -454,8 +454,7 @@ void wait_on_extent_buffer_writeback(struct extent_buffer *eb);
> >>  
> >>  static inline unsigned long num_extent_pages(u64 start, u64 len)
> >>  {
> >> -	return ((start + len + PAGE_SIZE - 1) >> PAGE_SHIFT) -
> >> -		(start >> PAGE_SHIFT);
> >> +	return len >> PAGE_SHIFT;
> > 
> > Shouldn't this really be len + PAGE_SIZE -1 or in fact DIV_ROUND_DOWN
> > (len, PAGE_SIZE). Because with a nodesize of 4k (and basically less than
> > a page size) we can get into a situation where we do:
> > 
> > 4096 >> 13 = 0
> > 
> > On powerpc for example we have:
> > 
> > arch/powerpc/include/asm/page.h:#define PAGE_SHIFT              18
> > arch/powerpc/include/asm/page.h:#define PAGE_SHIFT              16
> > arch/powerpc/include/asm/page.h:#define PAGE_SHIFT              14
> 
> For such case, the fs won't be mounted as we don't have sub-pagesized
> nodesize support yet.
> So won't hit the problem.
> 
> Although a WARN_ON(len < PAGE_SIZE || IS_ALIGNED(start, PAGE_SIZE))
> would do no harm here.

Such check is fine, but would be better placed in __alloc_extent_buffer,
not each time we access the eb.

  reply	other threads:[~2018-04-24 10:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-23 23:03 [PATCH 0/3] Simplify counting of extent buffer pages David Sterba
2018-04-23 23:03 ` [PATCH 1/3] btrfs: simplify counting number of eb pages David Sterba
2018-04-24  5:59   ` Nikolay Borisov
2018-04-24  6:22     ` Qu Wenruo
2018-04-24 10:29       ` David Sterba [this message]
2018-04-24 10:36         ` Qu Wenruo
2018-04-23 23:03 ` [PATCH 2/3] btrfs: pass only eb to num_extent_pages David Sterba
2018-04-24 13:26   ` Nikolay Borisov
2018-04-23 23:03 ` [PATCH 3/3] btrfs: switch types to int when counting eb pages David Sterba
2018-04-24 13:26   ` Nikolay Borisov

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=20180424102912.GA21272@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    --cc=quwenruo.btrfs@gmx.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