public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block/elevator: reduce the critical section
@ 2020-10-19 16:42 Hui Su
  2020-10-19 16:50 ` Jens Axboe
  2020-10-19 17:23 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Hui Su @ 2020-10-19 16:42 UTC (permalink / raw)
  To: axboe, linux-block, linux-kernel

1.reduce the critical section in elevator_get().
2.reduce the critical section in elevator_get_by_features().
3.remove the found variable.

the elv_list_lock is used to protect the elv_list,
and the operations of elevator_type does not need
to be protected.

Signed-off-by: Hui Su <sh_def@163.com>
---
 block/elevator.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/block/elevator.c b/block/elevator.c
index 293c5c81397a..727902b31954 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -151,11 +151,11 @@ static struct elevator_type *elevator_get(struct request_queue *q,
 		spin_lock(&elv_list_lock);
 		e = elevator_find(name, q->required_elevator_features);
 	}
+	spin_unlock(&elv_list_lock);
 
 	if (e && !try_module_get(e->elevator_owner))
 		e = NULL;
 
-	spin_unlock(&elv_list_lock);
 	return e;
 }
 
@@ -633,23 +633,21 @@ static struct elevator_type *elevator_get_default(struct request_queue *q)
  */
 static struct elevator_type *elevator_get_by_features(struct request_queue *q)
 {
-	struct elevator_type *e, *found = NULL;
+	struct elevator_type *e = NULL;
 
 	spin_lock(&elv_list_lock);
-
 	list_for_each_entry(e, &elv_list, list) {
 		if (elv_support_features(e->elevator_features,
 					 q->required_elevator_features)) {
-			found = e;
 			break;
 		}
 	}
+	spin_unlock(&elv_list_lock);
 
-	if (found && !try_module_get(found->elevator_owner))
-		found = NULL;
+	if (e && !try_module_get(e->elevator_owner))
+		e = NULL;
 
-	spin_unlock(&elv_list_lock);
-	return found;
+	return e;
 }
 
 /*
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-19 17:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-19 16:42 [PATCH] block/elevator: reduce the critical section Hui Su
2020-10-19 16:50 ` Jens Axboe
2020-10-19 17:23 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox