Skip to content

nbd: eliminate queue freeze/unfreeze overhead in connection setup#1004

Open
blktests-ci[bot] wants to merge 5 commits into
linus-master_basefrom
series/1116405=>linus-master
Open

nbd: eliminate queue freeze/unfreeze overhead in connection setup#1004
blktests-ci[bot] wants to merge 5 commits into
linus-master_basefrom
series/1116405=>linus-master

Conversation

@blktests-ci

@blktests-ci blktests-ci Bot commented Jun 25, 2026

Copy link
Copy Markdown

Pull request for series with
subject: nbd: eliminate queue freeze/unfreeze overhead in connection setup
version: 2
url: https://patchwork.kernel.org/project/linux-block/list/?series=1116405

@blktests-ci

blktests-ci Bot commented Jun 25, 2026

Copy link
Copy Markdown
Author

Upstream branch: bade58e
series: https://patchwork.kernel.org/project/linux-block/list/?series=1116405
version: 2

@blktests-ci

blktests-ci Bot commented Jun 26, 2026

Copy link
Copy Markdown
Author

Upstream branch: 4edcdef
series: https://patchwork.kernel.org/project/linux-block/list/?series=1116405
version: 2

@blktests-ci blktests-ci Bot force-pushed the series/1116405=>linus-master branch from ef76791 to d3072b0 Compare June 26, 2026 08:40
@blktests-ci blktests-ci Bot force-pushed the linus-master_base branch from 4cc45a3 to 90ffd56 Compare June 29, 2026 17:14
Long Li and others added 5 commits June 29, 2026 17:45
The second conditional checking nsock->fallback_index validity is the
logical inverse of the first, so drop it and let execution fall through
naturally. Consolidate the two identical dev_err_ratelimited() + return
paths into a single no_fallback label to reduce duplication.

Signed-off-by: Long Li <leo.lilong@huawei.com>
Replace the krealloc-based struct nbd_sock **socks array with struct
xarray socks. Each nbd sock is fully initialized before being stored
into the xarray via xa_store(), ensuring concurrent readers calling
xa_load() never observe a partially initialized socket.

Convert all array index accesses to xa_load() and open-coded for-loops
to xa_for_each().

Signed-off-by: Long Li <leo.lilong@huawei.com>
Now that config->socks uses xarray instead of a plain array, explicit
bounds checking against num_connections is no longer necessary.
xa_load() returns NULL for any out-of-range or missing index, and
xa_for_each() is a no-op on an empty xarray, making these guards
redundant.

Signed-off-by: Long Li <leo.lilong@huawei.com>
The queue freeze was originally needed to prevent concurrent requests
from accessing config->socks while the backing array was being
reallocated. Since config->socks is now an xarray, insertions are
safe under RCU without freezing the queue.

This significantly reduces connection setup time when using a large
number of connections (-C 256):

  before: real 4.510s
  after:  real 0.263s

Signed-off-by: Long Li <leo.lilong@huawei.com>
The preceding patches in this series removed the blk_mq_freeze_queue()
call from nbd_add_socket(), eliminating the freeze/unfreeze overhead
during socket insertion.  However, nbd_start_device() still calls
blk_mq_update_nr_hw_queues() when the hardware queue count differs
from the actual number of connections, which introduce freeze too.

There are two reasons nr_hw_queues may not match num_connections:

1. Reusing an existing nbd device (e.g. one pre-created at module
   load which nr_hw_queues always set as 1) that was originally
   configured with a different connection count.  This case genuinely
   requires blk_mq_update_nr_hw_queues() to adjust the hardware
   queue count.

2. Creating a new nbd device via the netlink connect path
   (nbd_genl_connect), where we know the exact number of connections
   upfront from the NBD_ATTR_SOCKETS attribute.  In this case, there
   is no need to default to nr_hw_queues=1 and then update.

This patch optimizes case 2 by setting nr_hw_queues correctly at
device creation time, so that nbd_start_device() can skip
blk_mq_update_nr_hw_queues() entirely when the count already matches.
Two changes are made:

1. Add a nr_hw_queues parameter to nbd_dev_add() so callers can
   specify the desired queue count instead of the hardcoded 1.

2. Add nbd_genl_count_sockets() to count socket FDs from the netlink
   NBD_ATTR_SOCKETS attribute before the device is created, and pass
   the count as nr_hw_queues when creating a new nbd device via
   netlink.

The ioctl path (NBD_SET_SOCK + NBD_DO_IT) remains fully functional:
pre-created devices with nbds_max>0 default to nr_hw_queues=1, and
nbd_start_device() still calls blk_mq_update_nr_hw_queues() when
needed.

Signed-off-by: Yang Erkun <yangerkun@huawei.com>
@blktests-ci

blktests-ci Bot commented Jun 29, 2026

Copy link
Copy Markdown
Author

Upstream branch: dc59e4f
series: https://patchwork.kernel.org/project/linux-block/list/?series=1116405
version: 2

@blktests-ci blktests-ci Bot force-pushed the series/1116405=>linus-master branch from d3072b0 to ffee8cc Compare June 29, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants