Skip to contentSkip to conversation

btrfs: cleanup extent locking sequence

PATCH Superseded Goldwyn Rodrigues 2 participants 2 messages Oct 11, 2017 – Oct 13, 2017 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: cleanup extent locking sequence

From: Goldwyn Rodrigues <[email protected]>

Code cleanup for better understanding:
needs_unlock to be called extent_locked to show state as opposed to action.
Changed the variable to int, to reduce code in the critical path(code usually executed).

---
 fs/btrfs/file.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
fs/btrfs/file.c +6 -8
index f6c6754cf52d..a3d006d14683 100644
@@ -1590,7 +1590,7 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
 	int ret = 0;
 	bool only_release_metadata = false;
 	bool force_page_uptodate = false;
-	bool need_unlock;
+	int extents_locked;
 
 	nrptrs = min(DIV_ROUND_UP(iov_iter_count(i), PAGE_SIZE),
 			PAGE_SIZE / (sizeof(struct page *)));
@@ -1670,7 +1670,6 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
 		}
 
 		release_bytes = reserve_bytes;
-		need_unlock = false;
 again:
 		/*
 		 * This is going to setup the pages array with the number of
@@ -1683,16 +1682,15 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
 		if (ret)
 			break;
 
-		ret = lock_and_cleanup_extent_if_need(BTRFS_I(inode), pages,
+		extents_locked = lock_and_cleanup_extent_if_need(
+				BTRFS_I(inode), pages,
 				num_pages, pos, write_bytes, &lockstart,
 				&lockend, &cached_state);
-		if (ret < 0) {
+		if (extents_locked < 0) {
 			if (ret == -EAGAIN)
 				goto again;
+			ret = extents_locked;
 			break;
-		} else if (ret > 0) {
-			need_unlock = true;
-			ret = 0;
 		}
 
 		copied = btrfs_copy_from_user(pos, write_bytes, pages, i);
@@ -1754,7 +1752,7 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
 		if (copied > 0)
 			ret = btrfs_dirty_pages(inode, pages, dirty_pages,
 						pos, copied, NULL);
-		if (need_unlock)
+		if (extents_locked)
 			unlock_extent_cached(&BTRFS_I(inode)->io_tree,
 					     lockstart, lockend, &cached_state,
 					     GFP_NOFS);
Signature · 1 line
2.14.2
#1 lore raw
Quoted 18 lines · Goldwyn Rodrigues

From: Goldwyn Rodrigues <[email protected]>

Code cleanup for better understanding:
needs_unlock to be called extent_locked to show state as opposed to action.
Changed the variable to int, to reduce code in the critical path(code usually executed).

---
 fs/btrfs/file.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
fs/btrfs/file.c +0 -0
index f6c6754cf52d..a3d006d14683 100644

fs/btrfs/file.c static noinline ssize_t __btrfs_buffered_write(struct file *file, · line 1593

Quoted 5 lines
fs/btrfs/file.c +1 -1
@@ -1590,7 +1590,7 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
 	int ret = 0;
 	bool only_release_metadata = false;
 	bool force_page_uptodate = false;
-	bool need_unlock;
+	int extents_locked;

The variable can be moved to the while() { } block

Quoted 13 lines
fs/btrfs/file.c +0 -1
 	nrptrs = min(DIV_ROUND_UP(iov_iter_count(i), PAGE_SIZE),
 			PAGE_SIZE / (sizeof(struct page *)));
@@ -1670,7 +1670,6 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
 		}
 
 		release_bytes = reserve_bytes;
-		need_unlock = false;
 again:
 		/*
 		 * This is going to setup the pages array with the number of
@@ -1683,16 +1682,15 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
 		if (ret)

fs/btrfs/file.c static noinline ssize_t __btrfs_buffered_write(struct file *file, · line 1690

Quoted 10 lines
fs/btrfs/file.c +3 -2
 			break;
 
-		ret = lock_and_cleanup_extent_if_need(BTRFS_I(inode), pages,
+		extents_locked = lock_and_cleanup_extent_if_need(
+				BTRFS_I(inode), pages,
 				num_pages, pos, write_bytes, &lockstart,
 				&lockend, &cached_state);
-		if (ret < 0) {
+		if (extents_locked < 0) {
 			if (ret == -EAGAIN)

either

		if (extents_locked == -EAGAIN)

or

move 'ret = extents_locked' above the if.

Quoted 7 lines
fs/btrfs/file.c +1 -3
 				goto again;
+			ret = extents_locked;
 			break;
-		} else if (ret > 0) {
-			need_unlock = true;
-			ret = 0;
 		}