Commit b6a06cbb authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: support hot file extension

This patch supports to recognize hot file extension in f2fs, so that we
can allocate proper hot segment location for its data, which can lead to
better hot/cold seperation in filesystem.

In addition, we changes a bit on query/add/del operation method for
extension_list sysfs entry as below:

- Query: cat /sys/fs/f2fs/<disk>/extension_list
- Add: echo 'extension' > /sys/fs/f2fs/<disk>/extension_list
- Del: echo '!extension' > /sys/fs/f2fs/<disk>/extension_list
- Add: echo '[h/c]extension' > /sys/fs/f2fs/<disk>/extension_list
- Del: echo '[h/c]!extension' > /sys/fs/f2fs/<disk>/extension_list
- [h] means add/del hot file extension
- [c] means add/del cold file extension
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 1dc0f899
...@@ -199,5 +199,7 @@ Contact: "Chao Yu" <yuchao0@huawei.com> ...@@ -199,5 +199,7 @@ Contact: "Chao Yu" <yuchao0@huawei.com>
Description: Description:
Used to control configure extension list: Used to control configure extension list:
- Query: cat /sys/fs/f2fs/<disk>/extension_list - Query: cat /sys/fs/f2fs/<disk>/extension_list
- Add: echo 'extension' > /sys/fs/f2fs/<disk>/extension_list - Add: echo '[h/c]extension' > /sys/fs/f2fs/<disk>/extension_list
- Del: echo '!extension' > /sys/fs/f2fs/<disk>/extension_list - Del: echo '[h/c]!extension' > /sys/fs/f2fs/<disk>/extension_list
- [h] means add/del hot file extension
- [c] means add/del cold file extension
...@@ -576,6 +576,7 @@ enum { ...@@ -576,6 +576,7 @@ enum {
#define FADVISE_ENCRYPT_BIT 0x04 #define FADVISE_ENCRYPT_BIT 0x04
#define FADVISE_ENC_NAME_BIT 0x08 #define FADVISE_ENC_NAME_BIT 0x08
#define FADVISE_KEEP_SIZE_BIT 0x10 #define FADVISE_KEEP_SIZE_BIT 0x10
#define FADVISE_HOT_BIT 0x20
#define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT)
#define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT)
...@@ -590,6 +591,9 @@ enum { ...@@ -590,6 +591,9 @@ enum {
#define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
#define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT)
#define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT)
#define file_is_hot(inode) is_file(inode, FADVISE_HOT_BIT)
#define file_set_hot(inode) set_file(inode, FADVISE_HOT_BIT)
#define file_clear_hot(inode) clear_file(inode, FADVISE_HOT_BIT)
#define DEF_DIR_LEVEL 0 #define DEF_DIR_LEVEL 0
...@@ -2614,7 +2618,7 @@ void handle_failed_inode(struct inode *inode); ...@@ -2614,7 +2618,7 @@ void handle_failed_inode(struct inode *inode);
* namei.c * namei.c
*/ */
int update_extension_list(struct f2fs_sb_info *sbi, const char *name, int update_extension_list(struct f2fs_sb_info *sbi, const char *name,
bool set); bool hot, bool set);
struct dentry *f2fs_get_parent(struct dentry *child); struct dentry *f2fs_get_parent(struct dentry *child);
/* /*
......
...@@ -142,7 +142,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode) ...@@ -142,7 +142,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
return ERR_PTR(err); return ERR_PTR(err);
} }
static int is_multimedia_file(const unsigned char *s, const char *sub) static int is_extension_exist(const unsigned char *s, const char *sub)
{ {
size_t slen = strlen(s); size_t slen = strlen(s);
size_t sublen = strlen(sub); size_t sublen = strlen(sub);
...@@ -168,33 +168,59 @@ static int is_multimedia_file(const unsigned char *s, const char *sub) ...@@ -168,33 +168,59 @@ static int is_multimedia_file(const unsigned char *s, const char *sub)
/* /*
* Set multimedia files as cold files for hot/cold data separation * Set multimedia files as cold files for hot/cold data separation
*/ */
static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode, static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *inode,
const unsigned char *name) const unsigned char *name)
{ {
__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
int i, count; int i, cold_count, hot_count;
down_read(&sbi->sb_lock); down_read(&sbi->sb_lock);
count = le32_to_cpu(sbi->raw_super->extension_count); cold_count = le32_to_cpu(sbi->raw_super->extension_count);
hot_count = sbi->raw_super->hot_ext_count;
for (i = 0; i < count; i++) { for (i = 0; i < cold_count + hot_count; i++) {
if (is_multimedia_file(name, extlist[i])) { if (!is_extension_exist(name, extlist[i]))
continue;
if (i < cold_count)
file_set_cold(inode); file_set_cold(inode);
break; else
} file_set_hot(inode);
break;
} }
up_read(&sbi->sb_lock); up_read(&sbi->sb_lock);
} }
int update_extension_list(struct f2fs_sb_info *sbi, const char *name, bool set) int update_extension_list(struct f2fs_sb_info *sbi, const char *name,
bool hot, bool set)
{ {
__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list; __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
int count = le32_to_cpu(sbi->raw_super->extension_count); int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
int hot_count = sbi->raw_super->hot_ext_count;
int total_count = cold_count + hot_count;
int start, count;
int i; int i;
for (i = 0; i < count; i++) { if (set) {
if (total_count == F2FS_MAX_EXTENSION)
return -EINVAL;
} else {
if (!hot && !cold_count)
return -EINVAL;
if (hot && !hot_count)
return -EINVAL;
}
if (hot) {
start = cold_count;
count = total_count;
} else {
start = 0;
count = cold_count;
}
for (i = start; i < count; i++) {
if (strcmp(name, extlist[i])) if (strcmp(name, extlist[i]))
continue; continue;
...@@ -202,20 +228,33 @@ int update_extension_list(struct f2fs_sb_info *sbi, const char *name, bool set) ...@@ -202,20 +228,33 @@ int update_extension_list(struct f2fs_sb_info *sbi, const char *name, bool set)
return -EINVAL; return -EINVAL;
memcpy(extlist[i], extlist[i + 1], memcpy(extlist[i], extlist[i + 1],
F2FS_EXTENSION_LEN * (count - i - 1)); F2FS_EXTENSION_LEN * (total_count - i - 1));
memset(extlist[count - 1], 0, F2FS_EXTENSION_LEN); memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN);
sbi->raw_super->extension_count = cpu_to_le32(count - 1); if (hot)
sbi->raw_super->hot_ext_count = hot_count - 1;
else
sbi->raw_super->extension_count =
cpu_to_le32(cold_count - 1);
return 0; return 0;
} }
if (!set) if (!set)
return -EINVAL; return -EINVAL;
if (count == F2FS_MAX_EXTENSION) if (hot) {
return -EINVAL; strncpy(extlist[count], name, strlen(name));
sbi->raw_super->hot_ext_count = hot_count + 1;
strncpy(extlist[count], name, strlen(name)); } else {
sbi->raw_super->extension_count = cpu_to_le32(count + 1); char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN];
memcpy(buf, &extlist[cold_count],
F2FS_EXTENSION_LEN * hot_count);
memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN);
strncpy(extlist[cold_count], name, strlen(name));
memcpy(&extlist[cold_count + 1], buf,
F2FS_EXTENSION_LEN * hot_count);
sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1);
}
return 0; return 0;
} }
...@@ -239,7 +278,7 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode, ...@@ -239,7 +278,7 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
return PTR_ERR(inode); return PTR_ERR(inode);
if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
set_cold_files(sbi, inode, dentry->d_name.name); set_file_temperature(sbi, inode, dentry->d_name.name);
inode->i_op = &f2fs_file_inode_operations; inode->i_op = &f2fs_file_inode_operations;
inode->i_fop = &f2fs_file_operations; inode->i_fop = &f2fs_file_operations;
......
...@@ -2587,7 +2587,8 @@ static int __get_segment_type_6(struct f2fs_io_info *fio) ...@@ -2587,7 +2587,8 @@ static int __get_segment_type_6(struct f2fs_io_info *fio)
if (is_cold_data(fio->page) || file_is_cold(inode)) if (is_cold_data(fio->page) || file_is_cold(inode))
return CURSEG_COLD_DATA; return CURSEG_COLD_DATA;
if (is_inode_flag_set(inode, FI_HOT_DATA)) if (file_is_hot(inode) ||
is_inode_flag_set(inode, FI_HOT_DATA))
return CURSEG_HOT_DATA; return CURSEG_HOT_DATA;
return rw_hint_to_seg_type(inode->i_write_hint); return rw_hint_to_seg_type(inode->i_write_hint);
} else { } else {
......
...@@ -139,10 +139,19 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a, ...@@ -139,10 +139,19 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
if (!strcmp(a->attr.name, "extension_list")) { if (!strcmp(a->attr.name, "extension_list")) {
__u8 (*extlist)[F2FS_EXTENSION_LEN] = __u8 (*extlist)[F2FS_EXTENSION_LEN] =
sbi->raw_super->extension_list; sbi->raw_super->extension_list;
int count = le32_to_cpu(sbi->raw_super->extension_count); int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
int hot_count = sbi->raw_super->hot_ext_count;
int len = 0, i; int len = 0, i;
for (i = 0; i < count; i++) len += snprintf(buf + len, PAGE_SIZE - len,
"cold file extenstion:\n");
for (i = 0; i < cold_count; i++)
len += snprintf(buf + len, PAGE_SIZE - len, "%s\n",
extlist[i]);
len += snprintf(buf + len, PAGE_SIZE - len,
"hot file extenstion:\n");
for (i = cold_count; i < cold_count + hot_count; i++)
len += snprintf(buf + len, PAGE_SIZE - len, "%s\n", len += snprintf(buf + len, PAGE_SIZE - len, "%s\n",
extlist[i]); extlist[i]);
return len; return len;
...@@ -168,9 +177,18 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a, ...@@ -168,9 +177,18 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
if (!strcmp(a->attr.name, "extension_list")) { if (!strcmp(a->attr.name, "extension_list")) {
const char *name = strim((char *)buf); const char *name = strim((char *)buf);
bool set = true; bool set = true, hot;
if (!strncmp(name, "[h]", 3))
hot = true;
else if (!strncmp(name, "[c]", 3))
hot = false;
else
return -EINVAL;
name += 3;
if (name[0] == '!') { if (*name == '!') {
name++; name++;
set = false; set = false;
} }
...@@ -180,13 +198,13 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a, ...@@ -180,13 +198,13 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
down_write(&sbi->sb_lock); down_write(&sbi->sb_lock);
ret = update_extension_list(sbi, name, set); ret = update_extension_list(sbi, name, hot, set);
if (ret) if (ret)
goto out; goto out;
ret = f2fs_commit_super(sbi, false); ret = f2fs_commit_super(sbi, false);
if (ret) if (ret)
update_extension_list(sbi, name, !set); update_extension_list(sbi, name, hot, !set);
out: out:
up_write(&sbi->sb_lock); up_write(&sbi->sb_lock);
return ret ? ret : count; return ret ? ret : count;
......
...@@ -111,7 +111,8 @@ struct f2fs_super_block { ...@@ -111,7 +111,8 @@ struct f2fs_super_block {
__u8 encrypt_pw_salt[16]; /* Salt used for string2key algorithm */ __u8 encrypt_pw_salt[16]; /* Salt used for string2key algorithm */
struct f2fs_device devs[MAX_DEVICES]; /* device list */ struct f2fs_device devs[MAX_DEVICES]; /* device list */
__le32 qf_ino[F2FS_MAX_QUOTAS]; /* quota inode numbers */ __le32 qf_ino[F2FS_MAX_QUOTAS]; /* quota inode numbers */
__u8 reserved[315]; /* valid reserved region */ __u8 hot_ext_count; /* # of hot file extension */
__u8 reserved[314]; /* valid reserved region */
} __packed; } __packed;
/* /*
......
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