FROMGIT: f2fs: add sysfs nodes to set last_age_weight

Bug: 267580491
(cherry picked from commit d23be468eada21c828058e0e8d60409eaec373ab
 https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git dev)
Signed-off-by: qixiaoyu1 <qixiaoyu1@xiaomi.com>
Signed-off-by: xiongping1 <xiongping1@xiaomi.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Change-Id: I88b795ec90f4589676daed4919db31b26574c84b
This commit is contained in:
qixiaoyu1
2022-12-20 16:16:29 +08:00
committed by Treehugger Robot
parent 899476c3af
commit 3fcc69ca4d
4 changed files with 26 additions and 6 deletions

View File

@@ -528,3 +528,8 @@ Contact: "Ping Xiong" <xiongping1@xiaomi.com>
Description: When DATA SEPARATION is on, it controls the age threshold to indicate Description: When DATA SEPARATION is on, it controls the age threshold to indicate
the data blocks as warm. By default it was initialized as 2621440 blocks the data blocks as warm. By default it was initialized as 2621440 blocks
(equals to 10GB). (equals to 10GB).
What: /sys/fs/f2fs/<disk>/last_age_weight
Date: January 2023
Contact: "Ping Xiong" <xiongping1@xiaomi.com>
Description: When DATA SEPARATION is on, it controls the weight of last data block age.

View File

@@ -870,19 +870,21 @@ unlock_out:
} }
#endif #endif
static unsigned long long __calculate_block_age(unsigned long long new, static unsigned long long __calculate_block_age(struct f2fs_sb_info *sbi,
unsigned long long new,
unsigned long long old) unsigned long long old)
{ {
unsigned int rem_old, rem_new; unsigned int rem_old, rem_new;
unsigned long long res; unsigned long long res;
unsigned int weight = sbi->last_age_weight;
res = div_u64_rem(new, 100, &rem_new) * (100 - LAST_AGE_WEIGHT) res = div_u64_rem(new, 100, &rem_new) * (100 - weight)
+ div_u64_rem(old, 100, &rem_old) * LAST_AGE_WEIGHT; + div_u64_rem(old, 100, &rem_old) * weight;
if (rem_new) if (rem_new)
res += rem_new * (100 - LAST_AGE_WEIGHT) / 100; res += rem_new * (100 - weight) / 100;
if (rem_old) if (rem_old)
res += rem_old * LAST_AGE_WEIGHT / 100; res += rem_old * weight / 100;
return res; return res;
} }
@@ -916,7 +918,7 @@ static int __get_new_block_age(struct inode *inode, struct extent_info *ei,
cur_age = ULLONG_MAX - tei.last_blocks + cur_blocks; cur_age = ULLONG_MAX - tei.last_blocks + cur_blocks;
if (tei.age) if (tei.age)
ei->age = __calculate_block_age(cur_age, tei.age); ei->age = __calculate_block_age(sbi, cur_age, tei.age);
else else
ei->age = cur_age; ei->age = cur_age;
ei->last_blocks = cur_blocks; ei->last_blocks = cur_blocks;
@@ -1233,6 +1235,7 @@ void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi)
atomic64_set(&sbi->allocated_data_blocks, 0); atomic64_set(&sbi->allocated_data_blocks, 0);
sbi->hot_data_age_threshold = DEF_HOT_DATA_AGE_THRESHOLD; sbi->hot_data_age_threshold = DEF_HOT_DATA_AGE_THRESHOLD;
sbi->warm_data_age_threshold = DEF_WARM_DATA_AGE_THRESHOLD; sbi->warm_data_age_threshold = DEF_WARM_DATA_AGE_THRESHOLD;
sbi->last_age_weight = LAST_AGE_WEIGHT;
} }
int __init f2fs_create_extent_cache(void) int __init f2fs_create_extent_cache(void)

View File

@@ -1627,6 +1627,7 @@ struct f2fs_sb_info {
/* The threshold used for hot and warm data seperation*/ /* The threshold used for hot and warm data seperation*/
unsigned int hot_data_age_threshold; unsigned int hot_data_age_threshold;
unsigned int warm_data_age_threshold; unsigned int warm_data_age_threshold;
unsigned int last_age_weight;
/* basic filesystem units */ /* basic filesystem units */
unsigned int log_sectors_per_block; /* log2 sectors per block */ unsigned int log_sectors_per_block; /* log2 sectors per block */

View File

@@ -567,6 +567,15 @@ out:
return count; return count;
} }
if (!strcmp(a->attr.name, "last_age_weight")) {
if (t > 100)
return -EINVAL;
if (t == *ui)
return count;
*ui = (unsigned int)t;
return count;
}
*ui = (unsigned int)t; *ui = (unsigned int)t;
return count; return count;
@@ -799,6 +808,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_reclaimed_segments, gc_reclaimed_segs);
/* For block age extent cache */ /* For block age extent cache */
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, hot_data_age_threshold, hot_data_age_threshold); F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, hot_data_age_threshold, hot_data_age_threshold);
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, warm_data_age_threshold, warm_data_age_threshold); F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, warm_data_age_threshold, warm_data_age_threshold);
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, last_age_weight, last_age_weight);
#define ATTR_LIST(name) (&f2fs_attr_##name.attr) #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
static struct attribute *f2fs_attrs[] = { static struct attribute *f2fs_attrs[] = {
@@ -877,6 +887,7 @@ static struct attribute *f2fs_attrs[] = {
ATTR_LIST(gc_reclaimed_segments), ATTR_LIST(gc_reclaimed_segments),
ATTR_LIST(hot_data_age_threshold), ATTR_LIST(hot_data_age_threshold),
ATTR_LIST(warm_data_age_threshold), ATTR_LIST(warm_data_age_threshold),
ATTR_LIST(last_age_weight),
NULL, NULL,
}; };
ATTRIBUTE_GROUPS(f2fs); ATTRIBUTE_GROUPS(f2fs);