Why this patch improves performance:
Multiple threads will not block on dqio_mutex in dquot_commit().
If thread A is writing dquot and another thread B is waiting for dqio_mutex, other threads can just skip dquot update. Thread B is guaranteed to write the latest data. Once it starts writing, it will clear DQ_MOD_B and new threads entering ldiskfs_mark_dquot_dirty() will have to queue at least one dquot update.
So we are moving from the following worst case (threads ordered by the time they called ldiskfs_mark_dquot_dirty()):
thread 1) executing dquot_commit()
thread 2) waiting in dquot_commit()
...
thread N) waiting in dquot_commit()
to the following case:
thread 1) executing dquot_commit()
thread 2) waiting in dquot_commit()
thread 3) can exit ldiskfs_mark_dquot_dirty() immediately since thread 2 is guaranteed to write the latest data to disk
...
thread N) can exit ldiskfs_mark_dquot_dirty() immediately since thread 2 is guaranteed to write the latest data to disk
Although, in the first case, a subset of thread 2, thread 3, ... thead N may find that DQ_MOD_B is already cleared so they can exit dquot_commit() without updating the disk buffer, each of them will still have to wait for dqio_mutex to do that.
Atomicity concerns:
The updates are guaranteed to be atomic since we always call ldiskfs_mark_dquot_dirty() with a transaction handle. And if multiple threads enter this code at the same time, they share handles to the same transaction by jbd2 design.
Jan Kara mentioned in LKML that this is not the case for dqctl calls which can call ext4_mark_dquot_dirty() without a jbd2 handle, but this case is not relevant for Lustre.
Significant dqio_mutex redesign was planned, so this patch was rejected in LKML, but we can at least slightly improve performance without any kernel fs/quota modification for the older kernels.
"Jian Yu <yujian@whamcloud.com>" uploaded a new patch: https://review.whamcloud.com/c/fs/lustre-release/+/50853
Subject:
LU-12353ldiskfs: add ext4-dquot-commit-speedup patch to more seriesProject: fs/lustre-release
Branch: master
Current Patch Set: 1
Commit: 8843159caf504c8fc22402ad5b06594da378bae7