Commit 687de7f1 authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: avoid IO split due to mixed WB_SYNC_ALL and WB_SYNC_NONE

If two threads try to flush dirty pages in different inodes respectively,
f2fs_write_data_pages() will produce WRITE and WRITE_SYNC one at a time,
resulting in a lot of 4KB seperated IOs.

So, this patch gives higher priority to WB_SYNC_ALL IOs and gathers write
IOs with a big WRITE_SYNC'ed bio.
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent ef095d19
...@@ -1605,7 +1605,9 @@ static int f2fs_write_cache_pages(struct address_space *mapping, ...@@ -1605,7 +1605,9 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
last_idx = page->index; last_idx = page->index;
} }
if (--wbc->nr_to_write <= 0 && /* give a priority to WB_SYNC threads */
if ((atomic_read(&F2FS_M_SB(mapping)->wb_sync_req) ||
--wbc->nr_to_write <= 0) &&
wbc->sync_mode == WB_SYNC_NONE) { wbc->sync_mode == WB_SYNC_NONE) {
done = 1; done = 1;
break; break;
...@@ -1662,9 +1664,18 @@ static int f2fs_write_data_pages(struct address_space *mapping, ...@@ -1662,9 +1664,18 @@ static int f2fs_write_data_pages(struct address_space *mapping,
trace_f2fs_writepages(mapping->host, wbc, DATA); trace_f2fs_writepages(mapping->host, wbc, DATA);
/* to avoid spliting IOs due to mixed WB_SYNC_ALL and WB_SYNC_NONE */
if (wbc->sync_mode == WB_SYNC_ALL)
atomic_inc(&sbi->wb_sync_req);
else if (atomic_read(&sbi->wb_sync_req))
goto skip_write;
blk_start_plug(&plug); blk_start_plug(&plug);
ret = f2fs_write_cache_pages(mapping, wbc); ret = f2fs_write_cache_pages(mapping, wbc);
blk_finish_plug(&plug); blk_finish_plug(&plug);
if (wbc->sync_mode == WB_SYNC_ALL)
atomic_dec(&sbi->wb_sync_req);
/* /*
* if some pages were truncated, we cannot guarantee its mapping->host * if some pages were truncated, we cannot guarantee its mapping->host
* to detect pending bios. * to detect pending bios.
......
...@@ -887,6 +887,9 @@ struct f2fs_sb_info { ...@@ -887,6 +887,9 @@ struct f2fs_sb_info {
/* # of allocated blocks */ /* # of allocated blocks */
struct percpu_counter alloc_valid_block_count; struct percpu_counter alloc_valid_block_count;
/* writeback control */
atomic_t wb_sync_req; /* count # of WB_SYNC threads */
/* valid inode count */ /* valid inode count */
struct percpu_counter total_valid_inode_count; struct percpu_counter total_valid_inode_count;
......
...@@ -1566,6 +1566,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi) ...@@ -1566,6 +1566,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
for (i = 0; i < NR_COUNT_TYPE; i++) for (i = 0; i < NR_COUNT_TYPE; i++)
atomic_set(&sbi->nr_pages[i], 0); atomic_set(&sbi->nr_pages[i], 0);
atomic_set(&sbi->wb_sync_req, 0);
INIT_LIST_HEAD(&sbi->s_list); INIT_LIST_HEAD(&sbi->s_list);
mutex_init(&sbi->umount_mutex); mutex_init(&sbi->umount_mutex);
mutex_init(&sbi->wio_mutex[NODE]); mutex_init(&sbi->wio_mutex[NODE]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment