]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
f2fs: fix lock priority inversion issue
authorChao Yu <chao@kernel.org>
Fri, 30 Jan 2026 13:28:08 +0000 (21:28 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sat, 31 Jan 2026 03:24:39 +0000 (03:24 +0000)
commit07de55cbf5762cb4a7e9e0db7aba5c10c8cfe079
tree423f23b83359ddbd7878b660a0735643c8301f11
parentd860974a7e38d35e9e2c4dc8a9f4223b38b6ad99
f2fs: fix lock priority inversion issue

If userspace thread has held f2fs rw semaphore, due to its low priority,
it could be runnable or preempted state for long time, during the time,
it will block high priority thread which is trying to grab the same rw
semaphore, e.g. cp_rwsem, io_rwsem...

To fix such issue, let's detect thread's priority when it tries to grab
f2fs_rwsem lock, if the priority is lower than a priority threshold, let's
uplift the priority before it enters into critical region of lock, and
restore the priority after it leaves from critical region.

Meanwhile, introducing two new sysfs nodes:
- /sys/fs/f2fs/<disk>/adjust_lock_priority, it is used to control whether
the functionality is enable or not.
==========     ==================
Flag_Value     Flag_Description
==========     ==================
0x00000000     Disabled (default)
0x00000001     cp_rwsem
0x00000002     node_change
0x00000004     node_write
0x00000008     gc_lock
0x00000010     cp_global
0x00000020     io_rwsem
==========     ==================
- /sys/fs/f2fs/<disk>/lock_duration_priority, it is used to control
priority threshold.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Documentation/ABI/testing/sysfs-fs-f2fs
fs/f2fs/checkpoint.c
fs/f2fs/f2fs.h
fs/f2fs/super.c
fs/f2fs/sysfs.c