Batch enqueue/dequeue for bqueue
authorMatthew Ahrens <mahrens@delphix.com>
Tue, 10 Jan 2023 21:39:22 +0000 (13:39 -0800)
committerGitHub <noreply@github.com>
Tue, 10 Jan 2023 21:39:22 +0000 (13:39 -0800)
commitfc45975ec8685a6c7a14c407a44f336fbbf18e76
tree6d4c32cc5d4e0f985411836f8f3b3521f3ccc9e2
parent0c8fbe5b6adcf8a9bf8445eb2d95a3e24531b8d4
Batch enqueue/dequeue for bqueue

The Blocking Queue (bqueue) code is used by zfs send/receive to send
messages between the various threads.  It uses a shared linked list,
which is locked whenever we enqueue or dequeue.  For workloads which
process many blocks per second, the locking on the shared list can be
quite expensive.

This commit changes the bqueue logic to have 3 linked lists:
1. An enquing list, which is used only by the (single) enquing thread,
   and thus needs no locks.
2. A shared list, with an associated lock.
3. A dequing list, which is used only by the (single) dequing thread,
   and thus needs no locks.

The entire enquing list can be moved to the shared list in constant
time, and the entire shared list can be moved to the dequing list in
constant time.  These operations only happen when the `fill_fraction` is
reached, or on an explicit flush request.  Therefore, the lock only
needs to be acquired infrequently.

The API already allows for dequing to block until an explicit flush, so
callers don't need to be changed.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes #14121
include/sys/bqueue.h
module/zfs/bqueue.c