Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 612e589b authored by Hyunchul Lee's avatar Hyunchul Lee Committed by Jaegeuk Kim
Browse files

f2fs: apply write hints to select the type of segment for direct write



When blocks are allocated for direct write, select the type of
segment using the kiocb hint. But if an inode has FI_NO_ALLOC,
use the inode hint.

Signed-off-by: default avatarHyunchul Lee <cheol.lee@lge.com>
Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 63a9fc80
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -782,7 +782,7 @@ got_it:
	return page;
}

static int __allocate_data_block(struct dnode_of_data *dn)
static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
{
	struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
	struct f2fs_summary sum;
@@ -807,7 +807,7 @@ alloc:
	set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);

	allocate_data_block(sbi, NULL, dn->data_blkaddr, &dn->data_blkaddr,
					&sum, CURSEG_WARM_DATA, NULL, false);
					&sum, seg_type, NULL, false);
	set_data_blkaddr(dn);

	/* update i_size */
@@ -850,12 +850,16 @@ int f2fs_preallocate_blocks(struct inode *inode, loff_t pos,
		map.m_len = 0;

	map.m_next_pgofs = NULL;
	map.m_seg_type = NO_CHECK_TYPE;

	if (dio)
	if (dio) {
		/* map.m_seg_type = rw_hint_to_seg_type(iocb->ki_hint); */
		map.m_seg_type = rw_hint_to_seg_type(WRITE_LIFE_NOT_SET);
		return f2fs_map_blocks(inode, &map, 1,
			__force_buffered_io(inode, WRITE) ?
				F2FS_GET_BLOCK_PRE_AIO :
				F2FS_GET_BLOCK_PRE_DIO);
	}
	if (pos + count > MAX_INLINE_DATA(inode)) {
		err = f2fs_convert_inline_inode(inode);
		if (err)
@@ -965,7 +969,8 @@ next_block:
					last_ofs_in_node = dn.ofs_in_node;
				}
			} else {
				err = __allocate_data_block(&dn);
				err = __allocate_data_block(&dn,
							map->m_seg_type);
				if (!err)
					set_inode_flag(inode, FI_APPEND_WRITE);
			}
@@ -1058,7 +1063,7 @@ out:

static int __get_data_block(struct inode *inode, sector_t iblock,
			struct buffer_head *bh, int create, int flag,
			pgoff_t *next_pgofs)
			pgoff_t *next_pgofs, int seg_type)
{
	struct f2fs_map_blocks map;
	int err;
@@ -1066,6 +1071,7 @@ static int __get_data_block(struct inode *inode, sector_t iblock,
	map.m_lblk = iblock;
	map.m_len = bh->b_size >> inode->i_blkbits;
	map.m_next_pgofs = next_pgofs;
	map.m_seg_type = seg_type;

	err = f2fs_map_blocks(inode, &map, create, flag);
	if (!err) {
@@ -1081,14 +1087,18 @@ static int get_data_block(struct inode *inode, sector_t iblock,
			pgoff_t *next_pgofs)
{
	return __get_data_block(inode, iblock, bh_result, create,
							flag, next_pgofs);
							flag, next_pgofs,
							NO_CHECK_TYPE);
}

static int get_data_block_dio(struct inode *inode, sector_t iblock,
			struct buffer_head *bh_result, int create)
{
	return __get_data_block(inode, iblock, bh_result, create,
						F2FS_GET_BLOCK_DEFAULT, NULL);
						F2FS_GET_BLOCK_DEFAULT, NULL,
						rw_hint_to_seg_type(
							WRITE_LIFE_NOT_SET));
						/* inode->i_write_hint)); */
}

static int get_data_block_bmap(struct inode *inode, sector_t iblock,
@@ -1099,7 +1109,8 @@ static int get_data_block_bmap(struct inode *inode, sector_t iblock,
		return -EFBIG;

	return __get_data_block(inode, iblock, bh_result, create,
						F2FS_GET_BLOCK_BMAP, NULL);
						F2FS_GET_BLOCK_BMAP, NULL,
						NO_CHECK_TYPE);
}

static inline sector_t logical_to_blk(struct inode *inode, loff_t offset)
@@ -1218,6 +1229,7 @@ static int f2fs_mpage_readpages(struct address_space *mapping,
	map.m_len = 0;
	map.m_flags = 0;
	map.m_next_pgofs = NULL;
	map.m_seg_type = NO_CHECK_TYPE;

	for (; nr_pages; nr_pages--) {
		if (pages) {
+11 −0
Original line number Diff line number Diff line
@@ -638,6 +638,7 @@ struct f2fs_map_blocks {
	unsigned int m_len;
	unsigned int m_flags;
	pgoff_t *m_next_pgofs;		/* point next possible non-hole pgofs */
	int m_seg_type;
};

/* for flag in get_data_block */
@@ -2537,6 +2538,15 @@ static inline void *kvzalloc(size_t size, gfp_t flags)
	return ret;
}

enum rw_hint {
	WRITE_LIFE_NOT_SET	= 0,
	WRITE_LIFE_NONE		= 1, /* RWH_WRITE_LIFE_NONE */
	WRITE_LIFE_SHORT	= 2, /* RWH_WRITE_LIFE_SHORT */
	WRITE_LIFE_MEDIUM	= 3, /* RWH_WRITE_LIFE_MEDIUM */
	WRITE_LIFE_LONG		= 4, /* RWH_WRITE_LIFE_LONG */
	WRITE_LIFE_EXTREME	= 5, /* RWH_WRITE_LIFE_EXTREME */
};

static inline int get_extra_isize(struct inode *inode)
{
	return F2FS_I(inode)->i_extra_isize / sizeof(__le32);
@@ -2790,6 +2800,7 @@ int build_segment_manager(struct f2fs_sb_info *sbi);
void destroy_segment_manager(struct f2fs_sb_info *sbi);
int __init create_segment_manager_caches(void);
void destroy_segment_manager_caches(void);
int rw_hint_to_seg_type(enum rw_hint hint);

/*
 * checkpoint.c
+4 −2
Original line number Diff line number Diff line
@@ -1401,7 +1401,8 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
					loff_t len, int mode)
{
	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
	struct f2fs_map_blocks map = { .m_next_pgofs = NULL };
	struct f2fs_map_blocks map = { .m_next_pgofs = NULL,
					.m_seg_type = NO_CHECK_TYPE };
	pgoff_t pg_end;
	loff_t new_size = i_size_read(inode);
	loff_t off_end;
@@ -2051,7 +2052,8 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
					struct f2fs_defragment *range)
{
	struct inode *inode = file_inode(filp);
	struct f2fs_map_blocks map = { .m_next_pgofs = NULL };
	struct f2fs_map_blocks map = { .m_next_pgofs = NULL,
					.m_seg_type = NO_CHECK_TYPE };
	struct extent_info ei = {0,0,0};
	pgoff_t pg_start, pg_end;
	unsigned int blk_per_seg = sbi->blocks_per_seg;
+0 −2
Original line number Diff line number Diff line
@@ -2515,7 +2515,6 @@ static bool __has_curseg_space(struct f2fs_sb_info *sbi, int type)
	return false;
}

#if 0
int rw_hint_to_seg_type(enum rw_hint hint)
{
	switch (hint) {
@@ -2527,7 +2526,6 @@ int rw_hint_to_seg_type(enum rw_hint hint)
		return CURSEG_WARM_DATA;
	}
}
#endif

static int __get_segment_type_2(struct f2fs_io_info *fio)
{