Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ocfs2: fix DIO failure due to insufficient transaction credits
The code in ocfs2_dio_end_io_write() estimates number of necessary transaction credits using ocfs2_calc_extend_credits(). This however does not take into account that the IO could be arbitrarily large and can contain arbitrary number of extents. Extent tree manipulations do often extend the current transaction but not in all of the cases. For example if we have only single block extents in the tree, ocfs2_mark_extent_written() will end up calling ocfs2_replace_extent_rec() all the time and we will never extend the current transaction and eventually exhaust all the transaction credits if the IO contains many single block extents. Once that happens a WARN_ON(jbd2_handle_buffer_credits(handle) <= 0) is triggered in jbd2_journal_dirty_metadata() and subsequently OCFS2 aborts in response to this error. This was actually triggered by one of our customers on a heavily fragmented OCFS2 filesystem. To fix the issue make sure the transaction always has enough credits for one extent insert before each call of ocfs2_mark_extent_written(). Heming Zhao said: ------ PANIC: "Kernel panic - not syncing: OCFS2: (device dm-1): panic forced after error" PID: xxx TASK: xxxx CPU: 5 COMMAND: "SubmitThread-CA" #0 machine_kexec at ffffffff8c069932 #1 __crash_kexec at ffffffff8c1338fa #2 panic at ffffffff8c1d69b9 ChimeraOS#3 ocfs2_handle_error at ffffffffc0c86c0c [ocfs2] ChimeraOS#4 __ocfs2_abort at ffffffffc0c88387 [ocfs2] ChimeraOS#5 ocfs2_journal_dirty at ffffffffc0c51e98 [ocfs2] ChimeraOS#6 ocfs2_split_extent at ffffffffc0c27ea3 [ocfs2] ChimeraOS#7 ocfs2_change_extent_flag at ffffffffc0c28053 [ocfs2] ChimeraOS#8 ocfs2_mark_extent_written at ffffffffc0c28347 [ocfs2] ChimeraOS#9 ocfs2_dio_end_io_write at ffffffffc0c2bef9 [ocfs2] ChimeraOS#10 ocfs2_dio_end_io at ffffffffc0c2c0f5 [ocfs2] ChimeraOS#11 dio_complete at ffffffff8c2b9fa7 ChimeraOS#12 do_blockdev_direct_IO at ffffffff8c2bc09f ChimeraOS#13 ocfs2_direct_IO at ffffffffc0c2b653 [ocfs2] ChimeraOS#14 generic_file_direct_write at ffffffff8c1dcf14 ChimeraOS#15 __generic_file_write_iter at ffffffff8c1dd07b ChimeraOS#16 ocfs2_file_write_iter at ffffffffc0c49f1f [ocfs2] ChimeraOS#17 aio_write at ffffffff8c2cc72e ChimeraOS#18 kmem_cache_alloc at ffffffff8c248dde ChimeraOS#19 do_io_submit at ffffffff8c2ccada torvalds#20 do_syscall_64 at ffffffff8c004984 torvalds#21 entry_SYSCALL_64_after_hwframe at ffffffff8c8000ba Link: https://lkml.kernel.org/r/20240617095543.6971-1-jack@suse.cz Link: https://lkml.kernel.org/r/20240614145243.8837-1-jack@suse.cz Fixes: c15471f ("ocfs2: fix sparse file & data ordering issue in direct io") Signed-off-by: Jan Kara <jack@suse.cz> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> Reviewed-by: Heming Zhao <heming.zhao@suse.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Gang He <ghe@suse.com> Cc: Jun Piao <piaojun@huawei.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
- Loading branch information