Skip to content

xfs: improve CIL scalability

Dave Chinner linux-xfs 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v8 Latest14 patches 2 repliesIn review
  2. v614 patches 1 replySuperseded
  3. v112 patches 0 repliesSuperseded

Patches in v8 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/14xfs: use the CIL space used counter for emptiness checksfs/xfs/xfs_log_cil.c fs/xfs/xfs_log_priv.h+28 -190 replies
2/14xfs: lift init CIL reservation out of xc_cil_lockfs/xfs/xfs_log_cil.c+14 -160 replies
3/14xfs: rework per-iclog header CIL reservationfs/xfs/xfs_log.c fs/xfs/xfs_log_cil.c fs/xfs/xfs_log_priv.h+59 -250 replies
4/14xfs: introduce per-cpu CIL tracking structurefs/xfs/xfs_log_cil.c fs/xfs/xfs_log_priv.h fs/xfs/xfs_super.c+47 -20 replies
5/14xfs: implement percpu cil space used calculationfs/xfs/xfs_log_cil.c fs/xfs/xfs_log_priv.h+149 -312 replies
6/14xfs: track CIL ticket reservation in percpu structurefs/xfs/xfs_log_cil.c fs/xfs/xfs_log_priv.h+13 -40 replies
7/14xfs: convert CIL busy extents to per-cpufs/xfs/xfs_log_cil.c+20 -60 replies
8/14xfs: Add order IDs to log items in CILfs/xfs/xfs_log_cil.c fs/xfs/xfs_log_priv.h fs/xfs/xfs_trans.h+33 -80 replies
9/14xfs: convert CIL to unordered per cpu listsfs/xfs/xfs_log_cil.c fs/xfs/xfs_log_priv.h+17 -210 replies
10/14xfs: convert log vector chain to use list headsfs/xfs/xfs_log.c fs/xfs/xfs_log.h fs/xfs/xfs_log_cil.c +3 more+43 -350 replies
11/14xfs: move CIL ordering to the logvec chainfs/xfs/xfs_log.h fs/xfs/xfs_log_cil.c+12 -50 replies
12/14xfs: avoid cil push lock if possiblefs/xfs/xfs_log_cil.c+11 -30 replies
13/14xfs: xlog_sync() manually adjusts grant head spacefs/xfs/xfs_log.c fs/xfs/xfs_log_cil.c fs/xfs/xfs_log_priv.h+41 -170 replies
14/14xfs: expanding delayed logging design with background materialDocumentation/filesystems/xfs-delayed-logging-design.rst+322 -390 replies

Reviews trailers per patch

All 14 patches have a Reviewed-by or Acked-by.

PatchDarrick J. Wong
1/14R-b
2/14R-b
3/14R-b
4/14R-b
5/14R-b
6/14R-b
7/14R-b
8/14R-b
9/14R-b
10/14R-b
11/14R-b
12/14R-b
13/14R-b
14/14R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v8 thread

Cover letter [PATCH 00/14 v8] xfs: improve CIL scalability

This series aims to improve the scalability of XFS transaction commits on large CPU count machines. My 32p machine hits contention limits in xlog_cil_commit() at about 700,000 transaction commits a section. It hits this at 16 thread workloads, and 32 thread workloads go no faster and just burn CPU on the CIL spinlocks.

This patchset gets rid of spinlocks and global serialisation points in the xlog_cil_commit() path. It does this by moving to a combination of per-cpu counters, unordered per-cpu lists and post-ordered per-cpu lists.

This results in transaction commit rates exceeding 1.6 million commits/s under unlink certain workloads, and while the log lock contention is largely gone there is still significant lock contention at the VFS at 600,000 transactions/s:

  19.39%  [kernel]  [k] __pv_queued_spin_lock_slowpath
   6.40%  [kernel]  [k] do_raw_spin_lock
   4.07%  [kernel]  [k] __raw_callee_save___pv_queued_spin_unlock
   3.08%  [kernel]  [k] memcpy_erms
   1.93%  [kernel]  [k] xfs_buf_find
   1.69%  [kernel]  [k] xlog_cil_commit
   1.50%  [kernel]  [k] syscall_exit_to_user_mode
   1.18%  [kernel]  [k] memset_erms

- 64.23% 0.22% [kernel] [k] path_openat
- 64.01% path_openat
- 48.69% xfs_vn_create
- 48.60% xfs_generic_create
- 40.96% xfs_create
- 20.39% xfs_dir_ialloc
- 7.05% xfs_setup_inode

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

- 6.87% inode_sb_list_add

- 6.54% _raw_spin_lock
- 6.53% do_raw_spin_lock
6.08% __pv_queued_spin_lock_slowpath
.....
- 11.27% xfs_trans_commit
- 11.23% __xfs_trans_commit
- 10.85% xlog_cil_commit
2.47% memcpy_erms
- 1.77% xfs_buf_item_committing
- 1.70% xfs_buf_item_release
- 0.79% xfs_buf_unlock 0.68% up
0.61% xfs_buf_rele
0.80% xfs_buf_item_format
0.73% xfs_inode_item_format 0.68% xfs_buf_item_size
- 0.55% kmem_alloc_large
- 0.55% kmem_alloc
0.52% __kmalloc
.....
- 7.08% d_instantiate
- 6.66% security_d_instantiate

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

- 6.63% selinux_d_instantiate

- 6.48% inode_doinit_with_dentry
- 6.11% _raw_spin_lock
- 6.09% do_raw_spin_lock
5.60% __pv_queued_spin_lock_slowpath
....
- 1.77% terminate_walk

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

- 1.69% dput

- 1.55% _raw_spin_lock
- do_raw_spin_lock
1.19% __pv_queued_spin_lock_slowpath

But when we extend out to 1.5M commits/s we see that the contention starts to shift to the atomics in the lockless log reservation path:

  14.81%  [kernel]  [k] __pv_queued_spin_lock_slowpath
   7.88%  [kernel]  [k] xlog_grant_add_space
   7.18%  [kernel]  [k] xfs_log_ticket_ungrant
   4.82%  [kernel]  [k] do_raw_spin_lock
   3.58%  [kernel]  [k] xlog_space_left
   3.51%  [kernel]  [k] xlog_cil_commit

There's still substantial spin lock contention occurring at the VFS, too, but it's indicating that multiple atomic variable updates per transaction reservation/commit pair is starting to reach scalability limits here.

This is largely a re-implementation of a past RFC patchsets. While that were good enough proof of concept to perf test, they did not preserve transaction order correctly and failed shutdown tests all the time. The changes to the CIL accounting and behaviour, combined with the structural changes to xlog_write() in prior patchsets make the per-cpu restructuring possible and sane.

Instead of trying to account for continuation log opheaders on a "growth" basis, we pre-calculate how many iclogs we'll need to write out a maximally sized CIL checkpoint and just reserve that space one per commit until the CIL has a full reservation. If we ever run a commit when we are already at the hard limit (because post-throttling) we simply take an extra reservation from each commit that is run when over the limit. Hence we don't need to do space usage math in the fast path and so never need to sum the per-cpu counters in this path.

Similarly, per-cpu lists have the problem of ordering - we can't remove an item from a per-cpu list if we want to move it forward in the CIL. We solve this problem by using an atomic counter to give every commit a sequence number that is copied into the log items in that transaction. Hence relogging items just overwrites the sequence number in the log item, and does not move it in the per-cpu lists. Once we reaggregate the per-cpu lists back into a single list in the CIL push work, we can run it through list-sort() and reorder it back into a globally ordered list. This costs a bit of CPU time, but now that the CIL can run multiple works and pipelines properly, this is not a limiting factor for performance. It does increase fsync latency when the CIL is full, but workloads issuing large numbers of fsync()s or sync transactions end up with very small CILs and so the latency impact or sorting is not measurable for such workloads.

git://git.kernel.org/pub/scm/linux/kernel/git/dgc/linux-xfs.git xfs-cil-scale-3

Version 8:
- rebase on 5.19-rc2

Version 7:
- not published.
- fixed per-emption bug when sampling first CIL context reservation after clearing XLOG_CIL_EMPTY. Pre-emption between clearing and sampling could result in other racing updates modifying t_unit_res and so the ctx_res could be larger than the reservations of the transaction being committed leading to transaction overrun and shutdown.
- fixed a percpu used space accounting bug where folding used the hard limit instead of the soft limit for the per-cpu proportion of the space used. This could lead to context ticket overruns.
- fixed hard limit overrun detection for extra reservations to check the push waitqueue to capture cases where log space is freed by a transaction commit. This could lead to context ticket overruns.

Version 6:
- https://lore.kernel.org/linux-xfs/[email protected]/
- split out from aggregated patchset
- rebase on linux-xfs/for-next + dgc/xlog-write-rework

Version 5:
- https://lore.kernel.org/linux-xfs/[email protected]/