bdev: reduce critical area in spdk_bdev_open
Since bdev->internal.mutex protects variables in bdev->internal, there's no need to init the fields of spdk_bdev_desc struct and free the struct when claim_module exists within the mutex lock. Reducing critical area could help to reduce lock competition caused by opening bdev concurrently. Change-Id: Ie6b2a63e44a97cfed914fa6d8adef2c5ec3ac300 Signed-off-by: lorneli <lorneli@163.com> Reviewed-on: https://review.gerrithub.io/c/438514 Reviewed-by: wuzhouhui <wuzhouhui@kingsoft.com> Reviewed-by: GangCao <gang.cao@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
0dff1888e2
commit
e3c26a054b
@ -3624,18 +3624,6 @@ spdk_bdev_open(struct spdk_bdev *bdev, bool write, spdk_bdev_remove_cb_t remove_
|
||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV, "Opening descriptor %p for bdev %s on thread %p\n", desc, bdev->name,
|
||||
spdk_get_thread());
|
||||
|
||||
pthread_mutex_lock(&bdev->internal.mutex);
|
||||
|
||||
if (write && bdev->internal.claim_module) {
|
||||
SPDK_ERRLOG("Could not open %s - %s module already claimed it\n",
|
||||
bdev->name, bdev->internal.claim_module->name);
|
||||
free(desc);
|
||||
pthread_mutex_unlock(&bdev->internal.mutex);
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
TAILQ_INSERT_TAIL(&bdev->internal.open_descs, desc, link);
|
||||
|
||||
desc->bdev = bdev;
|
||||
desc->thread = thread;
|
||||
desc->remove_cb = remove_cb;
|
||||
@ -3643,6 +3631,19 @@ spdk_bdev_open(struct spdk_bdev *bdev, bool write, spdk_bdev_remove_cb_t remove_
|
||||
desc->write = write;
|
||||
*_desc = desc;
|
||||
|
||||
pthread_mutex_lock(&bdev->internal.mutex);
|
||||
|
||||
if (write && bdev->internal.claim_module) {
|
||||
SPDK_ERRLOG("Could not open %s - %s module already claimed it\n",
|
||||
bdev->name, bdev->internal.claim_module->name);
|
||||
pthread_mutex_unlock(&bdev->internal.mutex);
|
||||
free(desc);
|
||||
*_desc = NULL;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
TAILQ_INSERT_TAIL(&bdev->internal.open_descs, desc, link);
|
||||
|
||||
pthread_mutex_unlock(&bdev->internal.mutex);
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user