Skip to content

Commit 8648de2

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: add bio cache for IPU
SQLite in Wal mode may trigger sequential IPU write in db-wal file, after commit d1b3e72 ("f2fs: submit bio of in-place-update pages"), we lost the chance of merging page in inner managed bio cache, result in submitting more small-sized IO. So let's add temporary bio in writepages() to cache mergeable write IO as much as possible. Test case: 1. xfs_io -f /mnt/f2fs/file -c "pwrite 0 65536" -c "fsync" 2. xfs_io -f /mnt/f2fs/file -c "pwrite 0 65536" -c "fsync" Before: f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65544, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65552, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65560, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65568, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65576, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65584, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65592, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65600, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65608, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65616, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65624, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65632, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65640, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65648, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65656, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65664, size = 4096 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), NODE, sector = 57352, size = 4096 After: f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), DATA, sector = 65544, size = 65536 f2fs_submit_write_bio: dev = (251,0)/(251,0), rw = WRITE(S), NODE, sector = 57368, size = 4096 Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 49dd883 commit 8648de2

File tree

3 files changed

+86
-10
lines changed

3 files changed

+86
-10
lines changed

fs/f2fs/data.c

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,20 +347,20 @@ static void __submit_merged_bio(struct f2fs_bio_info *io)
347347
io->bio = NULL;
348348
}
349349

350-
static bool __has_merged_page(struct f2fs_bio_info *io, struct inode *inode,
350+
static bool __has_merged_page(struct bio *bio, struct inode *inode,
351351
struct page *page, nid_t ino)
352352
{
353353
struct bio_vec *bvec;
354354
struct page *target;
355355
struct bvec_iter_all iter_all;
356356

357-
if (!io->bio)
357+
if (!bio)
358358
return false;
359359

360360
if (!inode && !page && !ino)
361361
return true;
362362

363-
bio_for_each_segment_all(bvec, io->bio, iter_all) {
363+
bio_for_each_segment_all(bvec, bio, iter_all) {
364364

365365
if (bvec->bv_page->mapping)
366366
target = bvec->bv_page;
@@ -411,7 +411,7 @@ static void __submit_merged_write_cond(struct f2fs_sb_info *sbi,
411411
struct f2fs_bio_info *io = sbi->write_io[btype] + temp;
412412

413413
down_read(&io->io_rwsem);
414-
ret = __has_merged_page(io, inode, page, ino);
414+
ret = __has_merged_page(io->bio, inode, page, ino);
415415
up_read(&io->io_rwsem);
416416
}
417417
if (ret)
@@ -481,6 +481,61 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
481481
return 0;
482482
}
483483

484+
int f2fs_merge_page_bio(struct f2fs_io_info *fio)
485+
{
486+
struct bio *bio = *fio->bio;
487+
struct page *page = fio->encrypted_page ?
488+
fio->encrypted_page : fio->page;
489+
490+
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
491+
__is_meta_io(fio) ? META_GENERIC : DATA_GENERIC))
492+
return -EFAULT;
493+
494+
trace_f2fs_submit_page_bio(page, fio);
495+
f2fs_trace_ios(fio, 0);
496+
497+
if (bio && (*fio->last_block + 1 != fio->new_blkaddr ||
498+
!__same_bdev(fio->sbi, fio->new_blkaddr, bio))) {
499+
__submit_bio(fio->sbi, bio, fio->type);
500+
bio = NULL;
501+
}
502+
alloc_new:
503+
if (!bio) {
504+
bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc,
505+
BIO_MAX_PAGES, false, fio->type, fio->temp);
506+
bio_set_op_attrs(bio, fio->op, fio->op_flags);
507+
}
508+
509+
if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
510+
__submit_bio(fio->sbi, bio, fio->type);
511+
bio = NULL;
512+
goto alloc_new;
513+
}
514+
515+
if (fio->io_wbc)
516+
wbc_account_io(fio->io_wbc, page, PAGE_SIZE);
517+
518+
inc_page_count(fio->sbi, WB_DATA_TYPE(page));
519+
520+
*fio->last_block = fio->new_blkaddr;
521+
*fio->bio = bio;
522+
523+
return 0;
524+
}
525+
526+
static void f2fs_submit_ipu_bio(struct f2fs_sb_info *sbi, struct bio **bio,
527+
struct page *page)
528+
{
529+
if (!bio)
530+
return;
531+
532+
if (!__has_merged_page(*bio, NULL, page, 0))
533+
return;
534+
535+
__submit_bio(sbi, *bio, DATA);
536+
*bio = NULL;
537+
}
538+
484539
void f2fs_submit_page_write(struct f2fs_io_info *fio)
485540
{
486541
struct f2fs_sb_info *sbi = fio->sbi;
@@ -1947,6 +2002,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
19472002
}
19482003

19492004
static int __write_data_page(struct page *page, bool *submitted,
2005+
struct bio **bio,
2006+
sector_t *last_block,
19502007
struct writeback_control *wbc,
19512008
enum iostat_type io_type)
19522009
{
@@ -1972,6 +2029,8 @@ static int __write_data_page(struct page *page, bool *submitted,
19722029
.need_lock = LOCK_RETRY,
19732030
.io_type = io_type,
19742031
.io_wbc = wbc,
2032+
.bio = bio,
2033+
.last_block = last_block,
19752034
};
19762035

19772036
trace_f2fs_writepage(page, DATA);
@@ -2070,10 +2129,13 @@ static int __write_data_page(struct page *page, bool *submitted,
20702129

20712130
unlock_page(page);
20722131
if (!S_ISDIR(inode->i_mode) && !IS_NOQUOTA(inode) &&
2073-
!F2FS_I(inode)->cp_task)
2132+
!F2FS_I(inode)->cp_task) {
2133+
f2fs_submit_ipu_bio(sbi, bio, page);
20742134
f2fs_balance_fs(sbi, need_balance_fs);
2135+
}
20752136

20762137
if (unlikely(f2fs_cp_error(sbi))) {
2138+
f2fs_submit_ipu_bio(sbi, bio, page);
20772139
f2fs_submit_merged_write(sbi, DATA);
20782140
submitted = NULL;
20792141
}
@@ -2100,7 +2162,7 @@ static int __write_data_page(struct page *page, bool *submitted,
21002162
static int f2fs_write_data_page(struct page *page,
21012163
struct writeback_control *wbc)
21022164
{
2103-
return __write_data_page(page, NULL, wbc, FS_DATA_IO);
2165+
return __write_data_page(page, NULL, NULL, NULL, wbc, FS_DATA_IO);
21042166
}
21052167

21062168
/*
@@ -2116,6 +2178,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
21162178
int done = 0;
21172179
struct pagevec pvec;
21182180
struct f2fs_sb_info *sbi = F2FS_M_SB(mapping);
2181+
struct bio *bio = NULL;
2182+
sector_t last_block;
21192183
int nr_pages;
21202184
pgoff_t uninitialized_var(writeback_index);
21212185
pgoff_t index;
@@ -2192,17 +2256,20 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
21922256
}
21932257

21942258
if (PageWriteback(page)) {
2195-
if (wbc->sync_mode != WB_SYNC_NONE)
2259+
if (wbc->sync_mode != WB_SYNC_NONE) {
21962260
f2fs_wait_on_page_writeback(page,
21972261
DATA, true, true);
2198-
else
2262+
f2fs_submit_ipu_bio(sbi, &bio, page);
2263+
} else {
21992264
goto continue_unlock;
2265+
}
22002266
}
22012267

22022268
if (!clear_page_dirty_for_io(page))
22032269
goto continue_unlock;
22042270

2205-
ret = __write_data_page(page, &submitted, wbc, io_type);
2271+
ret = __write_data_page(page, &submitted, &bio,
2272+
&last_block, wbc, io_type);
22062273
if (unlikely(ret)) {
22072274
/*
22082275
* keep nr_to_write, since vfs uses this to
@@ -2251,6 +2318,9 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
22512318
if (nwritten)
22522319
f2fs_submit_merged_write_cond(F2FS_M_SB(mapping), mapping->host,
22532320
NULL, 0, DATA);
2321+
/* submit cached bio of IPU write */
2322+
if (bio)
2323+
__submit_bio(sbi, bio, DATA);
22542324

22552325
return ret;
22562326
}

fs/f2fs/f2fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,8 @@ struct f2fs_io_info {
10521052
bool retry; /* need to reallocate block address */
10531053
enum iostat_type io_type; /* io type */
10541054
struct writeback_control *io_wbc; /* writeback control */
1055+
struct bio **bio; /* bio for ipu */
1056+
sector_t *last_block; /* last block number in bio */
10551057
unsigned char version; /* version of the node */
10561058
};
10571059

@@ -3169,6 +3171,7 @@ void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
31693171
nid_t ino, enum page_type type);
31703172
void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi);
31713173
int f2fs_submit_page_bio(struct f2fs_io_info *fio);
3174+
int f2fs_merge_page_bio(struct f2fs_io_info *fio);
31723175
void f2fs_submit_page_write(struct f2fs_io_info *fio);
31733176
struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
31743177
block_t blk_addr, struct bio *bio);

fs/f2fs/segment.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3202,7 +3202,10 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio)
32023202

32033203
stat_inc_inplace_blocks(fio->sbi);
32043204

3205-
err = f2fs_submit_page_bio(fio);
3205+
if (fio->bio)
3206+
err = f2fs_merge_page_bio(fio);
3207+
else
3208+
err = f2fs_submit_page_bio(fio);
32063209
if (!err) {
32073210
update_device_state(fio);
32083211
f2fs_update_iostat(fio->sbi, fio->io_type, F2FS_BLKSIZE);

0 commit comments

Comments
 (0)