Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3344987pxu; Mon, 19 Oct 2020 09:47:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVeXWlYDwHTV7SCNP5FLzfLVJLhD1cDxhRcW9oB0U4rJXvJugD/nFFVo7KYnLvlqsA3LVA X-Received: by 2002:aa7:c984:: with SMTP id c4mr747172edt.42.1603126052262; Mon, 19 Oct 2020 09:47:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603126052; cv=none; d=google.com; s=arc-20160816; b=fwwhSNZ9SsdrFukIQYGHoQV4oiLSZbLjy17SVDDkyqmVy4AS+INtk+l05Z2vaYjwLV LklA3vpBSVx+6ecyHKm5eVuDB2Enfl1oQpDWzuYrHy2erEVgtSbTP5vXfM00MvenNOEa NjR5mpdR13ahSnxk/5dKa5bPr0IbvbpDSmZR3qYt6qnurthbg6zIx4X292/W4VYRewox HBRcdLlD66fXCXuIKc/5kfm6DA+WiXcv6XggnHhpj3wiHvwtLoDk+c9aerzbMfhJT4aY 2PfRKBHInwghKORY0FZvnVFNbzwzkskIBtm4Jq5vf1bWS6srUEQhPAuuIpTB6SzUeqNw AZuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date:dkim-signature; bh=YC7HomMsF1MVd69eG5Tkh0OhJDK52Iatm/gNKnLN6Hw=; b=X1W32MXwOSR+AEc9lfR7uHgHmEJmFeLjEaM4gpbvSm8niM8babUE+rG3yDaa7+6KRG l8lf/nL4zUADgeWGUBY85dl7YpRgAze5vqpvj/971AnUaYD4z3kYTD6G7HRUXzkFa4DP SUtOMHSbANat+vdHR1tNUsTjDPWI+UKk8HLViu2RN34h1pn9RuvYCbMzLNkYYF3TJ60t AfSxk4CsQaBX3IC4oYQpATMJrxEEHmNXTGFb2F9I2QH6hB2v8LDSzhiHPcweSr1s7So7 amh2eMJkfnrkBIFPJjZENQwV0ye0QulKBSjHxX73Adopg2YTYu67tBMFeDeWPkDZ2BLL 3igg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=ZgCHt8Ot; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b41si107932edf.549.2020.10.19.09.47.09; Mon, 19 Oct 2020 09:47:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=ZgCHt8Ot; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730498AbgJSQnW (ORCPT + 99 others); Mon, 19 Oct 2020 12:43:22 -0400 Received: from m12-11.163.com ([220.181.12.11]:34633 "EHLO m12-11.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729879AbgJSQnW (ORCPT ); Mon, 19 Oct 2020 12:43:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version; bh=YC7Ho mMsF1MVd69eG5Tkh0OhJDK52Iatm/gNKnLN6Hw=; b=ZgCHt8Oth4PwwxBrN3a6W 93pEO49qRBuDZr5JsEBMJhwcxV86eRPOm7Xsy12j4cD5yPblTAIG4Zr+E3xS7I85 e0FgxWw/G5v5K27H/lah7nK0uhGk+JyFe+VqHJmsC2K3uBVQPr74iH7ecXVvSe6F OOSYrzO4ijI4PRpvDHnOzA= Received: from localhost (unknown [101.86.214.18]) by smtp7 (Coremail) with SMTP id C8CowAAX_dkGwo1fOyrtDw--.24180S2; Tue, 20 Oct 2020 00:42:46 +0800 (CST) Date: Tue, 20 Oct 2020 00:42:46 +0800 From: Hui Su To: axboe@kernel.dk, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] block/elevator: reduce the critical section Message-ID: <20201019164246.GA79115@rlk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-CM-TRANSID: C8CowAAX_dkGwo1fOyrtDw--.24180S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7tw4rJFWfJrWfWF1xWry3Jwb_yoW8Wr4kpr sIg3sxKr1kXryxZwsrAa429w1Iq34j9r4jqryrCw10kFnrXw43W3W7Ca17XF4YyayxXFs8 WF1ktFWDAFWUZr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jYksDUUUUU= X-Originating-IP: [101.86.214.18] X-CM-SenderInfo: xvkbvvri6rljoofrz/1tbiIAbCX10TB0yC3wAAsj Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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