nbd: eliminate queue freeze/unfreeze overhead in connection setup#1004
Open
blktests-ci[bot] wants to merge 5 commits into
Open
nbd: eliminate queue freeze/unfreeze overhead in connection setup#1004blktests-ci[bot] wants to merge 5 commits into
blktests-ci[bot] wants to merge 5 commits into
Conversation
Author
|
Upstream branch: bade58e |
7d8604f to
4cc45a3
Compare
Author
|
Upstream branch: 4edcdef |
ef76791 to
d3072b0
Compare
4cc45a3 to
90ffd56
Compare
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>
Author
|
Upstream branch: dc59e4f |
d3072b0 to
ffee8cc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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