Skip to content

Commit

Permalink
f2fs: avoid unnecessary bio submit when wait page writeback
Browse files Browse the repository at this point in the history
This patch introduce is_merged_page() to check whether current page is merged
in f2fs bio cache. When page is not in cache, we can avoid submitting bio cache,
resulting in having more chance to merge pages.

Signed-off-by: Chao Yu <[email protected]>
Signed-off-by: Jaegeuk Kim <[email protected]>
  • Loading branch information
chaseyu authored and Jaegeuk Kim committed Apr 1, 2014
1 parent 3bb5e2c commit df0f8dc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
8 changes: 4 additions & 4 deletions fs/f2fs/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi,

io = is_read_io(rw) ? &sbi->read_io : &sbi->write_io[btype];

mutex_lock(&io->io_mutex);
down_write(&io->io_rwsem);

/* change META to META_FLUSH in the checkpoint procedure */
if (type >= META_FLUSH) {
io->fio.type = META_FLUSH;
io->fio.rw = WRITE_FLUSH_FUA | REQ_META | REQ_PRIO;
}
__submit_merged_bio(io);
mutex_unlock(&io->io_mutex);
up_write(&io->io_rwsem);
}

/*
Expand Down Expand Up @@ -180,7 +180,7 @@ void f2fs_submit_page_mbio(struct f2fs_sb_info *sbi, struct page *page,

verify_block_addr(sbi, blk_addr);

mutex_lock(&io->io_mutex);
down_write(&io->io_rwsem);

if (!is_read)
inc_page_count(sbi, F2FS_WRITEBACK);
Expand All @@ -204,7 +204,7 @@ void f2fs_submit_page_mbio(struct f2fs_sb_info *sbi, struct page *page,

io->last_block_in_bio = blk_addr;

mutex_unlock(&io->io_mutex);
up_write(&io->io_rwsem);
trace_f2fs_submit_page_mbio(page, fio->rw, fio->type, blk_addr);
}

Expand Down
2 changes: 1 addition & 1 deletion fs/f2fs/f2fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ struct f2fs_bio_info {
struct bio *bio; /* bios to merge */
sector_t last_block_in_bio; /* last block number */
struct f2fs_io_info fio; /* store buffered io info. */
struct mutex io_mutex; /* mutex for bio */
struct rw_semaphore io_rwsem; /* blocking op for bio */
};

struct f2fs_sb_info {
Expand Down
28 changes: 27 additions & 1 deletion fs/f2fs/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,12 +1046,38 @@ void rewrite_node_page(struct f2fs_sb_info *sbi,
mutex_unlock(&curseg->curseg_mutex);
}

static inline bool is_merged_page(struct f2fs_sb_info *sbi,
struct page *page, enum page_type type)
{
enum page_type btype = PAGE_TYPE_OF_BIO(type);
struct f2fs_bio_info *io = &sbi->write_io[btype];
struct bio *bio = io->bio;
struct bio_vec *bvec;
int i;

down_read(&io->io_rwsem);
if (!bio)
goto out;

bio_for_each_segment_all(bvec, bio, i) {
if (page == bvec->bv_page) {
up_read(&io->io_rwsem);
return true;
}
}

out:
up_read(&io->io_rwsem);
return false;
}

void f2fs_wait_on_page_writeback(struct page *page,
enum page_type type)
{
struct f2fs_sb_info *sbi = F2FS_SB(page->mapping->host->i_sb);
if (PageWriteback(page)) {
f2fs_submit_merged_bio(sbi, type, WRITE);
if (is_merged_page(sbi, page, type))
f2fs_submit_merged_bio(sbi, type, WRITE);
wait_on_page_writeback(page);
}
}
Expand Down
4 changes: 2 additions & 2 deletions fs/f2fs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,11 +920,11 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
sbi->por_doing = false;
spin_lock_init(&sbi->stat_lock);

mutex_init(&sbi->read_io.io_mutex);
init_rwsem(&sbi->read_io.io_rwsem);
sbi->read_io.sbi = sbi;
sbi->read_io.bio = NULL;
for (i = 0; i < NR_PAGE_TYPE; i++) {
mutex_init(&sbi->write_io[i].io_mutex);
init_rwsem(&sbi->write_io[i].io_rwsem);
sbi->write_io[i].sbi = sbi;
sbi->write_io[i].bio = NULL;
}
Expand Down

0 comments on commit df0f8dc

Please sign in to comment.