Skip to content

Commit 5219093

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: sysfs: introduce critical_task_priority
This patch introduces /sys/fs/f2fs/<disk>/critical_task_priority, w/ this new sysfs interface, we can tune priority of f2fs_ckpt thread and f2fs_gc thread. Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent bc36777 commit 5219093

6 files changed

Lines changed: 34 additions & 0 deletions

File tree

Documentation/ABI/testing/sysfs-fs-f2fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,3 +987,11 @@ Contact: "Chao Yu" <chao@kernel.org>
987987
Description: f2fs can tune priority of thread which has entered into critical region covered by
988988
f2fs rwsemphore lock. This sysfs entry can be used to control priority value, the
989989
range is [100,139], by default the value is 120.
990+
991+
What: /sys/fs/f2fs/<disk>/critical_task_priority
992+
Date: February 2026
993+
Contact: "Chao Yu" <chao@kernel.org>
994+
Description: It can be used to tune priority of f2fs critical task, e.g. f2fs_ckpt, f2fs_gc
995+
threads, limitation as below:
996+
- it requires user has CAP_SYS_NICE capability.
997+
- the range is [100, 139], by default the value is 100.

fs/f2fs/checkpoint.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,6 +2158,8 @@ int f2fs_start_ckpt_thread(struct f2fs_sb_info *sbi)
21582158
}
21592159

21602160
set_task_ioprio(cprc->f2fs_issue_ckpt, cprc->ckpt_thread_ioprio);
2161+
set_user_nice(cprc->f2fs_issue_ckpt,
2162+
PRIO_TO_NICE(sbi->critical_task_priority));
21612163

21622164
return 0;
21632165
}

fs/f2fs/f2fs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,7 @@ enum node_type {
15931593
#define MAX_LOCK_ELAPSED_TIME 500
15941594

15951595
#define F2FS_DEFAULT_TASK_PRIORITY (DEFAULT_PRIO)
1596+
#define F2FS_CRITICAL_TASK_PRIORITY NICE_TO_PRIO(0)
15961597

15971598
static inline int f2fs_test_bit(unsigned int nr, char *addr);
15981599
static inline void f2fs_set_bit(unsigned int nr, char *addr);
@@ -2010,6 +2011,9 @@ struct f2fs_sb_info {
20102011
/* adjust priority for task which is in critical region covered by lock */
20112012
unsigned int lock_duration_priority;
20122013

2014+
/* priority for critical task, e.g. f2fs_ckpt, f2fs_gc threads */
2015+
long critical_task_priority;
2016+
20132017
#ifdef CONFIG_F2FS_FS_COMPRESSION
20142018
struct kmem_cache *page_array_slab; /* page array entry */
20152019
unsigned int page_array_slab_size; /* default page array slab size */

fs/f2fs/gc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ int f2fs_start_gc_thread(struct f2fs_sb_info *sbi)
234234
return err;
235235
}
236236

237+
set_user_nice(gc_th->f2fs_gc_task,
238+
PRIO_TO_NICE(sbi->critical_task_priority));
237239
return 0;
238240
}
239241

fs/f2fs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4340,6 +4340,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
43404340
sbi->max_lock_elapsed_time = MAX_LOCK_ELAPSED_TIME;
43414341
sbi->adjust_lock_priority = 0;
43424342
sbi->lock_duration_priority = F2FS_DEFAULT_TASK_PRIORITY;
4343+
sbi->critical_task_priority = F2FS_CRITICAL_TASK_PRIORITY;
43434344

43444345
sbi->sum_blocksize = f2fs_sb_has_packed_ssa(sbi) ?
43454346
4096 : sbi->blocksize;

fs/f2fs/sysfs.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,21 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
969969
return count;
970970
}
971971

972+
if (!strcmp(a->attr.name, "critical_task_priority")) {
973+
if (t < NICE_TO_PRIO(MIN_NICE) || t > NICE_TO_PRIO(MAX_NICE))
974+
return -EINVAL;
975+
if (!capable(CAP_SYS_NICE))
976+
return -EPERM;
977+
sbi->critical_task_priority = t;
978+
if (sbi->cprc_info.f2fs_issue_ckpt)
979+
set_user_nice(sbi->cprc_info.f2fs_issue_ckpt,
980+
PRIO_TO_NICE(sbi->critical_task_priority));
981+
if (sbi->gc_thread && sbi->gc_thread->f2fs_gc_task)
982+
set_user_nice(sbi->gc_thread->f2fs_gc_task,
983+
PRIO_TO_NICE(sbi->critical_task_priority));
984+
return count;
985+
}
986+
972987
__sbi_store_value(a, sbi, ptr + a->offset, t);
973988

974989
return count;
@@ -1288,6 +1303,7 @@ F2FS_SBI_GENERAL_RW_ATTR(bggc_io_aware);
12881303
F2FS_SBI_GENERAL_RW_ATTR(max_lock_elapsed_time);
12891304
F2FS_SBI_GENERAL_RW_ATTR(lock_duration_priority);
12901305
F2FS_SBI_GENERAL_RW_ATTR(adjust_lock_priority);
1306+
F2FS_SBI_GENERAL_RW_ATTR(critical_task_priority);
12911307

12921308
/* STAT_INFO ATTR */
12931309
#ifdef CONFIG_F2FS_STAT_FS
@@ -1496,6 +1512,7 @@ static struct attribute *f2fs_attrs[] = {
14961512
ATTR_LIST(max_lock_elapsed_time),
14971513
ATTR_LIST(lock_duration_priority),
14981514
ATTR_LIST(adjust_lock_priority),
1515+
ATTR_LIST(critical_task_priority),
14991516
NULL,
15001517
};
15011518
ATTRIBUTE_GROUPS(f2fs);

0 commit comments

Comments
 (0)