Skip to contentSkip to conversation

btrfs: Do not check for PagePrivate twice

PATCH In review Goldwyn Rodrigues 3 participants 5 messages Oct 18, 2019 – Nov 28, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: Do not check for PagePrivate twice

From: Goldwyn Rodrigues <[email protected]>

We are checking PagePrivate twice, once with lock and once without. Perform the check only once.

---
 fs/btrfs/extent_io.c | 3 ---
 1 file changed, 3 deletions(-)
fs/btrfs/extent_io.c +0 -3
index cceaf05aada2..425ba359178c 100644
@@ -3959,9 +3959,6 @@ int btree_write_cache_pages(struct address_space *mapping,
 		for (i = 0; i < nr_pages; i++) {
 			struct page *page = pvec.pages[i];
 
-			if (!PagePrivate(page))
-				continue;
-
 			spin_lock(&mapping->private_lock);
 			if (!PagePrivate(page)) {
 				spin_unlock(&mapping->private_lock);
Signature · 1 line
2.16.4
#1 lore raw

PATCH 1/1 btrfs: Do not check for writeback in btrfs_releasepage()

From: Goldwyn Rodrigues <[email protected]>

We check for PageWriteback in try_to_release_page(), the sole caller of address_space->releasepage(). We don't need to check it again in btrfs_releasepage()

---
 fs/btrfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/inode.c +1 -1
index 0f2754eaa05b..10303c2379a9 100644
@@ -8793,7 +8793,7 @@ static int __btrfs_releasepage(struct page *page, gfp_t gfp_flags)
 
 static int btrfs_releasepage(struct page *page, gfp_t gfp_flags)
 {
-	if (PageWriteback(page) || PageDirty(page))
+	if (PageDirty(page))
 		return 0;
 	return __btrfs_releasepage(page, gfp_flags);
 }
Signature · 1 line
2.16.4
#2 lore raw

Re: [PATCH] btrfs: Do not check for writeback in btrfs_releasepage()

Scratch this. btrfs_releasepage() is called from btrfs_invalidatepage() as well. Sorry for the noise.

Quoted 27 lines · Goldwyn Rodrigues

From: Goldwyn Rodrigues <[email protected]>

We check for PageWriteback in try_to_release_page(), the sole caller of address_space->releasepage(). We don't need to check it again in btrfs_releasepage()

---
 fs/btrfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/inode.c +1 -1
index 0f2754eaa05b..10303c2379a9 100644
@@ -8793,7 +8793,7 @@ static int __btrfs_releasepage(struct page *page, gfp_t gfp_flags)
 
 static int btrfs_releasepage(struct page *page, gfp_t gfp_flags)
 {
-	if (PageWriteback(page) || PageDirty(page))
+	if (PageDirty(page))
 		return 0;
 	return __btrfs_releasepage(page, gfp_flags);
 }
Signature · 1 line
2.16.4
Signature · 1 line
Goldwyn
#3 lore raw
In reply to Goldwyn Rodrigues
Quoted 5 lines · Goldwyn Rodrigues

From: Goldwyn Rodrigues <[email protected]>

We are checking PagePrivate twice, once with lock and once without. Perform the check only once.

Have you checked if there's some performance degradation after removing the check?
My guess is it's there to avoid taking the lock, as the lock can be heavily used on a system under heavy load (maybe even if it's not too heavy, since we generate a lot of dirty metadata due to cow). The page may have been released after locking the mapping, that's why we check it twice, and after unlocking we are sure it can not be released due to taking a reference on the extent buffer.

Thanks.

Quoted 23 lines
---
 fs/btrfs/extent_io.c | 3 ---
 1 file changed, 3 deletions(-)
fs/btrfs/extent_io.c +0 -4
index cceaf05aada2..425ba359178c 100644
@@ -3959,9 +3959,6 @@ int btree_write_cache_pages(struct address_space *mapping,
                for (i = 0; i < nr_pages; i++) {
                        struct page *page = pvec.pages[i];
 
-                       if (!PagePrivate(page))
-                               continue;
-
                        spin_lock(&mapping->private_lock);
                        if (!PagePrivate(page)) {
                                spin_unlock(&mapping->private_lock);
--

2.16.4

Signature · 3 lines
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”
#4 lore raw
Quoted 4 lines · Filipe Manana
Quoted 2 lines · Goldwyn Rodrigues

We are checking PagePrivate twice, once with lock and once without. Perform the check only once.

Quoted 8 lines

Have you checked if there's some performance degradation after removing the check?
My guess is it's there to avoid taking the lock, as the lock can be heavily used on a system under heavy load (maybe even if it's not too heavy, since we generate a lot of dirty metadata due to cow). The page may have been released after locking the mapping, that's why we check it twice, and after unlocking we are sure it can not be released due to taking a reference on the extent buffer.

That's my understanding as well, so the duplicate unlocked check should stay.