Skip to content

Commit 052a82d

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix to writeout dirty inode during node flush
As Eric reported: On xfstest generic/204 on f2fs, I'm getting a kernel BUG. allocate_segment_by_default+0x9d/0x100 [f2fs] f2fs_allocate_data_block+0x3c0/0x5c0 [f2fs] do_write_page+0x62/0x110 [f2fs] f2fs_do_write_node_page+0x2b/0xa0 [f2fs] __write_node_page+0x2ec/0x590 [f2fs] f2fs_sync_node_pages+0x756/0x7e0 [f2fs] block_operations+0x25b/0x350 [f2fs] f2fs_write_checkpoint+0x104/0x1150 [f2fs] f2fs_sync_fs+0xa2/0x120 [f2fs] f2fs_balance_fs_bg+0x33c/0x390 [f2fs] f2fs_write_node_pages+0x4c/0x1f0 [f2fs] do_writepages+0x1c/0x70 __writeback_single_inode+0x45/0x320 writeback_sb_inodes+0x273/0x5c0 wb_writeback+0xff/0x2e0 wb_workfn+0xa1/0x370 process_one_work+0x138/0x350 worker_thread+0x4d/0x3d0 kthread+0x109/0x140 The root cause of this issue is, in a very small partition, e.g. in generic/204 testcase of fstest suit, filesystem's free space is 50MB, so at most we can write 12800 inline inode with command: `echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX > $SCRATCH_MNT/$i`, then filesystem will have: - 12800 dirty inline data page - 12800 dirty inode page - and 12800 dirty imeta (dirty inode) When we flush node-inode's page cache, we can also flush inline data with each inode page, however it will run out-of-free-space in device, then once it triggers checkpoint, there is no room for huge number of imeta, at this time, GC is useless, as there is no dirty segment at all. In order to fix this, we try to recognize inode page during node_inode's page flushing, and update inode page from dirty inode, so that later another imeta (dirty inode) flush can be avoided. Reported-and-tested-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 950d47f commit 052a82d

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

‎fs/f2fs/node.c‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,47 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
17621762
return ret ? -EIO: 0;
17631763
}
17641764

1765+
static int f2fs_match_ino(struct inode *inode, unsigned long ino, void *data)
1766+
{
1767+
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1768+
bool clean;
1769+
1770+
if (inode->i_ino != ino)
1771+
return 0;
1772+
1773+
if (!is_inode_flag_set(inode, FI_DIRTY_INODE))
1774+
return 0;
1775+
1776+
spin_lock(&sbi->inode_lock[DIRTY_META]);
1777+
clean = list_empty(&F2FS_I(inode)->gdirty_list);
1778+
spin_unlock(&sbi->inode_lock[DIRTY_META]);
1779+
1780+
if (clean)
1781+
return 0;
1782+
1783+
inode = igrab(inode);
1784+
if (!inode)
1785+
return 0;
1786+
return 1;
1787+
}
1788+
1789+
static bool flush_dirty_inode(struct page *page)
1790+
{
1791+
struct f2fs_sb_info *sbi = F2FS_P_SB(page);
1792+
struct inode *inode;
1793+
nid_t ino = ino_of_node(page);
1794+
1795+
inode = find_inode_nowait(sbi->sb, ino, f2fs_match_ino, NULL);
1796+
if (!inode)
1797+
return false;
1798+
1799+
f2fs_update_inode(inode, page);
1800+
unlock_page(page);
1801+
1802+
iput(inode);
1803+
return true;
1804+
}
1805+
17651806
int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
17661807
struct writeback_control *wbc,
17671808
bool do_balance, enum iostat_type io_type)
@@ -1785,6 +1826,7 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
17851826
for (i = 0; i < nr_pages; i++) {
17861827
struct page *page = pvec.pages[i];
17871828
bool submitted = false;
1829+
bool may_dirty = true;
17881830

17891831
/* give a priority to WB_SYNC threads */
17901832
if (atomic_read(&sbi->wb_sync_req[NODE]) &&
@@ -1832,6 +1874,13 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
18321874
goto lock_node;
18331875
}
18341876

1877+
/* flush dirty inode */
1878+
if (IS_INODE(page) && may_dirty) {
1879+
may_dirty = false;
1880+
if (flush_dirty_inode(page))
1881+
goto lock_node;
1882+
}
1883+
18351884
f2fs_wait_on_page_writeback(page, NODE, true, true);
18361885

18371886
if (!clear_page_dirty_for_io(page))

0 commit comments

Comments
 (0)