linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v3 4/4] btrfs: avoid allocating unnecessary page pointers
Date: Tue, 25 Aug 2020 13:48:08 +0800	[thread overview]
Message-ID: <20200825054808.16241-5-wqu@suse.com> (raw)
In-Reply-To: <20200825054808.16241-1-wqu@suse.com>

Commit 142349f541d0 ("btrfs: lower the dirty balance poll interval")
introduced one limit which is definitely suspicious:

- ensure we always have 8 pages allocated
  The 8 lower limit looks pretty strange, this means even we're just
  writing 4K, we will allocate page pointers for 8 pages no matter what.
  To me, this 8 pages look more like a upper limit.

This 8 pages upper limit looks so incorrect that my eyes alawys correct
it into "min(, 8)" other than "max(, 8)".

This patch will use a fixed size (SZ_64K) other than page numbers to
setup the upper limit.
Also, with comment added to show why we need a upper limit.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/file.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 67d2368a8fa6..de6d1c313042 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1561,7 +1561,14 @@ static int calc_nr_pages(loff_t pos, struct iov_iter *iov)
 
 	nr_pages = min(nr_pages, current->nr_dirtied_pause -
 				 current->nr_dirtied);
-	nr_pages = max(nr_pages, 8);
+
+	/*
+	 * Limit the batch to 64K, too large batch may lead to higher memory
+	 * pressure and increase the possibility of short-copy.
+	 * With more and more short-copy, the benefit of batch copy would be
+	 * hugely reduced, as we will fall back to page-by-page copy.
+	 */
+	nr_pages = min(nr_pages, SZ_64K / PAGE_SIZE);
 	return nr_pages;
 }
 
-- 
2.28.0


  parent reply	other threads:[~2020-08-25  5:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-25  5:48 [PATCH v3 0/4] btrfs: basic refactor of btrfs_buffered_write() Qu Wenruo
2020-08-25  5:48 ` [PATCH v3 1/4] btrfs: refactor @nrptrs calculation " Qu Wenruo
2020-08-25  5:48 ` [PATCH v3 2/4] btrfs: refactor btrfs_buffered_write() into process_one_batch() Qu Wenruo
2020-08-25  5:48 ` [PATCH v3 3/4] btrfs: remove the again: tag in process_one_batch() Qu Wenruo
2020-08-25  5:48 ` Qu Wenruo [this message]
2020-08-25  7:46   ` [PATCH v3 4/4] btrfs: avoid allocating unnecessary page pointers kernel test robot
2020-08-25  7:57   ` kernel test robot
2020-08-26 12:31   ` kernel test robot
2020-08-25 11:44 ` [PATCH v3 0/4] btrfs: basic refactor of btrfs_buffered_write() Christoph Hellwig
2020-08-25 13:32   ` Goldwyn Rodrigues

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=20200825054808.16241-5-wqu@suse.com \
    --to=wqu@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 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).