From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
To: linux-fsdevel@vger.kernel.org
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>,
Hans Holmberg <hans.holmberg@wdc.com>
Subject: [PATCH] zonefs: Always invalidate last cache page on append write
Date: Wed, 29 Mar 2023 14:58:23 +0900 [thread overview]
Message-ID: <20230329055823.1677193-1-damien.lemoal@opensource.wdc.com> (raw)
When a direct append write is executed, the append offset may correspond
to the last page of an inode which might have been cached already by
buffered reads, page faults with mmap-read or non-direct readahead.
To ensure that the on-disk and cached data is consistant for such last
cached page, make sure to always invalidate it in
zonefs_file_dio_append(). This invalidation will always be a no-op when
the device block size is equal to the page size (e.g. 4K).
Reported-by: Hans Holmberg <Hans.Holmberg@wdc.com>
Fixes: 02ef12a663c7 ("zonefs: use REQ_OP_ZONE_APPEND for sync DIO")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
---
fs/zonefs/file.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c
index 617e4f9db42e..eeab8b93493b 100644
--- a/fs/zonefs/file.c
+++ b/fs/zonefs/file.c
@@ -390,6 +390,18 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from)
max = ALIGN_DOWN(max << SECTOR_SHIFT, inode->i_sb->s_blocksize);
iov_iter_truncate(from, max);
+ /*
+ * If the inode block size (sector size) is smaller than the
+ * page size, we may be appending data belonging to an already
+ * cached last page of the inode. So make sure to invalidate that
+ * last cached page. This will always be a no-op for the case where
+ * the block size is equal to the page size.
+ */
+ ret = invalidate_inode_pages2_range(inode->i_mapping,
+ iocb->ki_pos >> PAGE_SHIFT, -1);
+ if (ret)
+ return ret;
+
nr_pages = iov_iter_npages(from, BIO_MAX_VECS);
if (!nr_pages)
return 0;
--
2.39.2
next reply other threads:[~2023-03-29 5:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-29 5:58 Damien Le Moal [this message]
2023-03-29 6:14 ` [PATCH] zonefs: Always invalidate last cache page on append write Johannes Thumshirn
2023-03-29 8:14 ` Christoph Hellwig
2023-03-29 8:27 ` Damien Le Moal
2023-03-29 9:49 ` Damien Le Moal
2023-03-29 23:36 ` Christoph Hellwig
2023-03-29 23:57 ` Damien Le Moal
2023-03-30 0:07 ` Christoph Hellwig
2023-03-30 0:22 ` Damien Le Moal
2023-03-29 11:04 ` Hans Holmberg
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=20230329055823.1677193-1-damien.lemoal@opensource.wdc.com \
--to=damien.lemoal@opensource.wdc.com \
--cc=hans.holmberg@wdc.com \
--cc=johannes.thumshirn@wdc.com \
--cc=linux-fsdevel@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).