Skip to content

Commit 009a824

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: add a sysfs node to limit max read extent count per-inode
Quoted: "at this time, there are still 1086911 extent nodes in this zombie extent tree that need to be cleaned up. crash_arm64_sprd_v8.0.3++> extent_tree.node_cnt ffffff80896cc500 node_cnt = { counter = 1086911 }, " As reported by Xiuhong, there will be a huge number of extent nodes in extent tree, it may potentially cause: - slab memory fragments - extreme long time shrink on extent tree - low mapping efficiency Let's add a sysfs node to limit max read extent count for each inode, by default, value of this threshold is 10240, it can be updated according to user's requirement. Reported-by: Xiuhong Wang <xiuhong.wang@unisoc.com> Closes: https://lore.kernel.org/linux-f2fs-devel/20241112110627.1314632-1-xiuhong.wang@unisoc.com/ Signed-off-by: Xiuhong Wang <xiuhong.wang@unisoc.com> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com> Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 3fc5d5a commit 009a824

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

Documentation/ABI/testing/sysfs-fs-f2fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,3 +822,9 @@ Description: It controls the valid block ratio threshold not to trigger excessiv
822822
for zoned deivces. The initial value of it is 95(%). F2FS will stop the
823823
background GC thread from intiating GC for sections having valid blocks
824824
exceeding the ratio.
825+
826+
What: /sys/fs/f2fs/<disk>/max_read_extent_count
827+
Date: November 2024
828+
Contact: "Chao Yu" <chao@kernel.org>
829+
Description: It controls max read extent count for per-inode, the value of threshold
830+
is 10240 by default.

fs/f2fs/extent_cache.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,9 @@ static void __update_extent_tree_range(struct inode *inode,
717717
}
718718

719719
if (end < org_end && (type != EX_READ ||
720-
org_end - end >= F2FS_MIN_EXTENT_LEN)) {
720+
(org_end - end >= F2FS_MIN_EXTENT_LEN &&
721+
atomic_read(&et->node_cnt) <
722+
sbi->max_read_extent_count))) {
721723
if (parts) {
722724
__set_extent_info(&ei,
723725
end, org_end - end,
@@ -1212,6 +1214,7 @@ void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi)
12121214
sbi->hot_data_age_threshold = DEF_HOT_DATA_AGE_THRESHOLD;
12131215
sbi->warm_data_age_threshold = DEF_WARM_DATA_AGE_THRESHOLD;
12141216
sbi->last_age_weight = LAST_AGE_WEIGHT;
1217+
sbi->max_read_extent_count = DEF_MAX_READ_EXTENT_COUNT;
12151218
}
12161219

12171220
int __init f2fs_create_extent_cache(void)

fs/f2fs/f2fs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,9 @@ enum {
635635
#define DEF_HOT_DATA_AGE_THRESHOLD 262144
636636
#define DEF_WARM_DATA_AGE_THRESHOLD 2621440
637637

638+
/* default max read extent count per inode */
639+
#define DEF_MAX_READ_EXTENT_COUNT 10240
640+
638641
/* extent cache type */
639642
enum extent_type {
640643
EX_READ,
@@ -1619,6 +1622,7 @@ struct f2fs_sb_info {
16191622
/* for extent tree cache */
16201623
struct extent_tree_info extent_tree[NR_EXTENT_CACHES];
16211624
atomic64_t allocated_data_blocks; /* for block age extent_cache */
1625+
unsigned int max_read_extent_count; /* max read extent count per inode */
16221626

16231627
/* The threshold used for hot and warm data seperation*/
16241628
unsigned int hot_data_age_threshold;

fs/f2fs/sysfs.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
787787
return count;
788788
}
789789

790+
if (!strcmp(a->attr.name, "max_read_extent_count")) {
791+
if (t > UINT_MAX)
792+
return -EINVAL;
793+
*ui = (unsigned int)t;
794+
return count;
795+
}
796+
790797
if (!strcmp(a->attr.name, "ipu_policy")) {
791798
if (t >= BIT(F2FS_IPU_MAX))
792799
return -EINVAL;
@@ -1052,6 +1059,8 @@ F2FS_SBI_GENERAL_RW_ATTR(revoked_atomic_block);
10521059
F2FS_SBI_GENERAL_RW_ATTR(hot_data_age_threshold);
10531060
F2FS_SBI_GENERAL_RW_ATTR(warm_data_age_threshold);
10541061
F2FS_SBI_GENERAL_RW_ATTR(last_age_weight);
1062+
/* read extent cache */
1063+
F2FS_SBI_GENERAL_RW_ATTR(max_read_extent_count);
10551064
#ifdef CONFIG_BLK_DEV_ZONED
10561065
F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec);
10571066
F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy);
@@ -1242,6 +1251,7 @@ static struct attribute *f2fs_attrs[] = {
12421251
ATTR_LIST(hot_data_age_threshold),
12431252
ATTR_LIST(warm_data_age_threshold),
12441253
ATTR_LIST(last_age_weight),
1254+
ATTR_LIST(max_read_extent_count),
12451255
NULL,
12461256
};
12471257
ATTRIBUTE_GROUPS(f2fs);

0 commit comments

Comments
 (0)