]> git.hungrycats.org Git - linux/commit
btrfs: fix a livelock in wait_for_commit() on PREEMPT_RT
authorDaniel Vacek <neelx@suse.com>
Fri, 30 Oct 2026 14:28:03 +0000 (15:28 +0100)
committerDaniel Vacek <neelx@suse.com>
Sat, 31 Oct 2026 08:07:09 +0000 (09:07 +0100)
commit07d844bbfb87d9052c73a43134542afbaf98664d
tree53655ef7bc174ec76a50ddc3fe46818aa055c725
parent0a647b9c3426d5429e445493d6fe5f5a7b624a25
btrfs: fix a livelock in wait_for_commit() on PREEMPT_RT

Peter reported [1] that running multiple RR tasks doing sync()
on fully preemptible kernel may starve other/normal sync() tasks
due to fs_info::trans_lock turned into rt_mutex.

This is caused by RR tasks contending over the mutex with priority over
other tasks, which in turn lack progress and they are no longer able to
remove TRANS_STATE_COMPLETED transactions from the fs_info::trans_list.

The offenders start looping in wait_for_commit() expecting the completed
transactions to get off the trans_list but since they're bouncing the
trans_lock the tasks with other/normal priority which are about to delist
such transactions never get a chance to do so due to lower priority.

A simple reproducer can be found in the mentioned email thread [1].

The situation can be resolved by boosting the priority of the starved
tasks or dropping priority of the offenders. Thought this fix prevents
the situation from happening in the first place. We simply delist the
transactions before changing them to completed state. That breaks the
loop condition.

[1] https://lore.kernel.org/linux-btrfs/SJ0PR17MB4288C46458DCE2C015839D0FBB9E2@SJ0PR17MB4288.namprd17.prod.outlook.com/

Reported-by: Naulls, Peter <PeterNaulls@eaton.com>
Fixes: 5fd76bf31ccfe ("btrfs: fix relocation crash due to premature return from btrfs_commit_transaction()")
CC: stable@vger.kernel.org # 5.15+
Tested-by: Naulls, Peter <PeterNaulls@eaton.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Daniel Vacek <neelx@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/transaction.c