Re: [PATCH 1/3] f2fs: fix to alloc_mode changed after remount on a small volume device

Yuwei Guan
2022-11-14T16:13:23Z

On 2022/11/14 22:42, Chao Yu wrote:
> On 2022/11/12 16:32, Yuwei Guan wrote:
>> The commit 84b89e5d943d8 ("f2fs: add auto tuning for small devices") add
>> tuning for small volume device, now support to tune alloce_mode to
>> 'reuse'
>> if it's small size. But the alloc_mode will change to 'default' when do
>> remount on this small size dievce.
>>
>> The commit 4cac90d5491c9 ("f2fs: relocate readdir_ra configure
>> initialization") relocates readdir_ra variable to tuning process.
>>
>> This patch fo fix alloc_mode changed when do remount for a small volume
>> device.
>>
>> For a small device,
>> - alloc_mode will keep 'reuse', if no alloc_mode option in remount
>>    command,
>> - alloc_mode will be set as remount command, if it has 'alloc_mode='.
>>
>> Signed-off-by: Yuwei Guan <Yuwei.Guan@zeekrlife.com>
>> ---
>>   fs/f2fs/super.c | 37 ++++++++++++++++++++-----------------
>>   1 file changed, 20 insertions(+), 17 deletions(-)
>>
>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
>> index 3834ead04620..2f36824ff84b 100644
>> --- a/fs/f2fs/super.c
>> +++ b/fs/f2fs/super.c
>> @@ -2190,6 +2190,23 @@ static void f2fs_enable_checkpoint(struct
>> f2fs_sb_info *sbi)
>>       f2fs_flush_ckpt_thread(sbi);
>>   }
>>   +static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi, bool
>> is_remount)
>> +{
>> +    struct f2fs_sm_info *sm_i = SM_I(sbi);
>> +
>> +    /* adjust parameters according to the volume size */
>> +    if (sm_i->main_segments <= SMALL_VOLUME_SEGMENTS) {
>> +        F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
>
> How about moving above logic into default_options()?
>
Hi Chao,

'sm_i->main_segments' init in func 'f2fs_build_segment_manager()',

when do fill super process, so it cannot move into default_options().

> Thanks,
>
>> +        if (f2fs_block_unit_discard(sbi))
>> +            sm_i->dcc_info->discard_granularity = 1;
>> +        sm_i->ipu_policy = 1 << F2FS_IPU_FORCE |
>> +                    1 << F2FS_IPU_HONOR_OPU_WRITE;
>> +    }
>> +
>> +    if (!is_remount)
>> +        sbi->readdir_ra = 1;
>> +}
>> +
>>   static int f2fs_remount(struct super_block *sb, int *flags, char
>> *data)
>>   {
>>       struct f2fs_sb_info *sbi = F2FS_SB(sb);
>> @@ -2248,6 +2265,8 @@ static int f2fs_remount(struct super_block *sb,
>> int *flags, char *data)
>>         default_options(sbi);
>>   +    f2fs_tuning_parameters(sbi, true);
>> +
>>       /* parse mount options */
>>       err = parse_options(sb, data, true);
>>       if (err)
>> @@ -4054,22 +4073,6 @@ static int f2fs_setup_casefold(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) {
>> -        F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
>> -        if (f2fs_block_unit_discard(sbi))
>> -            sm_i->dcc_info->discard_granularity = 1;
>> -        sm_i->ipu_policy = 1 << F2FS_IPU_FORCE |
>> -                    1 << F2FS_IPU_HONOR_OPU_WRITE;
>> -    }
>> -
>> -    sbi->readdir_ra = 1;
>> -}
>> -
>>   static int f2fs_fill_super(struct super_block *sb, void *data, int
>> silent)
>>   {
>>       struct f2fs_sb_info *sbi;
>> @@ -4475,7 +4478,7 @@ static int f2fs_fill_super(struct super_block
>> *sb, void *data, int silent)
>>         f2fs_join_shrinker(sbi);
>>   -    f2fs_tuning_parameters(sbi);
>> +    f2fs_tuning_parameters(sbi, false);
>>         f2fs_notice(sbi, "Mounted with checkpoint version = %llx",
>>               cur_cp_version(F2FS_CKPT(sbi)));