Commit 0bf77e9d authored by Ming Lin's avatar Ming Lin Committed by Jens Axboe

nvme: switch to RCU freeing the namespace

Switch to RCU freeing the namespace structure so that
nvme_start_queues, nvme_stop_queues and nvme_kill_queues would
be able to get away with only a RCU read side critical section.
Suggested-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarMing Lin <ming.l@ssi.samsung.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarKeith Busch <keith.busch@intel.com>
Reviewed-by: default avatarSagi Grimerg <sagi@grimberg.me>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent a5b714ad
...@@ -1429,7 +1429,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) ...@@ -1429,7 +1429,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
if (nvme_revalidate_disk(ns->disk)) if (nvme_revalidate_disk(ns->disk))
goto out_free_disk; goto out_free_disk;
list_add_tail(&ns->list, &ctrl->namespaces); list_add_tail_rcu(&ns->list, &ctrl->namespaces);
kref_get(&ctrl->kref); kref_get(&ctrl->kref);
if (ns->type == NVME_NS_LIGHTNVM) if (ns->type == NVME_NS_LIGHTNVM)
return; return;
...@@ -1467,6 +1467,7 @@ static void nvme_ns_remove(struct nvme_ns *ns) ...@@ -1467,6 +1467,7 @@ static void nvme_ns_remove(struct nvme_ns *ns)
mutex_lock(&ns->ctrl->namespaces_mutex); mutex_lock(&ns->ctrl->namespaces_mutex);
list_del_init(&ns->list); list_del_init(&ns->list);
mutex_unlock(&ns->ctrl->namespaces_mutex); mutex_unlock(&ns->ctrl->namespaces_mutex);
synchronize_rcu();
nvme_put_ns(ns); nvme_put_ns(ns);
} }
...@@ -1751,8 +1752,8 @@ void nvme_kill_queues(struct nvme_ctrl *ctrl) ...@@ -1751,8 +1752,8 @@ void nvme_kill_queues(struct nvme_ctrl *ctrl)
{ {
struct nvme_ns *ns; struct nvme_ns *ns;
mutex_lock(&ctrl->namespaces_mutex); rcu_read_lock();
list_for_each_entry(ns, &ctrl->namespaces, list) { list_for_each_entry_rcu(ns, &ctrl->namespaces, list) {
if (!kref_get_unless_zero(&ns->kref)) if (!kref_get_unless_zero(&ns->kref))
continue; continue;
...@@ -1769,7 +1770,7 @@ void nvme_kill_queues(struct nvme_ctrl *ctrl) ...@@ -1769,7 +1770,7 @@ void nvme_kill_queues(struct nvme_ctrl *ctrl)
nvme_put_ns(ns); nvme_put_ns(ns);
} }
mutex_unlock(&ctrl->namespaces_mutex); rcu_read_unlock();
} }
EXPORT_SYMBOL_GPL(nvme_kill_queues); EXPORT_SYMBOL_GPL(nvme_kill_queues);
...@@ -1777,8 +1778,8 @@ void nvme_stop_queues(struct nvme_ctrl *ctrl) ...@@ -1777,8 +1778,8 @@ void nvme_stop_queues(struct nvme_ctrl *ctrl)
{ {
struct nvme_ns *ns; struct nvme_ns *ns;
mutex_lock(&ctrl->namespaces_mutex); rcu_read_lock();
list_for_each_entry(ns, &ctrl->namespaces, list) { list_for_each_entry_rcu(ns, &ctrl->namespaces, list) {
spin_lock_irq(ns->queue->queue_lock); spin_lock_irq(ns->queue->queue_lock);
queue_flag_set(QUEUE_FLAG_STOPPED, ns->queue); queue_flag_set(QUEUE_FLAG_STOPPED, ns->queue);
spin_unlock_irq(ns->queue->queue_lock); spin_unlock_irq(ns->queue->queue_lock);
...@@ -1786,7 +1787,7 @@ void nvme_stop_queues(struct nvme_ctrl *ctrl) ...@@ -1786,7 +1787,7 @@ void nvme_stop_queues(struct nvme_ctrl *ctrl)
blk_mq_cancel_requeue_work(ns->queue); blk_mq_cancel_requeue_work(ns->queue);
blk_mq_stop_hw_queues(ns->queue); blk_mq_stop_hw_queues(ns->queue);
} }
mutex_unlock(&ctrl->namespaces_mutex); rcu_read_unlock();
} }
EXPORT_SYMBOL_GPL(nvme_stop_queues); EXPORT_SYMBOL_GPL(nvme_stop_queues);
...@@ -1794,13 +1795,13 @@ void nvme_start_queues(struct nvme_ctrl *ctrl) ...@@ -1794,13 +1795,13 @@ void nvme_start_queues(struct nvme_ctrl *ctrl)
{ {
struct nvme_ns *ns; struct nvme_ns *ns;
mutex_lock(&ctrl->namespaces_mutex); rcu_read_lock();
list_for_each_entry(ns, &ctrl->namespaces, list) { list_for_each_entry_rcu(ns, &ctrl->namespaces, list) {
queue_flag_clear_unlocked(QUEUE_FLAG_STOPPED, ns->queue); queue_flag_clear_unlocked(QUEUE_FLAG_STOPPED, ns->queue);
blk_mq_start_stopped_hw_queues(ns->queue, true); blk_mq_start_stopped_hw_queues(ns->queue, true);
blk_mq_kick_requeue_list(ns->queue); blk_mq_kick_requeue_list(ns->queue);
} }
mutex_unlock(&ctrl->namespaces_mutex); rcu_read_unlock();
} }
EXPORT_SYMBOL_GPL(nvme_start_queues); EXPORT_SYMBOL_GPL(nvme_start_queues);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment