Skip to content

Commit c521a6a

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix to limit gc_pin_file_threshold
type of f2fs_inode.i_gc_failures, f2fs_inode_info.i_gc_failures, and f2fs_sb_info.gc_pin_file_threshold is __le16, unsigned int, and u64, so it will cause truncation during comparison and persistence. Unifying variable of these three variables to unsigned short, and add an upper boundary limitation for gc_pin_file_threshold. Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 968c4f7 commit c521a6a

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

Documentation/ABI/testing/sysfs-fs-f2fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ Date: January 2018
331331
Contact: Jaegeuk Kim <[email protected]>
332332
Description: This indicates how many GC can be failed for the pinned
333333
file. If it exceeds this, F2FS doesn't guarantee its pinning
334-
state. 2048 trials is set by default.
334+
state. 2048 trials is set by default, and 65535 as maximum.
335335

336336
What: /sys/fs/f2fs/<disk>/extension_list
337337
Date: February 2018

fs/f2fs/f2fs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ struct f2fs_inode_info {
813813
unsigned char i_dir_level; /* use for dentry level for large dir */
814814
union {
815815
unsigned int i_current_depth; /* only for directory depth */
816-
unsigned int i_gc_failures; /* for gc failure statistic */
816+
unsigned short i_gc_failures; /* for gc failure statistic */
817817
};
818818
unsigned int i_pino; /* parent inode number */
819819
umode_t i_acl_mode; /* keep file acl mode temporarily */
@@ -1673,7 +1673,7 @@ struct f2fs_sb_info {
16731673
unsigned long long skipped_gc_rwsem; /* FG_GC only */
16741674

16751675
/* threshold for gc trials on pinned files */
1676-
u64 gc_pin_file_threshold;
1676+
unsigned short gc_pin_file_threshold;
16771677
struct f2fs_rwsem pin_sem;
16781678

16791679
/* maximum # of trials to find a victim segment for SSR and GC */

fs/f2fs/file.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,16 +3215,17 @@ int f2fs_pin_file_control(struct inode *inode, bool inc)
32153215
struct f2fs_inode_info *fi = F2FS_I(inode);
32163216
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
32173217

3218-
/* Use i_gc_failures for normal file as a risk signal. */
3219-
if (inc)
3220-
f2fs_i_gc_failures_write(inode, fi->i_gc_failures + 1);
3221-
3222-
if (fi->i_gc_failures > sbi->gc_pin_file_threshold) {
3218+
if (fi->i_gc_failures >= sbi->gc_pin_file_threshold) {
32233219
f2fs_warn(sbi, "%s: Enable GC = ino %lx after %x GC trials",
32243220
__func__, inode->i_ino, fi->i_gc_failures);
32253221
clear_inode_flag(inode, FI_PIN_FILE);
32263222
return -EAGAIN;
32273223
}
3224+
3225+
/* Use i_gc_failures for normal file as a risk signal. */
3226+
if (inc)
3227+
f2fs_i_gc_failures_write(inode, fi->i_gc_failures + 1);
3228+
32283229
return 0;
32293230
}
32303231

fs/f2fs/gc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define LIMIT_FREE_BLOCK 40 /* percentage over invalid + free space */
2727

2828
#define DEF_GC_FAILED_PINNED_FILES 2048
29+
#define MAX_GC_FAILED_PINNED_FILES USHRT_MAX
2930

3031
/* Search max. number of dirty segments to select a victim segment */
3132
#define DEF_MAX_VICTIM_SEARCH 4096 /* covers 8GB */

fs/f2fs/sysfs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
675675
return count;
676676
}
677677

678+
if (!strcmp(a->attr.name, "gc_pin_file_threshold")) {
679+
if (t > MAX_GC_FAILED_PINNED_FILES)
680+
return -EINVAL;
681+
sbi->gc_pin_file_threshold = t;
682+
return count;
683+
}
684+
678685
if (!strcmp(a->attr.name, "gc_reclaimed_segments")) {
679686
if (t != 0)
680687
return -EINVAL;

0 commit comments

Comments
 (0)