From nobody Sat Feb 7 18:16:09 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 083EE3EBF11 for ; Thu, 5 Feb 2026 02:46:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770259578; cv=none; b=CsfuIMMcLK2eYA0+vj3a9m5MhZRdQJuLw4kAbwrgFit9FYFbFSTzz+N7DP6swevXCkNetBFZlK0rLiRiNMB1hpSwWxQFGMGTOleQNedAtyrvCKf4LCk3KCJYVh+jpp2YQnVNwbcCxkBeQeef7+cHsnAlTDkZyMJsspYTrbcbNbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770259578; c=relaxed/simple; bh=qajNYh1cYAOxjGPeTY7J0Zy6nCZS9ZMhYi30+EVTHI4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=JQ+aJcaBrUhMKPH4Bhw1xfhAIEnvdZWLFOxOTU+j8rbT9H8vX/7IKwwvwm95DOBXMYQirryoAFN5OLGdmY8u5hrgO+jIn7Oy/9T1/KaSef9D1EFpPZRsXdPatCfOrPEFWBIA151szMUcfbcLbs5jcDnpSTyUNGq+DJSGnHqNi+Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CBWxg/uS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CBWxg/uS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 673CBC4CEF7; Thu, 5 Feb 2026 02:46:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770259577; bh=qajNYh1cYAOxjGPeTY7J0Zy6nCZS9ZMhYi30+EVTHI4=; h=From:To:Cc:Subject:Date:From; b=CBWxg/uS54atrWl6dyPIaTvBFg5rdO08YR+Bgr30d+yKmkEThQAozwRnEDgENtNKf qSyDD93BDIThvv7z/xrDSD88HU3JEf2KWVfp2Jt5vCzmVyCEY+2Hg7KU0oBDl0u3uC PnJ9t92pzAbFllmrO3Ymj779FD/O67hlqylFB8xdJU29zZaQjbZkkb5qHh2I4IT8Hx XYLKByyeGpwWbRjlw2+GiUSayV3gcmAW0lDTQknqDL4oEqLMxirTCBh7tVi+ZZHom0 9eYx42MpT4wgddKcTE7cJb+Vxm3qvGNA42xwCwcWjxdUvIUsWVm1foWrmgC7i09jJ2 B30VIRJM5gCpg== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH] f2fs: sysfs: introduce critical_task_priority Date: Wed, 4 Feb 2026 11:05:01 +0800 Message-Id: <20260204030501.85441-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch introduces /sys/fs/f2fs//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 --- Documentation/ABI/testing/sysfs-fs-f2fs | 8 ++++++++ fs/f2fs/checkpoint.c | 2 ++ fs/f2fs/f2fs.h | 4 ++++ fs/f2fs/gc.c | 2 ++ fs/f2fs/super.c | 1 + fs/f2fs/sysfs.c | 17 +++++++++++++++++ 6 files changed, 34 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/te= sting/sysfs-fs-f2fs index ea6474db8a31..c1d2b3fd9c65 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -987,3 +987,11 @@ Contact: "Chao Yu" Description: f2fs can tune priority of thread which has entered into criti= cal region covered by f2fs rwsemphore lock. This sysfs entry can be used to control priority v= alue, the range is [100,139], by default the value is 120. + +What: /sys/fs/f2fs//critical_task_priority +Date: February 2026 +Contact: "Chao Yu" +Description: It can be used to tune priority of f2fs critical task, e.g. f= 2fs_ckpt, f2fs_gc + threads, limitation as below: + - it requires user has CAP_SYS_NICE capability. + - the range is [100, 139], by default the value is 100. diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 4afa5d9a19fc..6dd39b7de11a 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -2158,6 +2158,8 @@ int f2fs_start_ckpt_thread(struct f2fs_sb_info *sbi) } =20 set_task_ioprio(cprc->f2fs_issue_ckpt, cprc->ckpt_thread_ioprio); + set_user_nice(cprc->f2fs_issue_ckpt, + PRIO_TO_NICE(sbi->critical_task_priority)); =20 return 0; } diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index a6e7368fc40a..aa0bca9f851d 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1593,6 +1593,7 @@ enum node_type { #define MAX_LOCK_ELAPSED_TIME 500 =20 #define F2FS_DEFAULT_TASK_PRIORITY (DEFAULT_PRIO) +#define F2FS_CRITICAL_TASK_PRIORITY NICE_TO_PRIO(0) =20 static inline int f2fs_test_bit(unsigned int nr, char *addr); static inline void f2fs_set_bit(unsigned int nr, char *addr); @@ -2010,6 +2011,9 @@ struct f2fs_sb_info { /* adjust priority for task which is in critical region covered by lock */ unsigned int lock_duration_priority; =20 + /* priority for critical task, e.g. f2fs_ckpt, f2fs_gc threads */ + long critical_task_priority; + #ifdef CONFIG_F2FS_FS_COMPRESSION struct kmem_cache *page_array_slab; /* page array entry */ unsigned int page_array_slab_size; /* default page array slab size */ diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 60378614bc54..f46b2673d31f 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -234,6 +234,8 @@ int f2fs_start_gc_thread(struct f2fs_sb_info *sbi) return err; } =20 + set_user_nice(gc_th->f2fs_gc_task, + PRIO_TO_NICE(sbi->critical_task_priority)); return 0; } =20 diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index d5cf7265e5d3..1a755997aff5 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4340,6 +4340,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->max_lock_elapsed_time =3D MAX_LOCK_ELAPSED_TIME; sbi->adjust_lock_priority =3D 0; sbi->lock_duration_priority =3D F2FS_DEFAULT_TASK_PRIORITY; + sbi->critical_task_priority =3D F2FS_CRITICAL_TASK_PRIORITY; =20 sbi->sum_blocksize =3D f2fs_sb_has_packed_ssa(sbi) ? 4096 : sbi->blocksize; diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 3a272e7edf23..5fbfdc96e502 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -969,6 +969,21 @@ static ssize_t __sbi_store(struct f2fs_attr *a, return count; } =20 + if (!strcmp(a->attr.name, "critical_task_priority")) { + if (t < NICE_TO_PRIO(MIN_NICE) || t > NICE_TO_PRIO(MAX_NICE)) + return -EINVAL; + if (!capable(CAP_SYS_NICE)) + return -EPERM; + sbi->critical_task_priority =3D t; + if (sbi->cprc_info.f2fs_issue_ckpt) + set_user_nice(sbi->cprc_info.f2fs_issue_ckpt, + PRIO_TO_NICE(sbi->critical_task_priority)); + if (sbi->gc_thread && sbi->gc_thread->f2fs_gc_task) + set_user_nice(sbi->gc_thread->f2fs_gc_task, + PRIO_TO_NICE(sbi->critical_task_priority)); + return count; + } + __sbi_store_value(a, sbi, ptr + a->offset, t); =20 return count; @@ -1288,6 +1303,7 @@ F2FS_SBI_GENERAL_RW_ATTR(bggc_io_aware); F2FS_SBI_GENERAL_RW_ATTR(max_lock_elapsed_time); F2FS_SBI_GENERAL_RW_ATTR(lock_duration_priority); F2FS_SBI_GENERAL_RW_ATTR(adjust_lock_priority); +F2FS_SBI_GENERAL_RW_ATTR(critical_task_priority); =20 /* STAT_INFO ATTR */ #ifdef CONFIG_F2FS_STAT_FS @@ -1496,6 +1512,7 @@ static struct attribute *f2fs_attrs[] =3D { ATTR_LIST(max_lock_elapsed_time), ATTR_LIST(lock_duration_priority), ATTR_LIST(adjust_lock_priority), + ATTR_LIST(critical_task_priority), NULL, }; ATTRIBUTE_GROUPS(f2fs); --=20 2.40.1