f2fs: introduce blk_alloc_mode mount option
Subsystems (2)
PATCH 1/1 f2fs: introduce blk_alloc_mode mount option
From: Daeho Jeong <[email protected]>
Added a mount option to control block allocation mode for filesystem developer to simulate filesystem fragmentation and after-GC situation for experimental reasons to understand the filesystem behaviors well under the severe condition. This supports "normal", "seg_random" and "blk_random:<num>" options.
"normal" (default): f2fs allocates blocks in the normal way. "seg_random": f2fs allocates a new segment in ramdom position.
With this, we can simulate the after-GC condition.
"blk_random:<num>": We can make f2fs allocate only 1..<num> blocks
in a row and forcibly change the segment randomly. With this, the newly allocated blocks will be scatter throughout the whole partition and we can simulate filesystem fragmentation condition.
--- Documentation/filesystems/f2fs.rst | 16 ++++++++++ fs/f2fs/f2fs.h | 17 +++++++++++ fs/f2fs/gc.c | 5 +++- fs/f2fs/segment.c | 12 ++++++++ fs/f2fs/super.c | 47 ++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 1 deletion(-)
Documentation/filesystems/f2fs.rst +16 -0
@@ -312,6 +312,22 @@ inlinecrypt When possible, encrypt/decrypt the contents of encrypted Documentation/block/inline-encryption.rst. atgc Enable age-threshold garbage collection, it provides high effectiveness and efficiency on background GC. +bl_alloc_mode=%s Control block allocation mode. This is a developer option + for experiments to simulate filesystem fragmentation and + after-GC situation. The developers use this mode to understand + filesystem fragmentation and after-GC condition well, and + eventually get the insight to handle them better. + This supports "normal", "seg_random" and "blk_random:<num>" modes. + In "normal" mode (default), f2fs allocates blocks in the normal way. + In "seg_random", f2fs allocates a new segment in ramdom position. + With this, we can simulate the after-GC condition. + In "blk_random:<num>", we can make f2fs allocate only 1..<num> + blocks in a segment and forcibly change the segment randomly. + You can set the <num> within 1 .. <blocks per segment> number. + With this, the newly allocated blocks will be scatter throughout + the whole partition and we can simulate filesystem fragmentation + condition. Please, use this option for your experiments and we + strongly recommand a filesystem format after using this option. ======================== ============================================================ Debugfs Entries
fs/f2fs/f2fs.h +17 -0
@@ -155,6 +155,9 @@ struct f2fs_mount_info {int compress_mode;/* compression mode */ unsigned char extensions[COMPRESS_EXT_NUM ][F2FS_EXTENSION_LEN ];/* extensions */ unsigned char noextensions[COMPRESS_EXT_NUM ][F2FS_EXTENSION_LEN ];/* extensions */ + +int blk_alloc_mode;/* block allocation mode */ +int blk_alloc_random_max;/* the maximum chunk size for block random allocation mode */ };#define F2FS_FEATURE_ENCRYPT 0x0001
@@ -1740,6 +1743,8 @@ struct f2fs_sb_info {unsigned long seq_file_ra_mul;/* multiplier for ra_pages of seq. files in fadvise */ +int blk_alloc_remained;/* remained block count for this block allocation period */ +#ifdef CONFIG_F2FS_FS_COMPRESSION struct kmem_cache *page_array_slab;/* page array entry */ unsigned int page_array_slab_size;/* default page array slab size */
@@ -3619,6 +3624,18 @@ unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi,unsigned int f2fs_usable_blks_in_seg (struct f2fs_sb_info *sbi,unsigned int segno); +enum { +BLK_ALLOC_MODE_NORMAL ,/* normal block allocation mode */ +BLK_ALLOC_MODE_SEG_RANDOM ,/* make segment allocation random */ +BLK_ALLOC_MODE_BLK_RANDOM ,/* make block allocation random */ +}; + +static inline bool f2fs_need_seg_random (struct f2fs_sb_info *sbi) +{ +return F2FS_OPTION (sbi).blk_alloc_mode ==BLK_ALLOC_MODE_SEG_RANDOM || +F2FS_OPTION (sbi).blk_alloc_mode ==BLK_ALLOC_MODE_BLK_RANDOM ; +} +/* * checkpoint.c */
fs/f2fs/gc.c +4 -1
@@ -14,6 +14,7 @@#include <linux/delay.h> #include <linux/freezer.h> #include <linux/sched/signal.h> +#include <linux/random.h> #include "f2fs.h" #include "node.h"
@@ -256,7 +257,9 @@ static void select_policy(struct f2fs_sb_info *sbi, int gc_type, p->max_search = sbi->max_victim_search;/* let's select beginning hot/small space first in no_heap mode*/ -if (test_opt (sbi,NOHEAP ) && +if (f2fs_need_seg_random (sbi)) + p->offset =prandom_u32 () % (MAIN_SECS (sbi) * sbi->segs_per_sec); +else if (test_opt (sbi,NOHEAP ) && (type ==CURSEG_HOT_DATA ||IS_NODESEG (type))) p->offset =0 ;else
fs/f2fs/segment.c +12 -0
@@ -15,6 +15,7 @@#include <linux/timer.h> #include <linux/freezer.h> #include <linux/sched/signal.h> +#include <linux/random.h> #include "f2fs.h" #include "segment.h"
@@ -2587,6 +2588,8 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)unsigned short seg_type = curseg->seg_type;sanity_check_seg_type (sbi, seg_type); +if (f2fs_need_seg_random (sbi)) +return prandom_u32 () % (MAIN_SECS (sbi) * sbi->segs_per_sec);/* if segs_per_sec is large than 1, we need to keep original policy. */ if (__is_large_section (sbi))
@@ -3150,6 +3153,15 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)static bool __has_curseg_space (struct f2fs_sb_info *sbi,struct curseg_info *curseg) { +/* To allocate block chunks in different sizes, use random number */ +if (F2FS_OPTION (sbi).blk_alloc_mode ==BLK_ALLOC_MODE_BLK_RANDOM ) { +if (--sbi->blk_alloc_remained <0 ) { + sbi->blk_alloc_remained =prandom_u32 () % +F2FS_OPTION (sbi).blk_alloc_random_max; +return false; + } + } +return curseg->next_blkoff <f2fs_usable_blks_in_seg (sbi, curseg->segno); }
fs/f2fs/super.c +47 -0
77 lines not on this page · raw message
Signature · 1 line
2.32.0.605.g8dce9f2422-goog