linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: simplify read_extent_buffer_pages a bit
@ 2019-04-11 16:40 Johannes Thumshirn
  2019-04-11 16:59 ` David Sterba
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Thumshirn @ 2019-04-11 16:40 UTC (permalink / raw)
  To: David Sterba; +Cc: Linux BTRFS Mailinglist, Johannes Thumshirn

Currently read_extent_buffer_pages() uses a 4 pass algorithm to read an
extent buffer's pages from disk, all 4 stages looping over all pages of
the extent buffer.

1) Loop over all pages and lock them.
2) Loop over all pages and see if one is not marked as PageUptodate, so we
   can break out of the function early.
3) Loop over all pages and if the page is !PageUptodate read the page,
   otherwise unlock the page.
4) Loop over all pages and wait for stable pages.

Unify the 1st two for loops, we can count the number of uptodate pages
after we have locked them without the need for re-starting the loop.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 fs/btrfs/extent_io.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 828708f6510c..1d538bda4929 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -5357,14 +5357,12 @@ int read_extent_buffer_pages(struct extent_io_tree *tree,
 			lock_page(page);
 		}
 		locked_pages++;
-	}
-	/*
-	 * We need to firstly lock all pages to make sure that
-	 * the uptodate bit of our pages won't be affected by
-	 * clear_extent_buffer_uptodate().
-	 */
-	for (i = 0; i < num_pages; i++) {
-		page = eb->pages[i];
+
+		/*
+		 * We need to firstly lock all pages to make sure that
+		 * the uptodate bit of our pages won't be affected by
+		 * clear_extent_buffer_uptodate().
+		 */
 		if (!PageUptodate(page)) {
 			num_reads++;
 			all_uptodate = 0;
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: simplify read_extent_buffer_pages a bit
  2019-04-11 16:40 [PATCH] btrfs: simplify read_extent_buffer_pages a bit Johannes Thumshirn
@ 2019-04-11 16:59 ` David Sterba
  2019-04-16  9:16   ` Johannes Thumshirn
  0 siblings, 1 reply; 4+ messages in thread
From: David Sterba @ 2019-04-11 16:59 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: David Sterba, Linux BTRFS Mailinglist

On Thu, Apr 11, 2019 at 06:40:59PM +0200, Johannes Thumshirn wrote:
> Currently read_extent_buffer_pages() uses a 4 pass algorithm to read an
> extent buffer's pages from disk, all 4 stages looping over all pages of
> the extent buffer.
> 
> 1) Loop over all pages and lock them.
> 2) Loop over all pages and see if one is not marked as PageUptodate, so we
>    can break out of the function early.
> 3) Loop over all pages and if the page is !PageUptodate read the page,
>    otherwise unlock the page.
> 4) Loop over all pages and wait for stable pages.
> 
> Unify the 1st two for loops, we can count the number of uptodate pages
> after we have locked them without the need for re-starting the loop.

Effectively reverting 2571e739677f1e4c0c63f5ed49adcc0857923625 that
fixed a bug. Please have a look if something has really changed so that
the split loops are no longer necessary.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: simplify read_extent_buffer_pages a bit
  2019-04-11 16:59 ` David Sterba
@ 2019-04-16  9:16   ` Johannes Thumshirn
  2019-04-17 12:20     ` David Sterba
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Thumshirn @ 2019-04-16  9:16 UTC (permalink / raw)
  To: dsterba, David Sterba, Linux BTRFS Mailinglist


On Thu, Apr 11, 2019 at 06:59:35PM +0200, David Sterba wrote:
> On Thu, Apr 11, 2019 at 06:40:59PM +0200, Johannes Thumshirn wrote:
> > Currently read_extent_buffer_pages() uses a 4 pass algorithm to read an
> > extent buffer's pages from disk, all 4 stages looping over all pages of
> > the extent buffer.
> > 
> > 1) Loop over all pages and lock them.
> > 2) Loop over all pages and see if one is not marked as PageUptodate, so we
> >    can break out of the function early.
> > 3) Loop over all pages and if the page is !PageUptodate read the page,
> >    otherwise unlock the page.
> > 4) Loop over all pages and wait for stable pages.
> > 
> > Unify the 1st two for loops, we can count the number of uptodate pages
> > after we have locked them without the need for re-starting the loop.
> 
> Effectively reverting 2571e739677f1e4c0c63f5ed49adcc0857923625 that
> fixed a bug. Please have a look if something has really changed so that
> the split loops are no longer necessary.

After starring at the .s and .lst files GCC produces I cannot say whether this
holds true or not.

But as it was fixing a bug back then, I'll take back this patch.

-- 
Johannes Thumshirn                            SUSE Labs Filesystems
jthumshirn@suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: simplify read_extent_buffer_pages a bit
  2019-04-16  9:16   ` Johannes Thumshirn
@ 2019-04-17 12:20     ` David Sterba
  0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2019-04-17 12:20 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: dsterba, David Sterba, Linux BTRFS Mailinglist

On Tue, Apr 16, 2019 at 11:16:33AM +0200, Johannes Thumshirn wrote:
> 
> On Thu, Apr 11, 2019 at 06:59:35PM +0200, David Sterba wrote:
> > On Thu, Apr 11, 2019 at 06:40:59PM +0200, Johannes Thumshirn wrote:
> > > Currently read_extent_buffer_pages() uses a 4 pass algorithm to read an
> > > extent buffer's pages from disk, all 4 stages looping over all pages of
> > > the extent buffer.
> > > 
> > > 1) Loop over all pages and lock them.
> > > 2) Loop over all pages and see if one is not marked as PageUptodate, so we
> > >    can break out of the function early.
> > > 3) Loop over all pages and if the page is !PageUptodate read the page,
> > >    otherwise unlock the page.
> > > 4) Loop over all pages and wait for stable pages.
> > > 
> > > Unify the 1st two for loops, we can count the number of uptodate pages
> > > after we have locked them without the need for re-starting the loop.
> > 
> > Effectively reverting 2571e739677f1e4c0c63f5ed49adcc0857923625 that
> > fixed a bug. Please have a look if something has really changed so that
> > the split loops are no longer necessary.
> 
> After starring at the .s and .lst files GCC produces I cannot say whether this
> holds true or not.

I'm not sure this is about the assembly. Currently all pages are locked
first, then the bits are checked. Merging that locking and setting bit
to the same iteration has different effect to the outside, as mentioned
in the commit.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-04-17 12:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-11 16:40 [PATCH] btrfs: simplify read_extent_buffer_pages a bit Johannes Thumshirn
2019-04-11 16:59 ` David Sterba
2019-04-16  9:16   ` Johannes Thumshirn
2019-04-17 12:20     ` David Sterba

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).