mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
BACKPORT: f2fs: use meta inode for GC of atomic file
The page cache of the atomic file keeps new data pages which will be
stored in the COW file. It can also keep old data pages when GCing the
atomic file. In this case, new data can be overwritten by old data if a
GC thread sets the old data page as dirty after new data page was
evicted.
Also, since all writes to the atomic file are redirected to COW inodes,
GC for the atomic file is not working well as below.
f2fs_gc(gc_type=FG_GC)
- select A as a victim segment
do_garbage_collect
- iget atomic file's inode for block B
move_data_page
f2fs_do_write_data_page
- use dn of cow inode
- set fio->old_blkaddr from cow inode
- seg_freed is 0 since block B is still valid
- goto gc_more and A is selected as victim again
To solve the problem, let's separate GC writes and updates in the atomic
file by using the meta inode for GC writes.
Fixes: 3db1de0e58 ("f2fs: change the current atomic write way")
Cc: stable@vger.kernel.org #v5.19+
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Reviewed-by: Yeongjin Gil <youngjin.gil@samsung.com>
Signed-off-by: Sunmin Jeong <s_min.jeong@samsung.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Bug: 369150601
Change-Id: I0bcc1da7a59df3254d736ba3fb1d81a6d31bbbcd
(cherry picked from commit b40a2b00370931b0c50148681dd7364573e52e6b)
Signed-off-by: Daeho Jeong <daehojeong@google.com>
This commit is contained in:
committed by
Daeho Jeong
parent
30f8a76da5
commit
9b5ee2f2b1
@@ -2756,7 +2756,7 @@ got_it:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* wait for GCed page writeback via META_MAPPING */
|
/* wait for GCed page writeback via META_MAPPING */
|
||||||
if (fio->post_read)
|
if (fio->meta_gc)
|
||||||
f2fs_wait_on_block_writeback(inode, fio->old_blkaddr);
|
f2fs_wait_on_block_writeback(inode, fio->old_blkaddr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2852,7 +2852,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted,
|
|||||||
.submitted = 0,
|
.submitted = 0,
|
||||||
.compr_blocks = compr_blocks,
|
.compr_blocks = compr_blocks,
|
||||||
.need_lock = compr_blocks ? LOCK_DONE : LOCK_RETRY,
|
.need_lock = compr_blocks ? LOCK_DONE : LOCK_RETRY,
|
||||||
.post_read = f2fs_post_read_required(inode) ? 1 : 0,
|
.meta_gc = f2fs_meta_inode_gc_required(inode) ? 1 : 0,
|
||||||
.io_type = io_type,
|
.io_type = io_type,
|
||||||
.io_wbc = wbc,
|
.io_wbc = wbc,
|
||||||
.bio = bio,
|
.bio = bio,
|
||||||
|
|||||||
@@ -1205,7 +1205,7 @@ struct f2fs_io_info {
|
|||||||
unsigned int is_por:1; /* indicate IO is from recovery or not */
|
unsigned int is_por:1; /* indicate IO is from recovery or not */
|
||||||
unsigned int retry:1; /* need to reallocate block address */
|
unsigned int retry:1; /* need to reallocate block address */
|
||||||
unsigned int encrypted:1; /* indicate file is encrypted */
|
unsigned int encrypted:1; /* indicate file is encrypted */
|
||||||
unsigned int post_read:1; /* require post read */
|
unsigned int meta_gc:1; /* require meta inode GC */
|
||||||
enum iostat_type io_type; /* io type */
|
enum iostat_type io_type; /* io type */
|
||||||
struct writeback_control *io_wbc; /* writeback control */
|
struct writeback_control *io_wbc; /* writeback control */
|
||||||
struct bio **bio; /* bio for ipu */
|
struct bio **bio; /* bio for ipu */
|
||||||
@@ -4227,6 +4227,11 @@ static inline bool f2fs_post_read_required(struct inode *inode)
|
|||||||
f2fs_compressed_file(inode);
|
f2fs_compressed_file(inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool f2fs_meta_inode_gc_required(struct inode *inode)
|
||||||
|
{
|
||||||
|
return f2fs_post_read_required(inode) || f2fs_is_atomic_file(inode);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* compress.c
|
* compress.c
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1586,7 +1586,7 @@ next_step:
|
|||||||
start_bidx = f2fs_start_bidx_of_node(nofs, inode) +
|
start_bidx = f2fs_start_bidx_of_node(nofs, inode) +
|
||||||
ofs_in_node;
|
ofs_in_node;
|
||||||
|
|
||||||
if (f2fs_post_read_required(inode)) {
|
if (f2fs_meta_inode_gc_required(inode)) {
|
||||||
int err = ra_data_block(inode, start_bidx);
|
int err = ra_data_block(inode, start_bidx);
|
||||||
|
|
||||||
f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
|
f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
|
||||||
@@ -1637,7 +1637,7 @@ next_step:
|
|||||||
|
|
||||||
start_bidx = f2fs_start_bidx_of_node(nofs, inode)
|
start_bidx = f2fs_start_bidx_of_node(nofs, inode)
|
||||||
+ ofs_in_node;
|
+ ofs_in_node;
|
||||||
if (f2fs_post_read_required(inode))
|
if (f2fs_meta_inode_gc_required(inode))
|
||||||
err = move_data_block(inode, start_bidx,
|
err = move_data_block(inode, start_bidx,
|
||||||
gc_type, segno, off);
|
gc_type, segno, off);
|
||||||
else
|
else
|
||||||
@@ -1645,7 +1645,7 @@ next_step:
|
|||||||
segno, off);
|
segno, off);
|
||||||
|
|
||||||
if (!err && (gc_type == FG_GC ||
|
if (!err && (gc_type == FG_GC ||
|
||||||
f2fs_post_read_required(inode)))
|
f2fs_meta_inode_gc_required(inode)))
|
||||||
submitted++;
|
submitted++;
|
||||||
|
|
||||||
if (locked) {
|
if (locked) {
|
||||||
|
|||||||
@@ -3569,7 +3569,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio)
|
|||||||
goto drop_bio;
|
goto drop_bio;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fio->post_read)
|
if (fio->meta_gc)
|
||||||
invalidate_mapping_pages(META_MAPPING(sbi),
|
invalidate_mapping_pages(META_MAPPING(sbi),
|
||||||
fio->new_blkaddr, fio->new_blkaddr);
|
fio->new_blkaddr, fio->new_blkaddr);
|
||||||
|
|
||||||
@@ -3738,7 +3738,7 @@ void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr)
|
|||||||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||||
struct page *cpage;
|
struct page *cpage;
|
||||||
|
|
||||||
if (!f2fs_post_read_required(inode))
|
if (!f2fs_meta_inode_gc_required(inode))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!__is_valid_data_blkaddr(blkaddr))
|
if (!__is_valid_data_blkaddr(blkaddr))
|
||||||
@@ -3757,7 +3757,7 @@ void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr,
|
|||||||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||||
block_t i;
|
block_t i;
|
||||||
|
|
||||||
if (!f2fs_post_read_required(inode))
|
if (!f2fs_meta_inode_gc_required(inode))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
|
|||||||
Reference in New Issue
Block a user