From nobody Mon Oct 6 03:16:33 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85DC6293B42; Fri, 25 Jul 2025 07:12:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753427546; cv=none; b=neuVkJT0jfQkcxT1EM18rCzFatVgSj1DTEVv5u6rtGC6/HgsOXodQXNJoqvPo80Dv5QaXPohhnzqplhi0D3Ej7ooVZ82MXGFR+RlNPsvgRqCFM/PVYMKvsR+XqACcc77iK0mhCqEvqVXFZKk6WgSlCHwuVGMBtd6dQdZwG8xdX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753427546; c=relaxed/simple; bh=xM2fy3uV59FY935HHY8dOHWnpWoGdJCUddc/ecWB0FE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A1Fw9Vv7UKBNp9kEw9I8idsnYtjG+D33GbQvJ1HSZn1IRG6UzQW5JfPZEcGhxMHo/qw/dOiGdsoW48sMz5t9OYxQiV7q5yQ4VUcyYDSnDvfieLImkgO91OoKk9njcaxRKZdoK11EH9DATkDSEDbOA8u8G4jZYc/UHNw7wRxjSGw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4bpJwR5HwBzYQvBQ; Fri, 25 Jul 2025 15:12:23 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 6DAD61A1043; Fri, 25 Jul 2025 15:12:22 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgB3QBFRLoNonnivBQ--.56345S5; Fri, 25 Jul 2025 15:12:22 +0800 (CST) From: Yu Kuai To: jack@suse.cz, dlemoal@kernel.org, axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com, johnny.chenyi@huawei.com Subject: [PATCH 1/3] blk-ioc: add a new helper ioc_lookup_icq_rcu() Date: Fri, 25 Jul 2025 15:05:45 +0800 Message-Id: <20250725070547.3953398-2-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250725070547.3953398-1-yukuai1@huaweicloud.com> References: <20250725070547.3953398-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgB3QBFRLoNonnivBQ--.56345S5 X-Coremail-Antispam: 1UD129KBjvJXoW7Aw13Xr47Xw4fKFWxGFWrGrg_yoW8uw15pF WagFs0yr1jgr4xCrn3J3ZrZryfWay8ursrXa9avw4Ykr92krnavF10yryjqr1S9rs7JFs5 Xr17tw4UCry09rJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUm014x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWU JVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67 kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY 6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVj vjDU0xZFpf9x0JUqkskUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ Content-Type: text/plain; charset="utf-8" From: Yu Kuai ioc_lookup_icq() is used by bfq to lookup bfqq from IO path, the helper have to be protected by queue_lock, which is too heavy. Hence add a new helper that is lookless, this is safe because both request_queue and ioc can be pinged by IO that is still issuing. Signed-off-by: Yu Kuai --- block/blk-ioc.c | 34 ++++++++++++++++++++++++++++++++++ block/blk.h | 1 + 2 files changed, 35 insertions(+) diff --git a/block/blk-ioc.c b/block/blk-ioc.c index ce82770c72ab..4945b48dfdb6 100644 --- a/block/blk-ioc.c +++ b/block/blk-ioc.c @@ -343,6 +343,40 @@ struct io_cq *ioc_lookup_icq(struct request_queue *q) } EXPORT_SYMBOL(ioc_lookup_icq); =20 +/** + * ioc_lookup_icq_rcu - lookup io_cq from ioc in io path + * @q: the associated request_queue + * + * Look up io_cq associated with @ioc - @q pair from @ioc. Must be called = from + * io issue path, either return NULL if current issue io to @q for the fir= st + * time, or return a valid icq. + */ +struct io_cq *ioc_lookup_icq_rcu(struct request_queue *q) +{ + struct io_context *ioc =3D current->io_context; + struct io_cq *icq; + + WARN_ON_ONCE(percpu_ref_is_zero(&q->q_usage_counter)); + + if (!ioc) + return NULL; + + icq =3D rcu_dereference(ioc->icq_hint); + if (icq && icq->q =3D=3D q) + return icq; + + icq =3D radix_tree_lookup(&ioc->icq_tree, q->id); + if (!icq) + return NULL; + + if (WARN_ON_ONCE(icq->q !=3D q)) + return NULL; + + rcu_assign_pointer(ioc->icq_hint, icq); + return icq; +} +EXPORT_SYMBOL(ioc_lookup_icq_rcu); + /** * ioc_create_icq - create and link io_cq * @q: request_queue of interest diff --git a/block/blk.h b/block/blk.h index 468aa83c5a22..ef31b3ec1c69 100644 --- a/block/blk.h +++ b/block/blk.h @@ -461,6 +461,7 @@ static inline void req_set_nomerge(struct request_queue= *q, struct request *req) */ struct io_cq *ioc_find_get_icq(struct request_queue *q); struct io_cq *ioc_lookup_icq(struct request_queue *q); +struct io_cq *ioc_lookup_icq_rcu(struct request_queue *q); #ifdef CONFIG_BLK_ICQ void ioc_clear_queue(struct request_queue *q); #else --=20 2.39.2 From nobody Mon Oct 6 03:16:33 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E2C4293B5C; Fri, 25 Jul 2025 07:12:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753427547; cv=none; b=M9iHSkMZMAr55Q90Fgb0j0Up4FfBCxVe0HBAkeOZVuwRk5r+h/1RvV2sSlJL+hFFAZSAEaKa2NdLRjNO6aFw559mh7TyztpMIru5GHVfVfYbcrXImtM5FCFTtQGaIllGKEVhgcS2X87UZW6uoCt56v/ynYiL3LvhaHyInxxqQeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753427547; c=relaxed/simple; bh=bEDstxq6BkdpzQQ3dDSbj2qY8nAOSf0Fe4DnLSore8Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jrwgO9wzomiQPpHs5V32Ym6oEZhmvR3b8cxj8+P881DJTu1HupTpkvY3gjxmmwzhdN69TB4ie8lMY3l5hqd7YvLr+AW0tUkoFqebimVvT4uTQJ2kbYCZyxgWWibs0aXw8k2VfidRyDshDVfC2am3g4zsS6w4P90g20KJB5l71L8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4bpJwS0gp7zKHMc8; Fri, 25 Jul 2025 15:12:24 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id D452C1A0DDC; Fri, 25 Jul 2025 15:12:22 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgB3QBFRLoNonnivBQ--.56345S6; Fri, 25 Jul 2025 15:12:22 +0800 (CST) From: Yu Kuai To: jack@suse.cz, dlemoal@kernel.org, axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com, johnny.chenyi@huawei.com Subject: [PATCH 2/3] block, bfq: convert to use ioc_lookup_icq_rcu() Date: Fri, 25 Jul 2025 15:05:46 +0800 Message-Id: <20250725070547.3953398-3-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250725070547.3953398-1-yukuai1@huaweicloud.com> References: <20250725070547.3953398-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgB3QBFRLoNonnivBQ--.56345S6 X-Coremail-Antispam: 1UD129KBjvJXoW7Aw17XFyktF1UKry3trWUJwb_yoW8WFy5pF sIganIyr10gr1fur1jy3WDtFn3uan3WrW7KanIqw4FyryIyrnIq3Wjya4SvFySvrWxArsF vF1UK3ykAr4UJ3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUm014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWU JVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67 kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY 6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVj vjDU0xZFpf9x0JUczV8UUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ Content-Type: text/plain; charset="utf-8" From: Yu Kuai ioc_lookup_icq() are all called from IO issue path with queue_lock held, convert to use ioc_lookup_icq_rcu() to get rid of the disk level spin lock. Signed-off-by: Yu Kuai --- block/bfq-iosched.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 0cb1e9873aab..b3b9dbbc16d2 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -454,17 +454,13 @@ static struct bfq_io_cq *icq_to_bic(struct io_cq *icq) */ static struct bfq_io_cq *bfq_bic_lookup(struct request_queue *q) { - struct bfq_io_cq *icq; - unsigned long flags; - - if (!current->io_context) - return NULL; + struct io_cq *icq; =20 - spin_lock_irqsave(&q->queue_lock, flags); - icq =3D icq_to_bic(ioc_lookup_icq(q)); - spin_unlock_irqrestore(&q->queue_lock, flags); + rcu_read_lock(); + icq =3D ioc_lookup_icq_rcu(q); + rcu_read_unlock(); =20 - return icq; + return icq_to_bic(icq); } =20 /* @@ -2457,15 +2453,8 @@ static bool bfq_bio_merge(struct request_queue *q, s= truct bio *bio, unsigned int nr_segs) { struct bfq_data *bfqd =3D q->elevator->elevator_data; - struct request *free =3D NULL; - /* - * bfq_bic_lookup grabs the queue_lock: invoke it now and - * store its return value for later use, to avoid nesting - * queue_lock inside the bfqd->lock. We assume that the bic - * returned by bfq_bic_lookup does not go away before - * bfqd->lock is taken. - */ struct bfq_io_cq *bic =3D bfq_bic_lookup(q); + struct request *free =3D NULL; bool ret; =20 spin_lock_irq(&bfqd->lock); --=20 2.39.2 From nobody Mon Oct 6 03:16:33 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22138291C36; Fri, 25 Jul 2025 07:12:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753427547; cv=none; b=h8fKty51fXPAt+JkgwT+FC4uUM4ialXxvRPicgW/3/N6hCNX/K6ufY3s4LkTQAZn5njSyN6gb586xx1LtGAkOrp7+N+DI8wJew22X3o+4KGZd6tw2SDZF6/c9fEkULhAI3HhMfflrWwiAXQkdAe65egAjq/UwHTVE553L2FCA30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753427547; c=relaxed/simple; bh=4m21/tOaaQuK9P5OB3BkYbzOAtN//6qSdsCq/Pg9FOs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kPTrLYOQgbD/SRlaPj9HLyH3S27GdqgytmsAQuwoW/BI6wzvgGGHR5YvssxTG3ouSxgjZEwdLUtMZm9Apn66oXawotZkJM++3V2fUfH51ZAKnXSNYxMIaOKmJFBUc0hqNh1ad2ZNZxsurBaR1tYNCcPrCchkO1/BEwc4PXuac3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4bpJwS4zNNzYQvBW; Fri, 25 Jul 2025 15:12:24 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 63E8A1A0DEA; Fri, 25 Jul 2025 15:12:23 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgB3QBFRLoNonnivBQ--.56345S7; Fri, 25 Jul 2025 15:12:23 +0800 (CST) From: Yu Kuai To: jack@suse.cz, dlemoal@kernel.org, axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com, johnny.chenyi@huawei.com Subject: [PATCH 3/3] blk-ioc: convert to use ioc_lookup_icq_rcu() Date: Fri, 25 Jul 2025 15:05:47 +0800 Message-Id: <20250725070547.3953398-4-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250725070547.3953398-1-yukuai1@huaweicloud.com> References: <20250725070547.3953398-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgB3QBFRLoNonnivBQ--.56345S7 X-Coremail-Antispam: 1UD129KBjvJXoWxGF1DAFy5CF1ktr1fCr4rZrb_yoW5Cw45pF WagFsIyrW0gr47urykJ3ZrZrn3W3WUCr47tan3tw4Fkr92krnavF10yryIqFyS9rW8AFs0 qr18KrWDAr18uaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUm014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWU JVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67 kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY 6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVj vjDU0xZFpf9x0JUHWlkUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ Content-Type: text/plain; charset="utf-8" From: Yu Kuai Now ioc_lookup_icq() is only called from bfq_prepare_request() from IO issue path, if it's the first time current issue IO to the disk, 'queue_lock' will be held to creat new icq, otherwise it's safe to use the new helper. Noted if multiple task share one ioc, and ioc_create_icq() raced, queue_lock is used to serialize them and only the first one can succeed inserting icq to ioc. Also remove ioc_lookup_icq() that is not used now. Signed-off-by: Yu Kuai --- block/blk-ioc.c | 44 ++++---------------------------------------- block/blk.h | 1 - 2 files changed, 4 insertions(+), 41 deletions(-) diff --git a/block/blk-ioc.c b/block/blk-ioc.c index 4945b48dfdb6..27dd65957853 100644 --- a/block/blk-ioc.c +++ b/block/blk-ioc.c @@ -307,42 +307,6 @@ int __copy_io(unsigned long clone_flags, struct task_s= truct *tsk) } =20 #ifdef CONFIG_BLK_ICQ -/** - * ioc_lookup_icq - lookup io_cq from ioc - * @q: the associated request_queue - * - * Look up io_cq associated with @ioc - @q pair from @ioc. Must be called - * with @q->queue_lock held. - */ -struct io_cq *ioc_lookup_icq(struct request_queue *q) -{ - struct io_context *ioc =3D current->io_context; - struct io_cq *icq; - - lockdep_assert_held(&q->queue_lock); - - /* - * icq's are indexed from @ioc using radix tree and hint pointer, - * both of which are protected with RCU. All removals are done - * holding both q and ioc locks, and we're holding q lock - if we - * find a icq which points to us, it's guaranteed to be valid. - */ - rcu_read_lock(); - icq =3D rcu_dereference(ioc->icq_hint); - if (icq && icq->q =3D=3D q) - goto out; - - icq =3D radix_tree_lookup(&ioc->icq_tree, q->id); - if (icq && icq->q =3D=3D q) - rcu_assign_pointer(ioc->icq_hint, icq); /* allowed to race */ - else - icq =3D NULL; -out: - rcu_read_unlock(); - return icq; -} -EXPORT_SYMBOL(ioc_lookup_icq); - /** * ioc_lookup_icq_rcu - lookup io_cq from ioc in io path * @q: the associated request_queue @@ -420,7 +384,7 @@ static struct io_cq *ioc_create_icq(struct request_queu= e *q) et->ops.init_icq(icq); } else { kmem_cache_free(et->icq_cache, icq); - icq =3D ioc_lookup_icq(q); + icq =3D ioc_lookup_icq_rcu(q); if (!icq) printk(KERN_ERR "cfq: icq link failed!\n"); } @@ -454,9 +418,9 @@ struct io_cq *ioc_find_get_icq(struct request_queue *q) } else { get_io_context(ioc); =20 - spin_lock_irq(&q->queue_lock); - icq =3D ioc_lookup_icq(q); - spin_unlock_irq(&q->queue_lock); + rcu_read_lock(); + icq =3D ioc_lookup_icq_rcu(q); + rcu_read_unlock(); } =20 if (!icq) { diff --git a/block/blk.h b/block/blk.h index ef31b3ec1c69..3c078e517d59 100644 --- a/block/blk.h +++ b/block/blk.h @@ -460,7 +460,6 @@ static inline void req_set_nomerge(struct request_queue= *q, struct request *req) * Internal io_context interface */ struct io_cq *ioc_find_get_icq(struct request_queue *q); -struct io_cq *ioc_lookup_icq(struct request_queue *q); struct io_cq *ioc_lookup_icq_rcu(struct request_queue *q); #ifdef CONFIG_BLK_ICQ void ioc_clear_queue(struct request_queue *q); --=20 2.39.2