From: Daeho Jeong <daeho43@gmail.com>
To: linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com
Cc: Daeho Jeong <daehojeong@google.com>, stable@vger.kernel.org
Subject: [PATCH] f2fs: don't skip the inode update for a size grown within a block
Date: Sun, 15 Nov 2026 16:05:34 -0800 [thread overview]
Message-ID: <20261116000534.2303800-1-daeho43@gmail.com> (raw)
From: Daeho Jeong <daehojeong@google.com>
f2fs_skip_inode_update() lets fsync() skip writing the inode when
FI_AUTO_RECOVER is set and i_size is block aligned, relying on roll-forward
recovery to recover i_size from the position of the fsynced data block.
However, do_recover_data() extends i_size only by a block that starts at or
beyond the recovered i_size, so it cannot recover a size that grew within
the block holding the old size.
For example, on a 4KB block filesystem:
write(fd, buf, 14KB); fsync(fd);
write(fd, buf, 2KB); fsync(fd);
<sudden power-off>
- the first fsync() writes the inode with i_size 14KB.
- the second write() makes i_size 16KB in the same block. If it is in
the same timestamp tick as the first one, the timestamps do not change
and the inode is still clean, so FI_AUTO_RECOVER is set.
- the block is already allocated, so the second fsync() updates it in
place and writes no node. f2fs_skip_inode_update() skips the inode as
well, since i_size is block aligned and equals last_disk_size.
- recovery finds i_size 14KB in the inode from the first fsync() and has
no block to extend it with, so the last 2KB is lost.
Repeating a 2KB append and fsync() up to 16KB and then shutting down the
filesystem left 117 of 1200 files with 14KB on a 4KB page kernel, and none
with this patch.
Set FI_AUTO_RECOVER only if the old i_size is block aligned, and clear it
otherwise, so that fsync() writes the inode for such a size change.
Fixes: 3a3a5ead7b6d ("f2fs: do not recover i_size if it's valid")
Cc: stable@vger.kernel.org
Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
fs/f2fs/f2fs.h | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 50a5f845176d..b328e678d295 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -3676,8 +3676,9 @@ static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size)
{
bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
+ loff_t old_size = i_size_read(inode);
- if (i_size_read(inode) == i_size)
+ if (old_size == i_size)
return;
i_size_write(inode, i_size);
@@ -3686,8 +3687,16 @@ static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size)
return;
f2fs_mark_inode_dirty_sync(inode, true);
- if (clean || recover)
+
+ /*
+ * Roll-forward recovery extends i_size only by a block that starts at
+ * or beyond the recovered i_size, so it cannot recover a size that grew
+ * within the block holding the old size.
+ */
+ if ((clean || recover) && !(old_size & ~PAGE_MASK))
set_inode_flag(inode, FI_AUTO_RECOVER);
+ else
+ clear_inode_flag(inode, FI_AUTO_RECOVER);
}
static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth)
base-commit: b9d7379d10d43386b59082da8c9a0b111e054781
--
2.56.0.611.g1030f0b940-goog
reply other threads:[~2026-11-16 0:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261116000534.2303800-1-daeho43@gmail.com \
--to=daeho43@gmail.com \
--cc=daehojeong@google.com \
--cc=kernel-team@android.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@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
all inboxes | Powered by JetHome®