From: Chao Yu <chao@kernel.org>
To: jaegeuk@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH 2/4] f2fs: atomic: fix to not allow GC to pollute atomic_file
Date: Tue, 25 Jun 2024 11:13:49 +0800 [thread overview]
Message-ID: <20240625031351.3586955-2-chao@kernel.org> (raw)
In-Reply-To: <20240625031351.3586955-1-chao@kernel.org>
SQLite App GC Thread Shrinker
- f2fs_ioc_start_atomic_write
- f2fs_ioc_commit_atomic_write
- f2fs_commit_atomic_write
- filemap_write_and_wait_range
: write atomic_file's data to cow_inode
echo 3 > drop_caches
- f2fs_gc
- gc_data_segment
- move_data_page
- set_page_dirty
: it may load data of previous
transaction into pagecache.
- f2fs_down_write(&fi->i_gc_rwsem[WRITE])
- __f2fs_commit_atomic_write
- f2fs_up_write(&fi->i_gc_rwsem[WRITE])
During committing atomic_file, GC may be triggered to migrate
atomic_file's block, so it may contain data of previous transaction
in page cache, we should drop atomic_file's cache once it was
migrated by GC.
And also, we should writeback atomic_file and cow_file's data
w/ i_gc_rwsem lock held, in order to avoid block address change
during __f2fs_commit_atomic_write().
Meahwhile, this patch adds f2fs_wait_on_block_writeback_range()
to wait completion of block migration.
Fixes: 3db1de0e582c ("f2fs: change the current atomic write way")
Signed-off-by: Chao Yu <chao@kernel.org>
---
v1:
- this patch can fix in-memory data consistency issue caused by f2fs/003
fs/f2fs/segment.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 4db1add43e36..914a13bfc2ab 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -236,6 +236,9 @@ static int __replace_atomic_write_block(struct inode *inode, pgoff_t index,
return err;
}
+ if (__is_valid_data_blkaddr(dn.data_blkaddr))
+ f2fs_wait_on_block_writeback_range(inode, dn.data_blkaddr, 1);
+
if (recover) {
/* dn.data_blkaddr is always valid */
if (!__is_valid_data_blkaddr(new_addr)) {
@@ -339,6 +342,9 @@ static int __f2fs_commit_atomic_write(struct inode *inode)
goto out;
}
+ f2fs_wait_on_block_writeback_range(cow_inode,
+ blkaddr, 1);
+
new = f2fs_kmem_cache_alloc(revoke_entry_slab, GFP_NOFS,
true, NULL);
@@ -379,16 +385,28 @@ int f2fs_commit_atomic_write(struct inode *inode)
struct f2fs_inode_info *fi = F2FS_I(inode);
int err;
+ f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
+
err = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX);
if (err)
return err;
- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
- f2fs_lock_op(sbi);
+ /* writeback GCing page of cow_inode */
+ err = filemap_write_and_wait_range(fi->cow_inode->i_mapping,
+ 0, LLONG_MAX);
+ if (err)
+ return err;
- err = __f2fs_commit_atomic_write(inode);
+ filemap_invalidate_lock(inode->i_mapping);
+
+ /* don't allow clean page loaded by GC to pollute atomic_file */
+ truncate_pagecache(inode, 0);
+ f2fs_lock_op(sbi);
+ err = __f2fs_commit_atomic_write(inode);
f2fs_unlock_op(sbi);
+
+ filemap_invalidate_unlock(inode->i_mapping);
f2fs_up_write(&fi->i_gc_rwsem[WRITE]);
return err;
--
2.40.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
WARNING: multiple messages have this Message-ID (diff)
From: Chao Yu <chao@kernel.org>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, Chao Yu <chao@kernel.org>
Subject: [PATCH 2/4] f2fs: atomic: fix to not allow GC to pollute atomic_file
Date: Tue, 25 Jun 2024 11:13:49 +0800 [thread overview]
Message-ID: <20240625031351.3586955-2-chao@kernel.org> (raw)
In-Reply-To: <20240625031351.3586955-1-chao@kernel.org>
SQLite App GC Thread Shrinker
- f2fs_ioc_start_atomic_write
- f2fs_ioc_commit_atomic_write
- f2fs_commit_atomic_write
- filemap_write_and_wait_range
: write atomic_file's data to cow_inode
echo 3 > drop_caches
- f2fs_gc
- gc_data_segment
- move_data_page
- set_page_dirty
: it may load data of previous
transaction into pagecache.
- f2fs_down_write(&fi->i_gc_rwsem[WRITE])
- __f2fs_commit_atomic_write
- f2fs_up_write(&fi->i_gc_rwsem[WRITE])
During committing atomic_file, GC may be triggered to migrate
atomic_file's block, so it may contain data of previous transaction
in page cache, we should drop atomic_file's cache once it was
migrated by GC.
And also, we should writeback atomic_file and cow_file's data
w/ i_gc_rwsem lock held, in order to avoid block address change
during __f2fs_commit_atomic_write().
Meahwhile, this patch adds f2fs_wait_on_block_writeback_range()
to wait completion of block migration.
Fixes: 3db1de0e582c ("f2fs: change the current atomic write way")
Signed-off-by: Chao Yu <chao@kernel.org>
---
v1:
- this patch can fix in-memory data consistency issue caused by f2fs/003
fs/f2fs/segment.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 4db1add43e36..914a13bfc2ab 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -236,6 +236,9 @@ static int __replace_atomic_write_block(struct inode *inode, pgoff_t index,
return err;
}
+ if (__is_valid_data_blkaddr(dn.data_blkaddr))
+ f2fs_wait_on_block_writeback_range(inode, dn.data_blkaddr, 1);
+
if (recover) {
/* dn.data_blkaddr is always valid */
if (!__is_valid_data_blkaddr(new_addr)) {
@@ -339,6 +342,9 @@ static int __f2fs_commit_atomic_write(struct inode *inode)
goto out;
}
+ f2fs_wait_on_block_writeback_range(cow_inode,
+ blkaddr, 1);
+
new = f2fs_kmem_cache_alloc(revoke_entry_slab, GFP_NOFS,
true, NULL);
@@ -379,16 +385,28 @@ int f2fs_commit_atomic_write(struct inode *inode)
struct f2fs_inode_info *fi = F2FS_I(inode);
int err;
+ f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
+
err = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX);
if (err)
return err;
- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
- f2fs_lock_op(sbi);
+ /* writeback GCing page of cow_inode */
+ err = filemap_write_and_wait_range(fi->cow_inode->i_mapping,
+ 0, LLONG_MAX);
+ if (err)
+ return err;
- err = __f2fs_commit_atomic_write(inode);
+ filemap_invalidate_lock(inode->i_mapping);
+
+ /* don't allow clean page loaded by GC to pollute atomic_file */
+ truncate_pagecache(inode, 0);
+ f2fs_lock_op(sbi);
+ err = __f2fs_commit_atomic_write(inode);
f2fs_unlock_op(sbi);
+
+ filemap_invalidate_unlock(inode->i_mapping);
f2fs_up_write(&fi->i_gc_rwsem[WRITE]);
return err;
--
2.40.1
next prev parent reply other threads:[~2024-06-25 3:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-25 3:13 [f2fs-dev] [PATCH 1/4] f2fs: atomic: fix to avoid racing w/ GC Chao Yu
2024-06-25 3:13 ` Chao Yu
2024-06-25 3:13 ` Chao Yu [this message]
2024-06-25 3:13 ` [PATCH 2/4] f2fs: atomic: fix to not allow GC to pollute atomic_file Chao Yu
2024-06-25 3:13 ` [f2fs-dev] [PATCH 3/4] f2fs: atomic: fix to truncate pagecache before on-disk metadata truncation Chao Yu
2024-06-25 3:13 ` Chao Yu
2024-07-25 20:54 ` [f2fs-dev] " Jaegeuk Kim
2024-07-25 20:54 ` Jaegeuk Kim
2024-07-26 1:06 ` [f2fs-dev] " Chao Yu
2024-07-26 1:06 ` Chao Yu
2024-06-25 3:13 ` [f2fs-dev] [PATCH 4/4] f2fs: atomic: fix to forbid dio in atomic_file Chao Yu
2024-06-25 3:13 ` Chao Yu
2024-07-02 12:13 ` [f2fs-dev] " Sunmin Jeong
2024-07-02 12:13 ` Sunmin Jeong
2024-08-05 23:30 ` [f2fs-dev] [PATCH 1/4] f2fs: atomic: fix to avoid racing w/ GC patchwork-bot+f2fs
2024-08-05 23:30 ` patchwork-bot+f2fs
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=20240625031351.3586955-2-chao@kernel.org \
--to=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@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.