f2fs: add mount option for segment allocation policy
Subsystems (2)
Jaegeuk Kim
maintainerPATCH 1/5 f2fs: add mount option for segment allocation policy
This patch adds an mount option, "alloc_mode=%s" having two options, "default" and "reuse".
In "alloc_mode=reuse" case, f2fs starts to allocate segments from 0'th segment all the time to reassign segments. It'd be useful for small-sized eMMC parts.
--- fs/f2fs/f2fs.h | 8 ++++++++ fs/f2fs/segment.c | 5 +++++ fs/f2fs/super.c | 24 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+)
fs/f2fs/f2fs.h +8 -0
@@ -1043,6 +1043,11 @@ enum { WHINT_MODE_FS, /* pass down hints with F2FS policy */ }; +enum { +ALLOC_MODE_DEFAULT ,/* stay default */ +ALLOC_MODE_REUSE ,/* reuse segments as much as possible */ +}; +struct f2fs_sb_info {struct super_block *sb;/* pointer to VFS super block */ struct proc_dir_entry *s_proc;/* proc entry */
@@ -1229,6 +1234,9 @@ struct f2fs_sb_info {#endif /* For which write hints are passed down to block layer */ int whint_mode; + +/* segment allocation policy */ +int alloc_mode; };#ifdef CONFIG_F2FS_FAULT_INJECTION
fs/f2fs/segment.c +5 -0
@@ -2170,6 +2170,11 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)if (SIT_I (sbi)->last_victim[ALLOC_NEXT ])return SIT_I (sbi)->last_victim[ALLOC_NEXT ]; + +/* find segments from 0 to reuse freed segments */ +if (sbi->alloc_mode ==ALLOC_MODE_REUSE ) +return 0 ; +return CURSEG_I (sbi, type)->segno; }
fs/f2fs/super.c +24 -0
@@ -130,6 +130,7 @@ enum { Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_whint, + Opt_alloc, Opt_err, };
@@ -184,6 +185,7 @@ static match_table_t f2fs_tokens = { {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"}, {Opt_whint, "whint_mode=%s"}, + {Opt_alloc, "alloc_mode=%s"}, {Opt_err, NULL}, };
@@ -700,6 +702,23 @@ static int parse_options(struct super_block *sb, char *options) }kfree (name);break ; +case Opt_alloc: + name =match_strdup (&args[0 ]); +if (!name) +return -ENOMEM ; + +if (strlen (name) ==7 && + !strncmp (name,"default" ,7 )) { + sbi->alloc_mode =ALLOC_MODE_DEFAULT ; + }else if (strlen (name) ==5 && + !strncmp (name,"reuse" ,5 )) { + sbi->alloc_mode =ALLOC_MODE_REUSE ; + }else { +kfree (name); +return -EINVAL ; + } +kfree (name); +break ;default : f2fs_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" or missing value",
@@ -1264,6 +1283,10 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)else if (sbi->whint_mode ==WHINT_MODE_FS )seq_printf (seq,",whint_mode=%s" ,"fs-based" ); +if (sbi->alloc_mode ==ALLOC_MODE_DEFAULT ) +seq_printf (seq,",alloc_mode=%s" ,"default" ); +else if (sbi->alloc_mode ==ALLOC_MODE_REUSE ) +seq_printf (seq,",alloc_mode=%s" ,"reuse" );return 0 ; }
@@ -1273,6 +1296,7 @@ static void default_options(struct f2fs_sb_info *sbi) sbi->active_logs =NR_CURSEG_TYPE ; sbi->inline_xattr_size =DEFAULT_INLINE_XATTR_ADDRS ; sbi->whint_mode =WHINT_MODE_OFF ; + sbi->alloc_mode =ALLOC_MODE_DEFAULT ;set_opt (sbi,BG_GC );set_opt (sbi,INLINE_XATTR );
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
Jaegeuk Kim
maintainerPATCH 2/5 f2fs: add auto tuning for small devices
If f2fs is running on top of very small devices, it's worth to avoid abusing free LBAs. In order to achieve that, this patch introduces some parameter tuning.
--- fs/f2fs/segment.h | 2 ++ fs/f2fs/super.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+)
fs/f2fs/segment.h +2 -0
@@ -596,6 +596,8 @@ static inline int utilization(struct f2fs_sb_info *sbi)#define DEF_MIN_FSYNC_BLOCKS 8#define DEF_MIN_HOT_BLOCKS 16 +#define SMALL_VOLUME_SEGMENTS (16 * 512)/* 16GB */ +enum {F2FS_IPU_FORCE ,F2FS_IPU_SSR ,
fs/f2fs/super.c +14 -0
@@ -2512,6 +2512,18 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)return 0 ; } +static void f2fs_tuning_parameters (struct f2fs_sb_info *sbi) +{ +struct f2fs_sm_info *sm_i =SM_I (sbi); + +/* adjust parameters according to the volume size */ +if (sm_i->main_segments <=SMALL_VOLUME_SEGMENTS ) { + sbi->alloc_mode =ALLOC_MODE_REUSE ; + sm_i->dcc_info->discard_granularity =1 ; + sm_i->ipu_policy =1 <<F2FS_IPU_FORCE ; + } +} +static int f2fs_fill_super (struct super_block *sb,void *data,int silent) {struct f2fs_sb_info *sbi;
@@ -2864,6 +2876,8 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)f2fs_join_shrinker (sbi); +f2fs_tuning_parameters (sbi); +f2fs_msg (sbi->sb,KERN_NOTICE ,"Mounted with checkpoint version = %llx" ,cur_cp_version (F2FS_CKPT (sbi)));f2fs_update_time (sbi,CP_TIME );
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
Re: [PATCH 2/5] f2fs: add auto tuning for small devices
Quoted 5 lines · Jaegeuk Kim
If f2fs is running on top of very small devices, it's worth to avoid abusing free LBAs. In order to achieve that, this patch introduces some parameter tuning.
Signed-off-by Jaegeuk Kim <[email protected]>
Thanks,
Jaegeuk Kim
maintainerPATCH 3/5 f2fs: set readdir_ra by default
In reply to Jaegeuk KimIt gives general readdir improvement.
--- fs/f2fs/super.c | 1 + 1 file changed, 1 insertion(+)
fs/f2fs/super.c +1 -0
@@ -1297,6 +1297,7 @@ static void default_options(struct f2fs_sb_info *sbi) sbi->inline_xattr_size =DEFAULT_INLINE_XATTR_ADDRS ; sbi->whint_mode =WHINT_MODE_OFF ; sbi->alloc_mode =ALLOC_MODE_DEFAULT ; + sbi->readdir_ra =1 ;set_opt (sbi,BG_GC );set_opt (sbi,INLINE_XATTR );
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
Re: [PATCH 3/5] f2fs: set readdir_ra by default
Quoted 3 lines · Jaegeuk Kim
It gives general readdir improvement.
Signed-off-by Jaegeuk Kim <[email protected]>
Thanks,
Jaegeuk Kim
maintainerPATCH 4/5 f2fs: issue discard aggressively in the gc_urgent mode
In reply to Jaegeuk KimThis patch avoids to skip discard commands when user sets gc_urgent mode.
--- fs/f2fs/segment.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/segment.c +1 -1
@@ -1727,7 +1727,7 @@ void init_discard_policy(struct discard_policy *dpolicy, }else if (discard_type ==DPOLICY_FORCE ) { dpolicy->min_interval =DEF_MIN_DISCARD_ISSUE_TIME ; dpolicy->max_interval =DEF_MAX_DISCARD_ISSUE_TIME ; - dpolicy->io_aware = true; + dpolicy->io_aware = false; }else if (discard_type ==DPOLICY_FSTRIM ) { dpolicy->io_aware = false; }else if (discard_type ==DPOLICY_UMOUNT ) {
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
Re: [PATCH 4/5] f2fs: issue discard aggressively in the gc_urgent mode
Quoted 3 lines · Jaegeuk Kim
This patch avoids to skip discard commands when user sets
gc_urgentmode.Signed-off-by Jaegeuk Kim <[email protected]>
Thanks,
Re: [PATCH 4/5] f2fs: issue discard aggressively in the gc_urgent mode
In reply to Jaegeuk KimChange log from v1:
- relax more to issue discard commands
This patch avoids to skip discard commands when user sets gc_urgent mode.
--- fs/f2fs/segment.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
fs/f2fs/segment.c +5 -6
@@ -1411,12 +1411,11 @@ static int issue_discard_thread(void *data)if (kthread_should_stop ())return 0 ; -if (dcc->discard_wake) { +if (dcc->discard_wake) dcc->discard_wake =0 ; -if (sbi->gc_thread && sbi->gc_thread->gc_urgent) -init_discard_policy (&dpolicy, -DPOLICY_FORCE ,1 ); - } + +if (sbi->gc_thread && sbi->gc_thread->gc_urgent) +init_discard_policy (&dpolicy,DPOLICY_FORCE ,1 );sb_start_intwrite (sbi->sb);
@@ -1727,7 +1726,7 @@ void init_discard_policy(struct discard_policy *dpolicy, }else if (discard_type ==DPOLICY_FORCE ) { dpolicy->min_interval =DEF_MIN_DISCARD_ISSUE_TIME ; dpolicy->max_interval =DEF_MAX_DISCARD_ISSUE_TIME ; - dpolicy->io_aware = true; + dpolicy->io_aware = false; }else if (discard_type ==DPOLICY_FSTRIM ) { dpolicy->io_aware = false; }else if (discard_type ==DPOLICY_UMOUNT ) {
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
Jaegeuk Kim
maintainerPATCH 5/5 f2fs: don't stop GC if GC is contended
In reply to Jaegeuk KimLet's do GC as much as possible, while gc_urgent is set.
--- fs/f2fs/gc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/f2fs/gc.c +4 -3
@@ -76,14 +76,15 @@ static int gc_thread_func(void *data)* invalidated soon after by user update or deletion. * So, I'd like to wait some time to collect dirty segments. */ -if (!mutex_trylock (&sbi->gc_mutex)) - goto next; -if (gc_th->gc_urgent) { wait_ms = gc_th->urgent_sleep_time; +mutex_lock (&sbi->gc_mutex); goto do_gc; } +if (!mutex_trylock (&sbi->gc_mutex)) + goto next; +if (!is_idle (sbi)) {increase_sleep_time (gc_th, &wait_ms);mutex_unlock (&sbi->gc_mutex);
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
Re: [PATCH 5/5] f2fs: don't stop GC if GC is contended
Quoted 3 lines · Jaegeuk Kim
Let's do GC as much as possible, while
gc_urgentis set.Signed-off-by Jaegeuk Kim <[email protected]>
Thanks,
Hi Jaegeuk,
Quoted 5 lines · Jaegeuk Kim
This patch adds an mount option, "alloc_mode=%s" having two options, "default" and "reuse".
In "alloc_mode=reuse" case, f2fs starts to allocate segments from 0'th segment all the time to reassign segments. It'd be useful for small-sized eMMC parts.
We needs to add Doc for this mount option. ;)
Thanks,
Jaegeuk Kim
maintainerChange log from v1:
- add doc :)
This patch adds an mount option, "alloc_mode=%s" having two options, "default" and "reuse".
In "alloc_mode=reuse" case, f2fs starts to allocate segments from 0'th segment all the time to reassign segments. It'd be useful for small-sized eMMC parts.
--- Documentation/filesystems/f2fs.txt | 2 ++ fs/f2fs/f2fs.h | 8 ++++++++ fs/f2fs/segment.c | 5 +++++ fs/f2fs/super.c | 24 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+)
Documentation/filesystems/f2fs.txt +2 -0
@@ -180,6 +180,8 @@ whint_mode=%s Control which write hints are passed down to block down hints. In "user-based" mode, f2fs tries to pass down hints given by users. And in "fs-based" mode, f2fs passes down hints with its policy. +alloc_mode=%s Adjust block allocation policy, which supports "reuse" + and "default". ================================================================================ DEBUGFS ENTRIES
fs/f2fs/f2fs.h +8 -0
@@ -1043,6 +1043,11 @@ enum { WHINT_MODE_FS, /* pass down hints with F2FS policy */ }; +enum { +ALLOC_MODE_DEFAULT ,/* stay default */ +ALLOC_MODE_REUSE ,/* reuse segments as much as possible */ +}; +struct f2fs_sb_info {struct super_block *sb;/* pointer to VFS super block */ struct proc_dir_entry *s_proc;/* proc entry */
@@ -1229,6 +1234,9 @@ struct f2fs_sb_info {#endif /* For which write hints are passed down to block layer */ int whint_mode; + +/* segment allocation policy */ +int alloc_mode; };#ifdef CONFIG_F2FS_FAULT_INJECTION
fs/f2fs/segment.c +5 -0
@@ -2170,6 +2170,11 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)if (SIT_I (sbi)->last_victim[ALLOC_NEXT ])return SIT_I (sbi)->last_victim[ALLOC_NEXT ]; + +/* find segments from 0 to reuse freed segments */ +if (sbi->alloc_mode ==ALLOC_MODE_REUSE ) +return 0 ; +return CURSEG_I (sbi, type)->segno; }
fs/f2fs/super.c +24 -0
@@ -130,6 +130,7 @@ enum { Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_whint, + Opt_alloc, Opt_err, };
@@ -184,6 +185,7 @@ static match_table_t f2fs_tokens = { {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"}, {Opt_whint, "whint_mode=%s"}, + {Opt_alloc, "alloc_mode=%s"}, {Opt_err, NULL}, };
@@ -700,6 +702,23 @@ static int parse_options(struct super_block *sb, char *options) }kfree (name);break ; +case Opt_alloc: + name =match_strdup (&args[0 ]); +if (!name) +return -ENOMEM ; + +if (strlen (name) ==7 && + !strncmp (name,"default" ,7 )) { + sbi->alloc_mode =ALLOC_MODE_DEFAULT ; + }else if (strlen (name) ==5 && + !strncmp (name,"reuse" ,5 )) { + sbi->alloc_mode =ALLOC_MODE_REUSE ; + }else { +kfree (name); +return -EINVAL ; + } +kfree (name); +break ;default : f2fs_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" or missing value",
@@ -1264,6 +1283,10 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)else if (sbi->whint_mode ==WHINT_MODE_FS )seq_printf (seq,",whint_mode=%s" ,"fs-based" ); +if (sbi->alloc_mode ==ALLOC_MODE_DEFAULT ) +seq_printf (seq,",alloc_mode=%s" ,"default" ); +else if (sbi->alloc_mode ==ALLOC_MODE_REUSE ) +seq_printf (seq,",alloc_mode=%s" ,"reuse" );return 0 ; }
@@ -1273,6 +1296,7 @@ static void default_options(struct f2fs_sb_info *sbi) sbi->active_logs =NR_CURSEG_TYPE ; sbi->inline_xattr_size =DEFAULT_INLINE_XATTR_ADDRS ; sbi->whint_mode =WHINT_MODE_OFF ; + sbi->alloc_mode =ALLOC_MODE_DEFAULT ;set_opt (sbi,BG_GC );set_opt (sbi,INLINE_XATTR );
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
Chao Yu
Reviewed-byQuoted 10 lines · Jaegeuk Kim
Change log from v1:
- add doc :)This patch adds an mount option, "alloc_mode=%s" having two options, "default" and "reuse".
In "alloc_mode=reuse" case, f2fs starts to allocate segments from 0'th segment all the time to reassign segments. It'd be useful for small-sized eMMC parts.
Signed-off-by Jaegeuk Kim <[email protected]>
Thanks,
Chao Yu
maintainerQuoted 8 lines · Jaegeuk Kim
Change log from v1:
- add doc :)This patch adds an mount option, "alloc_mode=%s" having two options, "default" and "reuse".
In "alloc_mode=reuse" case, f2fs starts to allocate segments from 0'th segment all the time to reassign segments. It'd be useful for small-sized eMMC parts.
We have to restore old alloc_mode if we encounter any failure in ->remount, right?
Thanks,
Quoted 128 lines
Signed-off-by Jaegeuk Kim <[email protected]>--- Documentation/filesystems/f2fs.txt | 2 ++ fs/f2fs/f2fs.h | 8 ++++++++ fs/f2fs/segment.c | 5 +++++ fs/f2fs/super.c | 24 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+)Documentation/filesystems/f2fs.txt +2
-0@@ -180,6 +180,8 @@ whint_mode=%s Control which write hints are passed down to block down hints. In "user-based" mode, f2fs tries to pass down hints given by users. And in "fs-based" mode, f2fs passes down hints with its policy. +alloc_mode=%s Adjust block allocation policy, which supports "reuse" + and "default". ================================================================================ DEBUGFS ENTRIESfs/f2fs/f2fs.h +8
-0@@ -1043,6 +1043,11 @@ enum { WHINT_MODE_FS, /* pass down hints with F2FS policy */ }; +enum { +ALLOC_MODE_DEFAULT ,/* stay default */ +ALLOC_MODE_REUSE ,/* reuse segments as much as possible */ +}; +struct f2fs_sb_info {struct super_block *sb;/* pointer to VFS super block */ struct proc_dir_entry *s_proc;/* proc entry */ @@ -1229,6 +1234,9 @@ struct f2fs_sb_info {#endif /* For which write hints are passed down to block layer */ int whint_mode; + +/* segment allocation policy */ +int alloc_mode; };#ifdef CONFIG_F2FS_FAULT_INJECTION fs/f2fs/segment.c +5
-0@@ -2170,6 +2170,11 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)if (SIT_I (sbi)->last_victim[ALLOC_NEXT ])return SIT_I (sbi)->last_victim[ALLOC_NEXT ]; + +/* find segments from 0 to reuse freed segments */ +if (sbi->alloc_mode ==ALLOC_MODE_REUSE ) +return 0 ; +return CURSEG_I (sbi, type)->segno; }fs/f2fs/super.c +24
-0@@ -130,6 +130,7 @@ enum { Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_whint, + Opt_alloc, Opt_err, };@@ -184,6 +185,7 @@ static match_table_t f2fs_tokens = { {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"}, {Opt_whint, "whint_mode=%s"}, + {Opt_alloc, "alloc_mode=%s"}, {Opt_err, NULL}, };@@ -700,6 +702,23 @@ static int parse_options(struct super_block *sb, char *options) }kfree (name);break ; +case Opt_alloc: + name =match_strdup (&args[0 ]); +if (!name) +return -ENOMEM ; + +if (strlen (name) ==7 && + !strncmp (name,"default" ,7 )) { + sbi->alloc_mode =ALLOC_MODE_DEFAULT ; + }else if (strlen (name) ==5 && + !strncmp (name,"reuse" ,5 )) { + sbi->alloc_mode =ALLOC_MODE_REUSE ; + }else { +kfree (name); +return -EINVAL ; + } +kfree (name); +break ;default : f2fs_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" or missing value",@@ -1264,6 +1283,10 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)else if (sbi->whint_mode ==WHINT_MODE_FS )seq_printf (seq,",whint_mode=%s" ,"fs-based" ); +if (sbi->alloc_mode ==ALLOC_MODE_DEFAULT ) +seq_printf (seq,",alloc_mode=%s" ,"default" ); +else if (sbi->alloc_mode ==ALLOC_MODE_REUSE ) +seq_printf (seq,",alloc_mode=%s" ,"reuse" );return 0 ; }@@ -1273,6 +1296,7 @@ static void default_options(struct f2fs_sb_info *sbi) sbi->active_logs =NR_CURSEG_TYPE ; sbi->inline_xattr_size =DEFAULT_INLINE_XATTR_ADDRS ; sbi->whint_mode =WHINT_MODE_OFF ; + sbi->alloc_mode =ALLOC_MODE_DEFAULT ;set_opt (sbi,BG_GC );set_opt (sbi,INLINE_XATTR );
Jaegeuk Kim
maintainerQuoted 11 lines · Chao Yu
Quoted 8 lines · Jaegeuk Kim
Change log from v1:
- add doc :)This patch adds an mount option, "alloc_mode=%s" having two options, "default" and "reuse".
In "alloc_mode=reuse" case, f2fs starts to allocate segments from 0'th segment all the time to reassign segments. It'd be useful for small-sized eMMC parts.
We have to restore old
alloc_modeif we encounter any failure in ->remount, right?
Yup, done.
Quoted 131 lines
Thanks,
Quoted 128 lines
Signed-off-by Jaegeuk Kim <[email protected]>--- Documentation/filesystems/f2fs.txt | 2 ++ fs/f2fs/f2fs.h | 8 ++++++++ fs/f2fs/segment.c | 5 +++++ fs/f2fs/super.c | 24 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+)Documentation/filesystems/f2fs.txt +2
-0@@ -180,6 +180,8 @@ whint_mode=%s Control which write hints are passed down to block down hints. In "user-based" mode, f2fs tries to pass down hints given by users. And in "fs-based" mode, f2fs passes down hints with its policy. +alloc_mode=%s Adjust block allocation policy, which supports "reuse" + and "default". ================================================================================ DEBUGFS ENTRIESfs/f2fs/f2fs.h +8
-0@@ -1043,6 +1043,11 @@ enum { WHINT_MODE_FS, /* pass down hints with F2FS policy */ }; +enum { +ALLOC_MODE_DEFAULT ,/* stay default */ +ALLOC_MODE_REUSE ,/* reuse segments as much as possible */ +}; +struct f2fs_sb_info {struct super_block *sb;/* pointer to VFS super block */ struct proc_dir_entry *s_proc;/* proc entry */ @@ -1229,6 +1234,9 @@ struct f2fs_sb_info {#endif /* For which write hints are passed down to block layer */ int whint_mode; + +/* segment allocation policy */ +int alloc_mode; };#ifdef CONFIG_F2FS_FAULT_INJECTION fs/f2fs/segment.c +5
-0@@ -2170,6 +2170,11 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)if (SIT_I (sbi)->last_victim[ALLOC_NEXT ])return SIT_I (sbi)->last_victim[ALLOC_NEXT ]; + +/* find segments from 0 to reuse freed segments */ +if (sbi->alloc_mode ==ALLOC_MODE_REUSE ) +return 0 ; +return CURSEG_I (sbi, type)->segno; }fs/f2fs/super.c +24
-0@@ -130,6 +130,7 @@ enum { Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_whint, + Opt_alloc, Opt_err, };@@ -184,6 +185,7 @@ static match_table_t f2fs_tokens = { {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"}, {Opt_whint, "whint_mode=%s"}, + {Opt_alloc, "alloc_mode=%s"}, {Opt_err, NULL}, };@@ -700,6 +702,23 @@ static int parse_options(struct super_block *sb, char *options) }kfree (name);break ; +case Opt_alloc: + name =match_strdup (&args[0 ]); +if (!name) +return -ENOMEM ; + +if (strlen (name) ==7 && + !strncmp (name,"default" ,7 )) { + sbi->alloc_mode =ALLOC_MODE_DEFAULT ; + }else if (strlen (name) ==5 && + !strncmp (name,"reuse" ,5 )) { + sbi->alloc_mode =ALLOC_MODE_REUSE ; + }else { +kfree (name); +return -EINVAL ; + } +kfree (name); +break ;default : f2fs_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" or missing value",@@ -1264,6 +1283,10 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)else if (sbi->whint_mode ==WHINT_MODE_FS )seq_printf (seq,",whint_mode=%s" ,"fs-based" ); +if (sbi->alloc_mode ==ALLOC_MODE_DEFAULT ) +seq_printf (seq,",alloc_mode=%s" ,"default" ); +else if (sbi->alloc_mode ==ALLOC_MODE_REUSE ) +seq_printf (seq,",alloc_mode=%s" ,"reuse" );return 0 ; }@@ -1273,6 +1296,7 @@ static void default_options(struct f2fs_sb_info *sbi) sbi->active_logs =NR_CURSEG_TYPE ; sbi->inline_xattr_size =DEFAULT_INLINE_XATTR_ADDRS ; sbi->whint_mode =WHINT_MODE_OFF ; + sbi->alloc_mode =ALLOC_MODE_DEFAULT ;set_opt (sbi,BG_GC );set_opt (sbi,INLINE_XATTR );
Chao Yu
maintainerQuoted 8 lines · Jaegeuk Kim
Change log from v1:
- add doc :)This patch adds an mount option, "alloc_mode=%s" having two options, "default" and "reuse".
In "alloc_mode=reuse" case, f2fs starts to allocate segments from 0'th segment all the time to reassign segments. It'd be useful for small-sized eMMC parts.
We have to restore old alloc_mode if we encounter any failure in ->remount, right?
Thanks,
Quoted 128 lines
Signed-off-by Jaegeuk Kim <[email protected]>--- Documentation/filesystems/f2fs.txt | 2 ++ fs/f2fs/f2fs.h | 8 ++++++++ fs/f2fs/segment.c | 5 +++++ fs/f2fs/super.c | 24 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+)Documentation/filesystems/f2fs.txt +2
-0@@ -180,6 +180,8 @@ whint_mode=%s Control which write hints are passed down to block down hints. In "user-based" mode, f2fs tries to pass down hints given by users. And in "fs-based" mode, f2fs passes down hints with its policy. +alloc_mode=%s Adjust block allocation policy, which supports "reuse" + and "default". ================================================================================ DEBUGFS ENTRIESfs/f2fs/f2fs.h +8
-0@@ -1043,6 +1043,11 @@ enum { WHINT_MODE_FS, /* pass down hints with F2FS policy */ }; +enum { +ALLOC_MODE_DEFAULT ,/* stay default */ +ALLOC_MODE_REUSE ,/* reuse segments as much as possible */ +}; +struct f2fs_sb_info {struct super_block *sb;/* pointer to VFS super block */ struct proc_dir_entry *s_proc;/* proc entry */ @@ -1229,6 +1234,9 @@ struct f2fs_sb_info {#endif /* For which write hints are passed down to block layer */ int whint_mode; + +/* segment allocation policy */ +int alloc_mode; };#ifdef CONFIG_F2FS_FAULT_INJECTION fs/f2fs/segment.c +5
-0@@ -2170,6 +2170,11 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)if (SIT_I (sbi)->last_victim[ALLOC_NEXT ])return SIT_I (sbi)->last_victim[ALLOC_NEXT ]; + +/* find segments from 0 to reuse freed segments */ +if (sbi->alloc_mode ==ALLOC_MODE_REUSE ) +return 0 ; +return CURSEG_I (sbi, type)->segno; }fs/f2fs/super.c +24
-0@@ -130,6 +130,7 @@ enum { Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_whint, + Opt_alloc, Opt_err, };@@ -184,6 +185,7 @@ static match_table_t f2fs_tokens = { {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"}, {Opt_whint, "whint_mode=%s"}, + {Opt_alloc, "alloc_mode=%s"}, {Opt_err, NULL}, };@@ -700,6 +702,23 @@ static int parse_options(struct super_block *sb, char *options) }kfree (name);break ; +case Opt_alloc: + name =match_strdup (&args[0 ]); +if (!name) +return -ENOMEM ; + +if (strlen (name) ==7 && + !strncmp (name,"default" ,7 )) { + sbi->alloc_mode =ALLOC_MODE_DEFAULT ; + }else if (strlen (name) ==5 && + !strncmp (name,"reuse" ,5 )) { + sbi->alloc_mode =ALLOC_MODE_REUSE ; + }else { +kfree (name); +return -EINVAL ; + } +kfree (name); +break ;default : f2fs_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" or missing value",@@ -1264,6 +1283,10 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)else if (sbi->whint_mode ==WHINT_MODE_FS )seq_printf (seq,",whint_mode=%s" ,"fs-based" ); +if (sbi->alloc_mode ==ALLOC_MODE_DEFAULT ) +seq_printf (seq,",alloc_mode=%s" ,"default" ); +else if (sbi->alloc_mode ==ALLOC_MODE_REUSE ) +seq_printf (seq,",alloc_mode=%s" ,"reuse" );return 0 ; }@@ -1273,6 +1296,7 @@ static void default_options(struct f2fs_sb_info *sbi) sbi->active_logs =NR_CURSEG_TYPE ; sbi->inline_xattr_size =DEFAULT_INLINE_XATTR_ADDRS ; sbi->whint_mode =WHINT_MODE_OFF ; + sbi->alloc_mode =ALLOC_MODE_DEFAULT ;set_opt (sbi,BG_GC );set_opt (sbi,INLINE_XATTR );