All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 7/7] btrfs: Refactor shrink_delalloc
Date: Thu,  3 Jan 2019 10:50:05 +0200	[thread overview]
Message-ID: <20190103085005.32053-8-nborisov@suse.com> (raw)
In-Reply-To: <20190103085005.32053-1-nborisov@suse.com>

Add a couple of comments regarding the logic flow in shrink_delalloc.
Then, cease using max_reclaim as a temporary variable when calculating
nr_pages. Finally give max_reclaim a more becoming name, which
uneqivocally shows at what this variable really holds. No functional
changes.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/extent-tree.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index b15afeae16df..615441f4d458 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4743,7 +4743,7 @@ static void shrink_delalloc(struct btrfs_fs_info *fs_info, u64 to_reclaim,
 	struct btrfs_space_info *space_info;
 	struct btrfs_trans_handle *trans;
 	u64 delalloc_bytes;
-	u64 max_reclaim;
+	u64 async_pages;
 	u64 items;
 	long time_left;
 	unsigned long nr_pages;
@@ -4768,25 +4768,36 @@ static void shrink_delalloc(struct btrfs_fs_info *fs_info, u64 to_reclaim,
 
 	loops = 0;
 	while (delalloc_bytes && loops < 3) {
-		max_reclaim = min(delalloc_bytes, to_reclaim);
-		nr_pages = max_reclaim >> PAGE_SHIFT;
+		nr_pages = min(delalloc_bytes, to_reclaim) >> PAGE_SHIFT;
+
+		/*
+		 * Triggers inode writeback for up to nr_pages. This will invoke
+		 * ->writepages callback and trigger delalloc filling
+		 *  (btrfs_run_delalloc_range()).
+		 */
 		btrfs_writeback_inodes_sb_nr(fs_info, nr_pages, items);
+
 		/*
-		 * We need to wait for the async pages to actually start before
-		 * we do anything.
+		 * We need to wait for the compressed pages to start before
+		 * we continue.
 		 */
-		max_reclaim = atomic_read(&fs_info->async_delalloc_pages);
-		if (!max_reclaim)
+		async_pages = atomic_read(&fs_info->async_delalloc_pages);
+		if (!async_pages)
 			goto skip_async;
 
-		if (max_reclaim <= nr_pages)
-			max_reclaim = 0;
+		/*
+		 * Calculate how many compressed pages we want to be written
+		 * before we continue. I.e if there are more async pages than we
+		 * require wait_event will wait until nr_pages are written.
+		 */
+		if (async_pages <= nr_pages)
+			async_pages = 0;
 		else
-			max_reclaim -= nr_pages;
+			async_pages -= nr_pages;
 
 		wait_event(fs_info->async_submit_wait,
 			   atomic_read(&fs_info->async_delalloc_pages) <=
-			   (int)max_reclaim);
+			   (int)async_pages);
 skip_async:
 		spin_lock(&space_info->lock);
 		if (list_empty(&space_info->tickets) &&
-- 
2.17.1


  parent reply	other threads:[~2019-01-03  8:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-03  8:49 [PATCH 0/7] More misc fixes Nikolay Borisov
2019-01-03  8:49 ` [PATCH 1/7] btrfs: Remove inode argument from async_cow_submit Nikolay Borisov
2019-01-05  6:02   ` Anand Jain
2019-01-07 10:12   ` Johannes Thumshirn
2019-01-03  8:50 ` [PATCH 2/7] btrfs: Remove isize local variable in compress_file_range Nikolay Borisov
2019-01-05  6:17   ` Anand Jain
2019-01-07 10:17   ` Johannes Thumshirn
2019-01-07 17:41   ` David Sterba
2019-01-03  8:50 ` [PATCH 3/7] btrfs: Use ihold instead of igrab in cow_file_range_async Nikolay Borisov
2019-01-04 15:29   ` David Sterba
2019-01-03  8:50 ` [PATCH 4/7] btrfs: Remove WARN_ON in btrfs_alloc_delalloc_work Nikolay Borisov
2019-01-04 15:30   ` David Sterba
2019-01-07 10:19   ` Johannes Thumshirn
2019-01-03  8:50 ` [PATCH 5/7] btrfs: Document logic in async_cow_submit Nikolay Borisov
2019-01-03  8:50 ` [PATCH 6/7] btrfs: Replace open-coded maths with DIV_ROUND_UP Nikolay Borisov
2019-01-03 14:44   ` David Sterba
2019-01-03 15:33     ` Nikolay Borisov
2019-01-07 15:29       ` David Sterba
2019-01-03  8:50 ` Nikolay Borisov [this message]
2019-01-04 15:35   ` [PATCH 7/7] btrfs: Refactor shrink_delalloc David Sterba
2019-01-07 17:58     ` David Sterba
2019-01-07 17:59 ` [PATCH 0/7] More misc fixes David Sterba

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=20190103085005.32053-8-nborisov@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.