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

Commit 249b112b authored by Hyunchul Lee's avatar Hyunchul Lee Committed by Jaegeuk Kim
Browse files

f2fs: support passing down write hints given by users to block layer



Add the 'whint_mode' mount option that controls which write
hints are passed down to block layer. There are "off" and
"user-based" mode. The default mode is "off".

1) whint_mode=off. F2FS only passes down WRITE_LIFE_NOT_SET.

2) whint_mode=user-based. F2FS tries to pass down hints given
by users.

User                  F2FS                     Block
----                  ----                     -----
                      META                     WRITE_LIFE_NOT_SET
                      HOT_NODE                 "
                      WARM_NODE                "
                      COLD_NODE                "
ioctl(COLD)           COLD_DATA                WRITE_LIFE_EXTREME
extension list        "                        "

-- buffered io
WRITE_LIFE_EXTREME    COLD_DATA                WRITE_LIFE_EXTREME
WRITE_LIFE_SHORT      HOT_DATA                 WRITE_LIFE_SHORT
WRITE_LIFE_NOT_SET    WARM_DATA                WRITE_LIFE_NOT_SET
WRITE_LIFE_NONE       "                        "
WRITE_LIFE_MEDIUM     "                        "
WRITE_LIFE_LONG       "                        "

-- direct io
WRITE_LIFE_EXTREME    COLD_DATA                WRITE_LIFE_EXTREME
WRITE_LIFE_SHORT      HOT_DATA                 WRITE_LIFE_SHORT
WRITE_LIFE_NOT_SET    WARM_DATA                WRITE_LIFE_NOT_SET
WRITE_LIFE_NONE       "                        WRITE_LIFE_NONE
WRITE_LIFE_MEDIUM     "                        WRITE_LIFE_MEDIUM
WRITE_LIFE_LONG       "                        WRITE_LIFE_LONG

Many thanks to Chao Yu and Jaegeuk Kim for comments to
implement this patch.

Signed-off-by: default avatarHyunchul Lee <cheol.lee@lge.com>
Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
[Jaegeuk Kim: avoid build warning]
[Chao Yu: fix to restore whint_mode in ->remount_fs]
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 3b8cef6e
Loading
Loading
Loading
Loading
+21 −5
Original line number Original line Diff line number Diff line
@@ -174,15 +174,22 @@ static bool __same_bdev(struct f2fs_sb_info *sbi,
 */
 */
static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr,
static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr,
				struct writeback_control *wbc,
				struct writeback_control *wbc,
				int npages, bool is_read)
				int npages, bool is_read,
				enum page_type type, enum temp_type temp)
{
{
	struct bio *bio;
	struct bio *bio;


	bio = f2fs_bio_alloc(sbi, npages, true);
	bio = f2fs_bio_alloc(sbi, npages, true);


	f2fs_target_device(sbi, blk_addr, bio);
	f2fs_target_device(sbi, blk_addr, bio);
	bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io;
	if (is_read) {
	bio->bi_private = is_read ? NULL : sbi;
		bio->bi_end_io = f2fs_read_end_io;
		bio->bi_private = NULL;
	} else {
		bio->bi_end_io = f2fs_write_end_io;
		bio->bi_private = sbi;
		/* bio->bi_write_hint = io_type_to_rw_hint(sbi, type, temp); */
	}
	if (wbc)
	if (wbc)
		wbc_init_bio(wbc, bio);
		wbc_init_bio(wbc, bio);


@@ -381,7 +388,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)


	/* Allocate a new bio */
	/* Allocate a new bio */
	bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc,
	bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc,
				1, is_read_io(fio->op));
				1, is_read_io(fio->op), fio->type, fio->temp);


	if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
	if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
		bio_put(bio);
		bio_put(bio);
@@ -444,7 +451,8 @@ alloc_new:
			goto out_fail;
			goto out_fail;
		}
		}
		io->bio = __bio_alloc(sbi, fio->new_blkaddr, fio->io_wbc,
		io->bio = __bio_alloc(sbi, fio->new_blkaddr, fio->io_wbc,
						BIO_MAX_PAGES, false);
						BIO_MAX_PAGES, false,
						fio->type, fio->temp);
		io->fio = *fio;
		io->fio = *fio;
	}
	}


@@ -2292,8 +2300,11 @@ static ssize_t f2fs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
{
{
	struct address_space *mapping = iocb->ki_filp->f_mapping;
	struct address_space *mapping = iocb->ki_filp->f_mapping;
	struct inode *inode = mapping->host;
	struct inode *inode = mapping->host;
	/* struct f2fs_sb_info *sbi = F2FS_I_SB(inode); */
	size_t count = iov_iter_count(iter);
	size_t count = iov_iter_count(iter);
	int err;
	int err;
	/* enum rw_hint hint = iocb->ki_hint;
	int whint_mode = sbi->whint_mode; */


	err = check_direct_IO(inode, iter, offset);
	err = check_direct_IO(inode, iter, offset);
	if (err)
	if (err)
@@ -2304,11 +2315,16 @@ static ssize_t f2fs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,


	trace_f2fs_direct_IO_enter(inode, offset, count, rw);
	trace_f2fs_direct_IO_enter(inode, offset, count, rw);


	/* if (rw == WRITE && whint_mode == WHINT_MODE_OFF)
		iocb->ki_hint = WRITE_LIFE_NOT_SET; */

	down_read(&F2FS_I(inode)->dio_rwsem[rw]);
	down_read(&F2FS_I(inode)->dio_rwsem[rw]);
	err = blockdev_direct_IO(rw, iocb, inode, iter, offset, get_data_block_dio);
	err = blockdev_direct_IO(rw, iocb, inode, iter, offset, get_data_block_dio);
	up_read(&F2FS_I(inode)->dio_rwsem[rw]);
	up_read(&F2FS_I(inode)->dio_rwsem[rw]);


	if (rw & WRITE) {
	if (rw & WRITE) {
		/* if (whint_mode == WHINT_MODE_OFF)
			iocb->ki_hint = hint; */
		if (err > 0) {
		if (err > 0) {
			f2fs_update_iostat(F2FS_I_SB(inode), APP_DIRECT_IO,
			f2fs_update_iostat(F2FS_I_SB(inode), APP_DIRECT_IO,
									err);
									err);
+9 −0
Original line number Original line Diff line number Diff line
@@ -1135,6 +1135,11 @@ enum {
#define F2FS_MAXQUOTAS 2
#define F2FS_MAXQUOTAS 2
#endif
#endif


enum {
	WHINT_MODE_OFF,		/* not pass down write hints */
	WHINT_MODE_USER,	/* try to pass down hints given by users */
};

struct f2fs_sb_info {
struct f2fs_sb_info {
	struct super_block *sb;			/* pointer to VFS super block */
	struct super_block *sb;			/* pointer to VFS super block */
	struct proc_dir_entry *s_proc;		/* proc entry */
	struct proc_dir_entry *s_proc;		/* proc entry */
@@ -1318,6 +1323,8 @@ struct f2fs_sb_info {
	char *s_qf_names[F2FS_MAXQUOTAS];
	char *s_qf_names[F2FS_MAXQUOTAS];
	int s_jquota_fmt;			/* Format of quota to use */
	int s_jquota_fmt;			/* Format of quota to use */
#endif
#endif
	/* For which write hints are passed down to block layer */
	int whint_mode;
};
};


#ifdef CONFIG_F2FS_FAULT_INJECTION
#ifdef CONFIG_F2FS_FAULT_INJECTION
@@ -2905,6 +2912,8 @@ void destroy_segment_manager(struct f2fs_sb_info *sbi);
int __init create_segment_manager_caches(void);
int __init create_segment_manager_caches(void);
void destroy_segment_manager_caches(void);
void destroy_segment_manager_caches(void);
int rw_hint_to_seg_type(enum rw_hint hint);
int rw_hint_to_seg_type(enum rw_hint hint);
enum rw_hint io_type_to_rw_hint(struct f2fs_sb_info *sbi, enum page_type type,
				enum temp_type temp);


/*
/*
 * checkpoint.c
 * checkpoint.c
+59 −0
Original line number Original line Diff line number Diff line
@@ -2537,6 +2537,62 @@ int rw_hint_to_seg_type(enum rw_hint hint)
	}
	}
}
}


/* This returns write hints for each segment type. This hints will be
 * passed down to block layer. There are mapping tables which depend on
 * the mount option 'whint_mode'.
 *
 * 1) whint_mode=off. F2FS only passes down WRITE_LIFE_NOT_SET.
 *
 * 2) whint_mode=user-based. F2FS tries to pass down hints given by users.
 *
 * User                  F2FS                     Block
 * ----                  ----                     -----
 *                       META                     WRITE_LIFE_NOT_SET
 *                       HOT_NODE                 "
 *                       WARM_NODE                "
 *                       COLD_NODE                "
 * ioctl(COLD)           COLD_DATA                WRITE_LIFE_EXTREME
 * extension list        "                        "
 *
 * -- buffered io
 * WRITE_LIFE_EXTREME    COLD_DATA                WRITE_LIFE_EXTREME
 * WRITE_LIFE_SHORT      HOT_DATA                 WRITE_LIFE_SHORT
 * WRITE_LIFE_NOT_SET    WARM_DATA                WRITE_LIFE_NOT_SET
 * WRITE_LIFE_NONE       "                        "
 * WRITE_LIFE_MEDIUM     "                        "
 * WRITE_LIFE_LONG       "                        "
 *
 * -- direct io
 * WRITE_LIFE_EXTREME    COLD_DATA                WRITE_LIFE_EXTREME
 * WRITE_LIFE_SHORT      HOT_DATA                 WRITE_LIFE_SHORT
 * WRITE_LIFE_NOT_SET    WARM_DATA                WRITE_LIFE_NOT_SET
 * WRITE_LIFE_NONE       "                        WRITE_LIFE_NONE
 * WRITE_LIFE_MEDIUM     "                        WRITE_LIFE_MEDIUM
 * WRITE_LIFE_LONG       "                        WRITE_LIFE_LONG
 *
 */

enum rw_hint io_type_to_rw_hint(struct f2fs_sb_info *sbi,
				enum page_type type, enum temp_type temp)
{
	if (sbi->whint_mode == WHINT_MODE_USER) {
		if (type == DATA) {
			switch (temp) {
			case COLD:
				return WRITE_LIFE_EXTREME;
			case HOT:
				return WRITE_LIFE_SHORT;
			default:
				return WRITE_LIFE_NOT_SET;
			}
		} else {
			return WRITE_LIFE_NOT_SET;
		}
	} else {
		return WRITE_LIFE_NOT_SET;
	}
}

static int __get_segment_type_2(struct f2fs_io_info *fio)
static int __get_segment_type_2(struct f2fs_io_info *fio)
{
{
	if (fio->type == DATA)
	if (fio->type == DATA)
@@ -2726,6 +2782,7 @@ void write_meta_page(struct f2fs_sb_info *sbi, struct page *page,
	struct f2fs_io_info fio = {
	struct f2fs_io_info fio = {
		.sbi = sbi,
		.sbi = sbi,
		.type = META,
		.type = META,
		.temp = HOT,
		.op = REQ_OP_WRITE,
		.op = REQ_OP_WRITE,
		.op_flags = REQ_SYNC | REQ_META | REQ_PRIO,
		.op_flags = REQ_SYNC | REQ_META | REQ_PRIO,
		.old_blkaddr = page->index,
		.old_blkaddr = page->index,
@@ -2774,6 +2831,8 @@ int rewrite_data_page(struct f2fs_io_info *fio)
	int err;
	int err;


	fio->new_blkaddr = fio->old_blkaddr;
	fio->new_blkaddr = fio->old_blkaddr;
	/* i/o temperature is needed for passing down write hints */
	__get_segment_type(fio);
	stat_inc_inplace_blocks(fio->sbi);
	stat_inc_inplace_blocks(fio->sbi);


	err = f2fs_submit_page_bio(fio);
	err = f2fs_submit_page_bio(fio);
+30 −1
Original line number Original line Diff line number Diff line
@@ -132,6 +132,7 @@ enum {
	Opt_jqfmt_vfsold,
	Opt_jqfmt_vfsold,
	Opt_jqfmt_vfsv0,
	Opt_jqfmt_vfsv0,
	Opt_jqfmt_vfsv1,
	Opt_jqfmt_vfsv1,
	Opt_whint,
	Opt_err,
	Opt_err,
};
};


@@ -185,6 +186,7 @@ static match_table_t f2fs_tokens = {
	{Opt_jqfmt_vfsold, "jqfmt=vfsold"},
	{Opt_jqfmt_vfsold, "jqfmt=vfsold"},
	{Opt_jqfmt_vfsv0, "jqfmt=vfsv0"},
	{Opt_jqfmt_vfsv0, "jqfmt=vfsv0"},
	{Opt_jqfmt_vfsv1, "jqfmt=vfsv1"},
	{Opt_jqfmt_vfsv1, "jqfmt=vfsv1"},
	{Opt_whint, "whint_mode=%s"},
	{Opt_err, NULL},
	{Opt_err, NULL},
};
};


@@ -695,6 +697,22 @@ static int parse_options(struct super_block *sb, char *options)
					"quota operations not supported");
					"quota operations not supported");
			break;
			break;
#endif
#endif
		case Opt_whint:
			name = match_strdup(&args[0]);
			if (!name)
				return -ENOMEM;
			if (strlen(name) == 10 &&
					!strncmp(name, "user-based", 10)) {
				sbi->whint_mode = WHINT_MODE_USER;
			} else if (strlen(name) == 3 &&
					!strncmp(name, "off", 3)) {
				sbi->whint_mode = WHINT_MODE_OFF;
			} else {
				kfree(name);
				return -EINVAL;
			}
			kfree(name);
			break;
		default:
		default:
			f2fs_msg(sb, KERN_ERR,
			f2fs_msg(sb, KERN_ERR,
				"Unrecognized mount option \"%s\" or missing value",
				"Unrecognized mount option \"%s\" or missing value",
@@ -738,6 +756,12 @@ static int parse_options(struct super_block *sb, char *options)
			return -EINVAL;
			return -EINVAL;
		}
		}
	}
	}

	/* Not pass down write hints if the number of active logs is lesser
	 * than NR_CURSEG_TYPE.
	 */
	if (sbi->active_logs != NR_CURSEG_TYPE)
		sbi->whint_mode = WHINT_MODE_OFF;
	return 0;
	return 0;
}
}


@@ -1248,6 +1272,8 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
		seq_puts(seq, ",prjquota");
		seq_puts(seq, ",prjquota");
#endif
#endif
	f2fs_show_quota_options(seq, sbi->sb);
	f2fs_show_quota_options(seq, sbi->sb);
	if (sbi->whint_mode == WHINT_MODE_USER)
		seq_printf(seq, ",whint_mode=%s", "user-based");


	return 0;
	return 0;
}
}
@@ -1257,6 +1283,7 @@ static void default_options(struct f2fs_sb_info *sbi)
	/* init some FS parameters */
	/* init some FS parameters */
	sbi->active_logs = NR_CURSEG_TYPE;
	sbi->active_logs = NR_CURSEG_TYPE;
	sbi->inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
	sbi->inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
	sbi->whint_mode = WHINT_MODE_OFF;


	set_opt(sbi, BG_GC);
	set_opt(sbi, BG_GC);
	set_opt(sbi, INLINE_XATTR);
	set_opt(sbi, INLINE_XATTR);
@@ -1297,6 +1324,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
	bool need_restart_gc = false;
	bool need_restart_gc = false;
	bool need_stop_gc = false;
	bool need_stop_gc = false;
	bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE);
	bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE);
	int old_whint_mode = sbi->whint_mode;
#ifdef CONFIG_F2FS_FAULT_INJECTION
#ifdef CONFIG_F2FS_FAULT_INJECTION
	struct f2fs_fault_info ffi = sbi->fault_info;
	struct f2fs_fault_info ffi = sbi->fault_info;
#endif
#endif
@@ -1396,7 +1424,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
		need_stop_gc = true;
		need_stop_gc = true;
	}
	}


	if (*flags & MS_RDONLY) {
	if (*flags & MS_RDONLY || sbi->whint_mode != old_whint_mode) {
		writeback_inodes_sb(sb, WB_REASON_SYNC);
		writeback_inodes_sb(sb, WB_REASON_SYNC);
		sync_inodes_sb(sb);
		sync_inodes_sb(sb);


@@ -1446,6 +1474,7 @@ restore_opts:
		sbi->s_qf_names[i] = s_qf_names[i];
		sbi->s_qf_names[i] = s_qf_names[i];
	}
	}
#endif
#endif
	sbi->whint_mode = old_whint_mode;
	sbi->mount_opt = org_mount_opt;
	sbi->mount_opt = org_mount_opt;
	sbi->active_logs = active_logs;
	sbi->active_logs = active_logs;
	sb->s_flags = old_sb_flags;
	sb->s_flags = old_sb_flags;