From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2] btrfs: Always check nocow for quota enabled case to make sure we won't reserve unnecessary data space
Date: Tue, 21 Aug 2018 13:40:16 +0800 [thread overview]
Message-ID: <20180821054016.28058-1-wqu@suse.com> (raw)
Commit c6887cd11149 ("Btrfs: don't do nocow check unless we have to")
makes nocow check less frequent to improve performance.
However for quota enabled case, such optimization could lead to extra
unnecessary data reservation, which results failure for test case like
btrfs/153 in fstests.
Fix it by reverting to old behavior for quota enabled case.
Fixes: c6887cd11149 ("Btrfs: don't do nocow check unless we have to")
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
changelog
v2:
Fix regression for quota+cow case. (Previously it will skip data
reservation if quota is enabled, causing regression for limit case.
Pointed out by Misono)
---
fs/btrfs/file.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 2be00e873e92..183e5fb96f42 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1584,6 +1584,7 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
int ret = 0;
bool only_release_metadata = false;
bool force_page_uptodate = false;
+ bool quota_enabled = test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags);
nrptrs = min(DIV_ROUND_UP(iov_iter_count(i), PAGE_SIZE),
PAGE_SIZE / (sizeof(struct page *)));
@@ -1624,13 +1625,28 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
fs_info->sectorsize);
extent_changeset_release(data_reserved);
+
+ /*
+ * If we have quota enabled, we must do the heavy lift nocow
+ * check here to avoid reserving data space, or we can hit
+ * limitation for NOCOW files.
+ */
+ if (quota_enabled) {
+ if ((BTRFS_I(inode)->flags & (BTRFS_INODE_NODATACOW |
+ BTRFS_INODE_PREALLOC)) &&
+ check_can_nocow(BTRFS_I(inode), pos,
+ &write_bytes) > 0)
+ goto reserve_meta_only;
+ }
ret = btrfs_check_data_free_space(inode, &data_reserved, pos,
write_bytes);
if (ret < 0) {
if ((BTRFS_I(inode)->flags & (BTRFS_INODE_NODATACOW |
BTRFS_INODE_PREALLOC)) &&
check_can_nocow(BTRFS_I(inode), pos,
- &write_bytes) > 0) {
+ &write_bytes) > 0 &&
+ !quota_enabled) {
+reserve_meta_only:
/*
* For nodata cow case, no need to reserve
* data space.
--
2.18.0
next reply other threads:[~2018-08-21 8:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-21 5:40 Qu Wenruo [this message]
2018-08-24 7:14 ` [PATCH v2] btrfs: Always check nocow for quota enabled case to make sure we won't reserve unnecessary data space Misono Tomohiro
2018-08-24 7:20 ` Qu Wenruo
2018-08-24 7:54 ` Misono Tomohiro
2018-08-24 7:58 ` Qu Wenruo
2018-08-24 8:09 ` Misono Tomohiro
2018-08-28 5:21 ` Qu Wenruo
2018-08-30 1:57 ` Misono Tomohiro
2018-08-30 2:14 ` Qu Wenruo
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=20180821054016.28058-1-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).