From patchwork Tue Mar 16 03:15:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 12141151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 975FCC4332D for ; Tue, 16 Mar 2021 03:18:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7579C65099 for ; Tue, 16 Mar 2021 03:18:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229901AbhCPDRx (ORCPT ); Mon, 15 Mar 2021 23:17:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49958 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231309AbhCPDRb (ORCPT ); Mon, 15 Mar 2021 23:17:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615864650; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/RJohKht9zxsacAuN+lwrqQhpotTsKSMza5HyLGE6fs=; b=ayA2u+x/UG1JrKStkldUCIl0FbReVuNGzSyidOoHnBnqw3JnLnE8SM4J8pp5sEULSPvD2g BPC1eLwRIGUZ2x/VIBfmX9xm7/4/pjKV8wmE0ZJqS4mdJH4snW/3EkFXKJpbYWuUCcEkUy qeiaxTR+wdD2rleGaRu525xs+csOQpQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-491-PHKCVHeiOLmjbiIqp8KsLA-1; Mon, 15 Mar 2021 23:17:26 -0400 X-MC-Unique: PHKCVHeiOLmjbiIqp8KsLA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EFDB2107ACCD; Tue, 16 Mar 2021 03:17:24 +0000 (UTC) Received: from localhost (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26B7360C0F; Tue, 16 Mar 2021 03:17:12 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Jeffle Xu , Mike Snitzer , dm-devel@redhat.com, Ming Lei Subject: [RFC PATCH 01/11] block: add helper of blk_queue_poll Date: Tue, 16 Mar 2021 11:15:13 +0800 Message-Id: <20210316031523.864506-2-ming.lei@redhat.com> In-Reply-To: <20210316031523.864506-1-ming.lei@redhat.com> References: <20210316031523.864506-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org There has been 3 users, and will be more, so add one such helper. Signed-off-by: Ming Lei Reviewed-by: Chaitanya Kulkarni --- block/blk-core.c | 2 +- block/blk-mq.c | 3 +-- drivers/nvme/host/core.c | 2 +- include/linux/blkdev.h | 1 + 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index fc60ff208497..a31371d55b9d 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -836,7 +836,7 @@ static noinline_for_stack bool submit_bio_checks(struct bio *bio) } } - if (!test_bit(QUEUE_FLAG_POLL, &q->queue_flags)) + if (!blk_queue_poll(q)) bio->bi_opf &= ~REQ_HIPRI; switch (bio_op(bio)) { diff --git a/block/blk-mq.c b/block/blk-mq.c index d4d7c1caa439..63c81df3b8b5 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3869,8 +3869,7 @@ int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin) struct blk_mq_hw_ctx *hctx; long state; - if (!blk_qc_t_valid(cookie) || - !test_bit(QUEUE_FLAG_POLL, &q->queue_flags)) + if (!blk_qc_t_valid(cookie) || !blk_queue_poll(q)) return 0; if (current->plug) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index e68a8c4ac5a6..bb7da34dd967 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -955,7 +955,7 @@ static void nvme_execute_rq_polled(struct request_queue *q, { DECLARE_COMPLETION_ONSTACK(wait); - WARN_ON_ONCE(!test_bit(QUEUE_FLAG_POLL, &q->queue_flags)); + WARN_ON_ONCE(!blk_queue_poll(q)); rq->cmd_flags |= REQ_HIPRI; rq->end_io_data = &wait; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index bc6bc8383b43..89a01850cf12 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -665,6 +665,7 @@ bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q); #define blk_queue_fua(q) test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags) #define blk_queue_registered(q) test_bit(QUEUE_FLAG_REGISTERED, &(q)->queue_flags) #define blk_queue_nowait(q) test_bit(QUEUE_FLAG_NOWAIT, &(q)->queue_flags) +#define blk_queue_poll(q) test_bit(QUEUE_FLAG_POLL, &(q)->queue_flags) extern void blk_set_pm_only(struct request_queue *q); extern void blk_clear_pm_only(struct request_queue *q); From patchwork Tue Mar 16 03:15:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 12141149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 852A3C433E0 for ; Tue, 16 Mar 2021 03:18:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 501F565090 for ; Tue, 16 Mar 2021 03:18:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230394AbhCPDRy (ORCPT ); Mon, 15 Mar 2021 23:17:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26511 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233061AbhCPDRk (ORCPT ); Mon, 15 Mar 2021 23:17:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615864660; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rVViYM6RdcSRq6ph00xTm+3/tk+wViBgPjyHPeg8h0o=; b=RFIRMm9mYoTWYnXvZAJlzgHZK+xXDFUx64CaHrcsnHTxfUkBdB2S4hbg4j0COu0jKiH2A+ Tbp/5PboLGrHJbzroJHiSnMo9xWtm9HEvJyRdo+cIjxAzgBulru1QAcnSBU7AfE5sKW6YG YfELJVFWO8Sp/MIru1hx9FGfM1teIiw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-115-p0ousvEjPGGJUTyVpz_IAQ-1; Mon, 15 Mar 2021 23:17:38 -0400 X-MC-Unique: p0ousvEjPGGJUTyVpz_IAQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0324E107ACCA; Tue, 16 Mar 2021 03:17:37 +0000 (UTC) Received: from localhost (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30776614FB; Tue, 16 Mar 2021 03:17:26 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Jeffle Xu , Mike Snitzer , dm-devel@redhat.com, Ming Lei Subject: [RFC PATCH 02/11] block: add one helper to free io_context Date: Tue, 16 Mar 2021 11:15:14 +0800 Message-Id: <20210316031523.864506-3-ming.lei@redhat.com> In-Reply-To: <20210316031523.864506-1-ming.lei@redhat.com> References: <20210316031523.864506-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Prepare for putting bio poll queue into io_context, so add one helper for free io_context. Signed-off-by: Ming Lei --- block/blk-ioc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/block/blk-ioc.c b/block/blk-ioc.c index 57299f860d41..b0cde18c4b8c 100644 --- a/block/blk-ioc.c +++ b/block/blk-ioc.c @@ -17,6 +17,11 @@ */ static struct kmem_cache *iocontext_cachep; +static inline void free_io_context(struct io_context *ioc) +{ + kmem_cache_free(iocontext_cachep, ioc); +} + /** * get_io_context - increment reference count to io_context * @ioc: io_context to get @@ -129,7 +134,7 @@ static void ioc_release_fn(struct work_struct *work) spin_unlock_irq(&ioc->lock); - kmem_cache_free(iocontext_cachep, ioc); + free_io_context(ioc); } /** @@ -164,7 +169,7 @@ void put_io_context(struct io_context *ioc) } if (free_ioc) - kmem_cache_free(iocontext_cachep, ioc); + free_io_context(ioc); } /** @@ -278,7 +283,7 @@ int create_task_io_context(struct task_struct *task, gfp_t gfp_flags, int node) (task == current || !(task->flags & PF_EXITING))) task->io_context = ioc; else - kmem_cache_free(iocontext_cachep, ioc); + free_io_context(ioc); ret = task->io_context ? 0 : -EBUSY; From patchwork Tue Mar 16 03:15:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 12141153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7401C433DB for ; Tue, 16 Mar 2021 03:19:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B287864F07 for ; Tue, 16 Mar 2021 03:19:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233330AbhCPDSZ (ORCPT ); Mon, 15 Mar 2021 23:18:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49329 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233613AbhCPDSB (ORCPT ); Mon, 15 Mar 2021 23:18:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615864680; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hiQvZh7foPjrFz+jjL1c3fsVbvj1Kh2WiEPhGKCssXE=; b=cqsM0Hsn2y5g28l87SOgwy3StuvaU8h8BRUcwSJlME/qk4z3Wi0TGma97524Hiz5h8pCUg B3DSy0CqQLUJ5HXbecspSsmHmEdBPH+agg6SGb7zYw2O23jb/6WfzqEclKfjmj9H7cZ6mQ TvUxwWwN6fqmVQ8NAPZ4d4LOQ7sFl6Y= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-KfXlP2LPNwCQ6xbXJaS3TQ-1; Mon, 15 Mar 2021 23:17:57 -0400 X-MC-Unique: KfXlP2LPNwCQ6xbXJaS3TQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3F5DC107ACCA; Tue, 16 Mar 2021 03:17:56 +0000 (UTC) Received: from localhost (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F21760C0F; Tue, 16 Mar 2021 03:17:44 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Jeffle Xu , Mike Snitzer , dm-devel@redhat.com, Ming Lei Subject: [RFC PATCH 03/11] block: add helper of blk_create_io_context Date: Tue, 16 Mar 2021 11:15:15 +0800 Message-Id: <20210316031523.864506-4-ming.lei@redhat.com> In-Reply-To: <20210316031523.864506-1-ming.lei@redhat.com> References: <20210316031523.864506-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add one helper for creating io context and prepare for supporting efficient bio based io poll. Meantime move the code of creating io_context before checking bio's REQ_HIPRI flag because the following patch may change to clear REQ_HIPRI if io_context can't be created. Signed-off-by: Ming Lei --- block/blk-core.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index a31371d55b9d..d58f8a0c80de 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -792,6 +792,18 @@ static inline blk_status_t blk_check_zone_append(struct request_queue *q, return BLK_STS_OK; } +static inline void blk_create_io_context(struct request_queue *q) +{ + /* + * Various block parts want %current->io_context, so allocate it up + * front rather than dealing with lots of pain to allocate it only + * where needed. This may fail and the block layer knows how to live + * with it. + */ + if (unlikely(!current->io_context)) + create_task_io_context(current, GFP_ATOMIC, q->node); +} + static noinline_for_stack bool submit_bio_checks(struct bio *bio) { struct block_device *bdev = bio->bi_bdev; @@ -836,6 +848,8 @@ static noinline_for_stack bool submit_bio_checks(struct bio *bio) } } + blk_create_io_context(q); + if (!blk_queue_poll(q)) bio->bi_opf &= ~REQ_HIPRI; @@ -876,15 +890,6 @@ static noinline_for_stack bool submit_bio_checks(struct bio *bio) break; } - /* - * Various block parts want %current->io_context, so allocate it up - * front rather than dealing with lots of pain to allocate it only - * where needed. This may fail and the block layer knows how to live - * with it. - */ - if (unlikely(!current->io_context)) - create_task_io_context(current, GFP_ATOMIC, q->node); - if (blk_throtl_bio(bio)) { blkcg_bio_issue_init(bio); return false; From patchwork Tue Mar 16 03:15:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 12141155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4DE9C4332B for ; Tue, 16 Mar 2021 03:19:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C64FA64FB2 for ; Tue, 16 Mar 2021 03:19:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231326AbhCPDSZ (ORCPT ); Mon, 15 Mar 2021 23:18:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57589 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234765AbhCPDSO (ORCPT ); Mon, 15 Mar 2021 23:18:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615864693; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IiPSr5VwrIg5qmtCl0gZdFgm3nFcl1UuqPwXIPyktps=; b=A08wCPtI688RI+1hf4v78hgPwlhzc+iuVUeiILqIbLUz6eQRzT8LWIXCRStCJ9mTb+wgK7 oTBbpVanWLJ0Xe9SBk8USzgSz0Dao80BYRQE4yJnneYEkW0ssGaUg4IxJGy6bAzNXFQPev neW3rev48ZvVYxJn3UMSAIt/og5TY8g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-214-j3BGYDWOMgqAe0S5pqn8bA-1; Mon, 15 Mar 2021 23:18:11 -0400 X-MC-Unique: j3BGYDWOMgqAe0S5pqn8bA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 565DD1074644; Tue, 16 Mar 2021 03:18:10 +0000 (UTC) Received: from localhost (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 709725C261; Tue, 16 Mar 2021 03:17:58 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Jeffle Xu , Mike Snitzer , dm-devel@redhat.com, Ming Lei Subject: [RFC PATCH 04/11] block: create io poll context for submission and poll task Date: Tue, 16 Mar 2021 11:15:16 +0800 Message-Id: <20210316031523.864506-5-ming.lei@redhat.com> In-Reply-To: <20210316031523.864506-1-ming.lei@redhat.com> References: <20210316031523.864506-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Create per-task io poll context for both IO submission and poll task if the queue is bio based and supports polling. This io polling context includes two queues: submission queue(sq) for storing HIPRI bio submission result(cookie) and the bio, written by submission task and read by poll task; polling queue(pq) for holding data moved from sq, only used in poll context for running bio polling. Following patches will support bio poll. Signed-off-by: Ming Lei --- block/blk-core.c | 59 +++++++++++++++++++++++++++++++-------- block/blk-ioc.c | 1 + block/blk-mq.c | 14 ++++++++++ block/blk.h | 45 +++++++++++++++++++++++++++++ include/linux/iocontext.h | 2 ++ 5 files changed, 109 insertions(+), 12 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index d58f8a0c80de..7c7b0dba4f5c 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -792,16 +792,47 @@ static inline blk_status_t blk_check_zone_append(struct request_queue *q, return BLK_STS_OK; } -static inline void blk_create_io_context(struct request_queue *q) +static inline bool blk_queue_support_bio_poll(struct request_queue *q) { - /* - * Various block parts want %current->io_context, so allocate it up - * front rather than dealing with lots of pain to allocate it only - * where needed. This may fail and the block layer knows how to live - * with it. - */ - if (unlikely(!current->io_context)) - create_task_io_context(current, GFP_ATOMIC, q->node); + return !queue_is_mq(q) && blk_queue_poll(q); +} + +static inline struct blk_bio_poll_ctx *blk_get_bio_poll_ctx(void) +{ + struct io_context *ioc = current->io_context; + + return ioc ? ioc->data : NULL; +} + +static void bio_poll_ctx_init(struct blk_bio_poll_ctx *pc) +{ + spin_lock_init(&pc->lock); + INIT_KFIFO(pc->sq); + + mutex_init(&pc->pq_lock); + memset(pc->pq, 0, sizeof(pc->pq)); +} + +void bio_poll_ctx_alloc(struct io_context *ioc) +{ + struct blk_bio_poll_ctx *pc; + + pc = kmalloc(sizeof(*pc), GFP_ATOMIC); + if (pc) { + bio_poll_ctx_init(pc); + if (cmpxchg(&ioc->data, NULL, (void *)pc)) + kfree(pc); + } +} + +static inline void blk_bio_poll_preprocess(struct request_queue *q, + struct bio *bio) +{ + if (!(bio->bi_opf & REQ_HIPRI)) + return; + + if (!blk_queue_poll(q) || (!queue_is_mq(q) && !blk_get_bio_poll_ctx())) + bio->bi_opf &= ~REQ_HIPRI; } static noinline_for_stack bool submit_bio_checks(struct bio *bio) @@ -848,10 +879,14 @@ static noinline_for_stack bool submit_bio_checks(struct bio *bio) } } - blk_create_io_context(q); + /* + * Created per-task io poll queue if we supports bio polling + * and it is one HIPRI bio. + */ + blk_create_io_context(q, blk_queue_support_bio_poll(q) && + (bio->bi_opf & REQ_HIPRI)); - if (!blk_queue_poll(q)) - bio->bi_opf &= ~REQ_HIPRI; + blk_bio_poll_preprocess(q, bio); switch (bio_op(bio)) { case REQ_OP_DISCARD: diff --git a/block/blk-ioc.c b/block/blk-ioc.c index b0cde18c4b8c..5574c398eff6 100644 --- a/block/blk-ioc.c +++ b/block/blk-ioc.c @@ -19,6 +19,7 @@ static struct kmem_cache *iocontext_cachep; static inline void free_io_context(struct io_context *ioc) { + kfree(ioc->data); kmem_cache_free(iocontext_cachep, ioc); } diff --git a/block/blk-mq.c b/block/blk-mq.c index 63c81df3b8b5..c832faa52ca0 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3852,6 +3852,17 @@ static bool blk_mq_poll_hybrid(struct request_queue *q, return blk_mq_poll_hybrid_sleep(q, rq); } +static int blk_bio_poll(struct request_queue *q, blk_qc_t cookie, bool spin) +{ + /* + * Create poll queue for storing poll bio and its cookie from + * submission queue + */ + blk_create_io_context(q, true); + + return 0; +} + /** * blk_poll - poll for IO completions * @q: the queue @@ -3875,6 +3886,9 @@ int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin) if (current->plug) blk_flush_plug_list(current->plug, false); + if (!queue_is_mq(q)) + return blk_bio_poll(q, cookie, spin); + hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)]; /* diff --git a/block/blk.h b/block/blk.h index 3b53e44b967e..f7a889bb3720 100644 --- a/block/blk.h +++ b/block/blk.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "blk-crypto-internal.h" #include "blk-mq.h" #include "blk-mq-sched.h" @@ -357,4 +358,48 @@ int bio_add_hw_page(struct request_queue *q, struct bio *bio, struct page *page, unsigned int len, unsigned int offset, unsigned int max_sectors, bool *same_page); +#define BLK_BIO_POLL_SQ_SZ 64U +#define BLK_BIO_POLL_PQ_SZ (BLK_BIO_POLL_SQ_SZ * 2) + +/* result of submit_bio */ +struct blk_bio_poll_data { + struct bio *bio; +}; + +/* Per-task bio poll queue data and attached to io context */ +struct blk_bio_poll_ctx { + spinlock_t lock; + /* + * Submission queue for storing HIPRI bio submission result, written + * by submission task and read by poll task + */ + DECLARE_KFIFO(sq, struct blk_bio_poll_data, BLK_BIO_POLL_SQ_SZ); + + /* Holding poll data moved from sq, only used in poll task */ + struct mutex pq_lock; + struct blk_bio_poll_data pq[BLK_BIO_POLL_PQ_SZ]; +}; + +void bio_poll_ctx_alloc(struct io_context *ioc); + +static inline void blk_create_io_context(struct request_queue *q, + bool need_poll_ctx) +{ + struct io_context *ioc; + + /* + * Various block parts want %current->io_context, so allocate it up + * front rather than dealing with lots of pain to allocate it only + * where needed. This may fail and the block layer knows how to live + * with it. + */ + if (unlikely(!current->io_context)) + create_task_io_context(current, GFP_ATOMIC, q->node); + + ioc = current->io_context; + if (need_poll_ctx && unlikely(ioc && !ioc->data)) + bio_poll_ctx_alloc(ioc); +} + + #endif /* BLK_INTERNAL_H */ diff --git a/include/linux/iocontext.h b/include/linux/iocontext.h index 0a9dc40b7be8..f9a467571356 100644 --- a/include/linux/iocontext.h +++ b/include/linux/iocontext.h @@ -110,6 +110,8 @@ struct io_context { struct io_cq __rcu *icq_hint; struct hlist_head icq_list; + void *data; + struct work_struct release_work; }; From patchwork Tue Mar 16 03:15:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 12141161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCCC9C433E9 for ; Tue, 16 Mar 2021 03:19:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABF156502E for ; Tue, 16 Mar 2021 03:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234773AbhCPDS5 (ORCPT ); Mon, 15 Mar 2021 23:18:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:34013 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231309AbhCPDS0 (ORCPT ); Mon, 15 Mar 2021 23:18:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615864705; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v2A/PMV03yGjSXb6zLcTex0eodeOpfhdbFj6ScnnbhQ=; b=UCrAm5Ywj8YNmxbOBv2hbPYexWvsRXiWIHXJDpjgilvxy0Tcm8LilfJ2aEno4ldED6yx95 v7GVN4GeKM3scTFUpfJ9dKoAN2HH6sIGoYyr5x8mNkulRQtOtZbBKj1/5mGL1XO3PeIlAl etmEslZHc6j+KrgTZx0DBVhNBSeisuM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-0f0lJ0WBOWK-84C9rIT1fw-1; Mon, 15 Mar 2021 23:18:23 -0400 X-MC-Unique: 0f0lJ0WBOWK-84C9rIT1fw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3183680006E; Tue, 16 Mar 2021 03:18:22 +0000 (UTC) Received: from localhost (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8401E1B472; Tue, 16 Mar 2021 03:18:12 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Jeffle Xu , Mike Snitzer , dm-devel@redhat.com, Ming Lei Subject: [RFC PATCH 05/11] block: add req flag of REQ_TAG Date: Tue, 16 Mar 2021 11:15:17 +0800 Message-Id: <20210316031523.864506-6-ming.lei@redhat.com> In-Reply-To: <20210316031523.864506-1-ming.lei@redhat.com> References: <20210316031523.864506-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add one req flag REQ_TAG which will be used in the following patch for supporting bio based IO polling. Exactly this flag can help us to do: 1) request flag is cloned in bio_fast_clone(), so if we mark one FS bio as REQ_TAG, all bios cloned from this FS bio will be marked as REQ_TAG. 2)create per-task io polling context if the bio based queue supports polling and the submitted bio is HIPRI. This per-task io polling context will be created during submit_bio() before marking this HIPRI bio as REQ_TAG. Then we can avoid to create such io polling context if one cloned bio with REQ_TAG is submitted from another kernel context. 3) for supporting bio based io polling, we need to poll IOs from all underlying queues of bio device/driver, this way help us to recognize which IOs need to polled in bio based style, which will be implemented in next patch. Signed-off-by: Ming Lei --- block/blk-core.c | 29 +++++++++++++++++++++++++++-- include/linux/blk_types.h | 4 ++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 7c7b0dba4f5c..a082bbc856fb 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -828,11 +828,30 @@ void bio_poll_ctx_alloc(struct io_context *ioc) static inline void blk_bio_poll_preprocess(struct request_queue *q, struct bio *bio) { + bool mq; + if (!(bio->bi_opf & REQ_HIPRI)) return; - if (!blk_queue_poll(q) || (!queue_is_mq(q) && !blk_get_bio_poll_ctx())) + /* + * Can't support bio based IO poll without per-task poll queue + * + * Now we have created per-task io poll context, and mark this + * bio as REQ_TAG, so: 1) if any cloned bio from this bio is + * submitted from another kernel context, we won't create bio + * poll context for it, so that bio will be completed by IRQ; + * 2) If such bio is submitted from current context, we will + * complete it via blk_poll(); 3) If driver knows that one + * underlying bio allocated from driver is for FS bio, meantime + * it is submitted in current context, driver can mark such bio + * as REQ_TAG manually, so the bio can be completed via blk_poll + * too. + */ + mq = queue_is_mq(q); + if (!blk_queue_poll(q) || (!mq && !blk_get_bio_poll_ctx())) bio->bi_opf &= ~REQ_HIPRI; + else if (!mq) + bio->bi_opf |= REQ_TAG; } static noinline_for_stack bool submit_bio_checks(struct bio *bio) @@ -881,9 +900,15 @@ static noinline_for_stack bool submit_bio_checks(struct bio *bio) /* * Created per-task io poll queue if we supports bio polling - * and it is one HIPRI bio. + * and it is one HIPRI bio, and this HIPRI bio has to be from + * FS. If REQ_TAG isn't set for HIPRI bio, we think it originated + * from FS. + * + * Driver may allocated bio by itself and REQ_TAG is set, but they + * won't be marked as HIPRI. */ blk_create_io_context(q, blk_queue_support_bio_poll(q) && + !(bio->bi_opf & REQ_TAG) && (bio->bi_opf & REQ_HIPRI)); blk_bio_poll_preprocess(q, bio); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index db026b6ec15a..a1bcade4bcc3 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -394,6 +394,9 @@ enum req_flag_bits { __REQ_HIPRI, + /* for marking IOs originated from same FS bio in same context */ + __REQ_TAG, + /* for driver use */ __REQ_DRV, __REQ_SWAP, /* swapping request. */ @@ -418,6 +421,7 @@ enum req_flag_bits { #define REQ_NOUNMAP (1ULL << __REQ_NOUNMAP) #define REQ_HIPRI (1ULL << __REQ_HIPRI) +#define REQ_TAG (1ULL << __REQ_TAG) #define REQ_DRV (1ULL << __REQ_DRV) #define REQ_SWAP (1ULL << __REQ_SWAP) From patchwork Tue Mar 16 03:15:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 12141159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAD0BC433E0 for ; Tue, 16 Mar 2021 03:19:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8BA4E65081 for ; Tue, 16 Mar 2021 03:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234758AbhCPDS6 (ORCPT ); Mon, 15 Mar 2021 23:18:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57689 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232177AbhCPDSj (ORCPT ); Mon, 15 Mar 2021 23:18:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615864718; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pPmdiGFpIEVHHdkjC5nrbTsamI2Cw8osFs9EsU37nO0=; b=AsIpwbIJILZRaNNM5RlOjMPmfLEP6dkqmiwixkzJk9CKkQyM3daFjSMmFYpQEbN/X9euU+ o69T5q9tJOFiKM8sT//dyrwAlnx20i0ctfUuJuE6FBeIOTP4R0vjQCXJLBDjOcqD5/vcv9 LmmWja+vSTrUHLT6cjT0hSh7qo/jFTM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-48-M_Q4PBwyO3Sa6_OxTYscOw-1; Mon, 15 Mar 2021 23:18:36 -0400 X-MC-Unique: M_Q4PBwyO3Sa6_OxTYscOw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C14E13E745; Tue, 16 Mar 2021 03:18:35 +0000 (UTC) Received: from localhost (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9056E1F04A; Tue, 16 Mar 2021 03:18:24 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Jeffle Xu , Mike Snitzer , dm-devel@redhat.com, Ming Lei Subject: [RFC PATCH 06/11] block: add new field into 'struct bvec_iter' Date: Tue, 16 Mar 2021 11:15:18 +0800 Message-Id: <20210316031523.864506-7-ming.lei@redhat.com> In-Reply-To: <20210316031523.864506-1-ming.lei@redhat.com> References: <20210316031523.864506-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org There is a hole at the end of 'struct bvec_iter', so put a new field here and we can save cookie returned from submit_bio() here for supporting bio based polling. This way can avoid to extend bio unnecessarily. Signed-off-by: Ming Lei --- include/linux/bvec.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index ff832e698efb..61c0f55f7165 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -43,6 +43,15 @@ struct bvec_iter { unsigned int bi_bvec_done; /* number of bytes completed in current bvec */ + + /* + * There is a hole at the end of bvec_iter, define one filed to + * hold something which isn't relate with 'bvec_iter', so that we can + * avoid to extend bio. So far this new field is used for bio based + * pooling, we will store returning value of underlying queue's + * submit_bio() here. + */ + unsigned int bi_private_data; }; struct bvec_iter_all { From patchwork Tue Mar 16 03:15:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 12141157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98ECAC433DB for ; Tue, 16 Mar 2021 03:19:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 629566502E for ; Tue, 16 Mar 2021 03:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232177AbhCPDS6 (ORCPT ); Mon, 15 Mar 2021 23:18:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:32039 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232083AbhCPDSx (ORCPT ); Mon, 15 Mar 2021 23:18:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615864733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OGFzBt2lBQvR+kYNIXjbrj2LIjdMT9WGJclN37ZNiu4=; b=Fhgc9WX+sXer6m2NHcH3u+GXMg1cCtMgEwPMtVM3lOL2sxxGuXo99ha0dyHaL4smWXoTly 1xVZdtSoy015PtT96ftUPuZuLdIUZY8RNIEhfF11AyHbB37GktMbSdVvoF2TGxBXaqKpQM c3eOu4ru6iXeyTeGvqH2mSzMvb7gQMQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-466-OJUyNo3lM2WFqyOXNHNubg-1; Mon, 15 Mar 2021 23:18:50 -0400 X-MC-Unique: OJUyNo3lM2WFqyOXNHNubg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 753E518460E0; Tue, 16 Mar 2021 03:18:49 +0000 (UTC) Received: from localhost (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3616B60C0F; Tue, 16 Mar 2021 03:18:37 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Jeffle Xu , Mike Snitzer , dm-devel@redhat.com, Ming Lei Subject: [RFC PATCH 07/11] block/mq: extract one helper function polling hw queue Date: Tue, 16 Mar 2021 11:15:19 +0800 Message-Id: <20210316031523.864506-8-ming.lei@redhat.com> In-Reply-To: <20210316031523.864506-1-ming.lei@redhat.com> References: <20210316031523.864506-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Jeffle Xu Extract the logic of polling one hw queue and related statistics handling out as the helper function. Signed-off-by: Jeffle Xu Signed-off-by: Ming Lei --- block/blk-mq.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index c832faa52ca0..03f59915fe2c 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3852,6 +3852,19 @@ static bool blk_mq_poll_hybrid(struct request_queue *q, return blk_mq_poll_hybrid_sleep(q, rq); } +static inline int blk_mq_poll_hctx(struct request_queue *q, + struct blk_mq_hw_ctx *hctx) +{ + int ret; + + hctx->poll_invoked++; + ret = q->mq_ops->poll(hctx); + if (ret > 0) + hctx->poll_success++; + + return ret; +} + static int blk_bio_poll(struct request_queue *q, blk_qc_t cookie, bool spin) { /* @@ -3908,11 +3921,8 @@ int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin) do { int ret; - hctx->poll_invoked++; - - ret = q->mq_ops->poll(hctx); + ret = blk_mq_poll_hctx(q, hctx); if (ret > 0) { - hctx->poll_success++; __set_current_state(TASK_RUNNING); return ret; } From patchwork Tue Mar 16 03:15:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 12141167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68E5BC433E0 for ; Tue, 16 Mar 2021 03:20:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43FA06509D for ; Tue, 16 Mar 2021 03:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233340AbhCPDT3 (ORCPT ); Mon, 15 Mar 2021 23:19:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43274 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234849AbhCPDTN (ORCPT ); Mon, 15 Mar 2021 23:19:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615864753; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mhtTZBRRpja8MMSLJvzi2bXYke2hXN6fXMc9kYf1Bpc=; b=SOoUdZJg0EQ3edkTSSE3o6wPNMMor2ewLpPMLrxdlJC7ddw4pmeFpxzhQE/tl4Vq794WmE YftBWjYZRbaqyuaJvF7ZUIDuTU338Qqx7NJWhkV4nzv8lXUoH/AfdRspx1dhkTBHWdP+5c sF7FOBZvZZfd/PEaHjpGLwIjja+FXUI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-530-i569yDTKNjWdptLojf8tsA-1; Mon, 15 Mar 2021 23:19:03 -0400 X-MC-Unique: i569yDTKNjWdptLojf8tsA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D94A087139C; Tue, 16 Mar 2021 03:19:01 +0000 (UTC) Received: from localhost (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1EE83100239A; Tue, 16 Mar 2021 03:18:51 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Jeffle Xu , Mike Snitzer , dm-devel@redhat.com, Ming Lei Subject: [RFC PATCH 08/11] block: use per-task poll context to implement bio based io poll Date: Tue, 16 Mar 2021 11:15:20 +0800 Message-Id: <20210316031523.864506-9-ming.lei@redhat.com> In-Reply-To: <20210316031523.864506-1-ming.lei@redhat.com> References: <20210316031523.864506-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Currently bio based IO poll needs to poll all hw queue blindly, this way is very inefficient, and the big reason is that we can't pass bio submission result to io poll task. In IO submission context, store associated underlying bios into the submission queue and save 'cookie' poll data in bio->bi_iter.bi_private_data, and return current->pid to caller of submit_bio() for any DM or bio based driver's IO, which is submitted from FS. In IO poll context, the passed cookie tells us the PID of submission context, and we can find the bio from that submission context. Moving bio from submission queue to poll queue of the poll context, and keep polling until these bios are ended. Remove bio from poll queue if the bio is ended. Add BIO_DONE and BIO_END_BY_POLL for such purpose. Usually submission shares context with io poll. The per-task poll context is just like stack variable, and it is cheap to move data between the two per-task queues. Signed-off-by: Ming Lei --- block/bio.c | 5 ++ block/blk-core.c | 74 +++++++++++++++++- block/blk-mq.c | 156 +++++++++++++++++++++++++++++++++++++- include/linux/blk_types.h | 3 + 4 files changed, 235 insertions(+), 3 deletions(-) diff --git a/block/bio.c b/block/bio.c index a1c4d2900c7a..bcf5eca0e8e3 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1402,6 +1402,11 @@ static inline bool bio_remaining_done(struct bio *bio) **/ void bio_endio(struct bio *bio) { + /* BIO_END_BY_POLL has to be set before calling submit_bio */ + if (bio_flagged(bio, BIO_END_BY_POLL)) { + bio_set_flag(bio, BIO_DONE); + return; + } again: if (!bio_remaining_done(bio)) return; diff --git a/block/blk-core.c b/block/blk-core.c index a082bbc856fb..970b23fa2e6e 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -854,6 +854,40 @@ static inline void blk_bio_poll_preprocess(struct request_queue *q, bio->bi_opf |= REQ_TAG; } +static bool blk_bio_poll_prep_submit(struct io_context *ioc, struct bio *bio) +{ + struct blk_bio_poll_data data = { + .bio = bio, + }; + struct blk_bio_poll_ctx *pc = ioc->data; + unsigned int queued; + + /* lock is required if there is more than one writer */ + if (unlikely(atomic_read(&ioc->nr_tasks) > 1)) { + spin_lock(&pc->lock); + queued = kfifo_put(&pc->sq, data); + spin_unlock(&pc->lock); + } else { + queued = kfifo_put(&pc->sq, data); + } + + /* + * Now the bio is added per-task fifo, mark it as END_BY_POLL, + * so we can save cookie into this bio after submit_bio(). + */ + if (queued) + bio_set_flag(bio, BIO_END_BY_POLL); + else + bio->bi_opf &= ~(REQ_HIPRI | REQ_TAG); + + return queued; +} + +static void blk_bio_poll_post_submit(struct bio *bio, blk_qc_t cookie) +{ + bio->bi_iter.bi_private_data = cookie; +} + static noinline_for_stack bool submit_bio_checks(struct bio *bio) { struct block_device *bdev = bio->bi_bdev; @@ -1008,7 +1042,7 @@ static blk_qc_t __submit_bio(struct bio *bio) * bio_list_on_stack[1] contains bios that were submitted before the current * ->submit_bio_bio, but that haven't been processed yet. */ -static blk_qc_t __submit_bio_noacct(struct bio *bio) +static blk_qc_t __submit_bio_noacct_int(struct bio *bio, struct io_context *ioc) { struct bio_list bio_list_on_stack[2]; blk_qc_t ret = BLK_QC_T_NONE; @@ -1031,7 +1065,16 @@ static blk_qc_t __submit_bio_noacct(struct bio *bio) bio_list_on_stack[1] = bio_list_on_stack[0]; bio_list_init(&bio_list_on_stack[0]); - ret = __submit_bio(bio); + if (ioc && queue_is_mq(q) && + (bio->bi_opf & (REQ_HIPRI | REQ_TAG))) { + bool queued = blk_bio_poll_prep_submit(ioc, bio); + + ret = __submit_bio(bio); + if (queued) + blk_bio_poll_post_submit(bio, ret); + } else { + ret = __submit_bio(bio); + } /* * Sort new bios into those for a lower level and those for the @@ -1057,6 +1100,33 @@ static blk_qc_t __submit_bio_noacct(struct bio *bio) return ret; } +static inline blk_qc_t __submit_bio_noacct_poll(struct bio *bio, + struct io_context *ioc) +{ + struct blk_bio_poll_ctx *pc = ioc->data; + int entries = kfifo_len(&pc->sq); + + __submit_bio_noacct_int(bio, ioc); + + /* bio submissions queued to per-task poll context */ + if (kfifo_len(&pc->sq) > entries) + return current->pid; + + /* swapper's pid is 0, but it can't submit poll IO for us */ + return 0; +} + +static inline blk_qc_t __submit_bio_noacct(struct bio *bio) +{ + struct io_context *ioc = current->io_context; + + if (ioc && ioc->data && (bio->bi_opf & REQ_HIPRI)) + return __submit_bio_noacct_poll(bio, ioc); + + return __submit_bio_noacct_int(bio, NULL); +} + + static blk_qc_t __submit_bio_noacct_mq(struct bio *bio) { struct bio_list bio_list[2] = { }; diff --git a/block/blk-mq.c b/block/blk-mq.c index 03f59915fe2c..4e6f1467d303 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3865,14 +3865,168 @@ static inline int blk_mq_poll_hctx(struct request_queue *q, return ret; } +static blk_qc_t bio_get_poll_cookie(struct bio *bio) +{ + return bio->bi_iter.bi_private_data; +} + +static int blk_mq_poll_io(struct bio *bio) +{ + struct request_queue *q = bio->bi_bdev->bd_disk->queue; + blk_qc_t cookie = bio_get_poll_cookie(bio); + int ret = 0; + + if (!bio_flagged(bio, BIO_DONE) && blk_qc_t_valid(cookie)) { + struct blk_mq_hw_ctx *hctx = + q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)]; + + ret += blk_mq_poll_hctx(q, hctx); + } + return ret; +} + +static int blk_bio_poll_and_end_io(struct request_queue *q, + struct blk_bio_poll_ctx *poll_ctx) +{ + struct blk_bio_poll_data *poll_data = &poll_ctx->pq[0]; + int ret = 0; + int i; + + for (i = 0; i < BLK_BIO_POLL_PQ_SZ; i++) { + struct bio *bio = poll_data[i].bio; + + if (!bio) + continue; + + ret += blk_mq_poll_io(bio); + if (bio_flagged(bio, BIO_DONE)) { + poll_data[i].bio = NULL; + + /* clear BIO_END_BY_POLL and end me really */ + bio_clear_flag(bio, BIO_END_BY_POLL); + bio_endio(bio); + } + } + return ret; +} + +static int __blk_bio_poll_io(struct request_queue *q, + struct blk_bio_poll_ctx *submit_ctx, + struct blk_bio_poll_ctx *poll_ctx) +{ + struct blk_bio_poll_data *poll_data = &poll_ctx->pq[0]; + int i; + + /* + * Move IO submission result from submission queue in submission + * context to poll queue of poll context. + * + * There may be more than one readers on poll queue of the same + * submission context, so have to lock here. + */ + spin_lock(&submit_ctx->lock); + for (i = 0; i < BLK_BIO_POLL_PQ_SZ; i++) { + if (poll_data[i].bio == NULL && + !kfifo_get(&submit_ctx->sq, &poll_data[i])) + break; + } + spin_unlock(&submit_ctx->lock); + + return blk_bio_poll_and_end_io(q, poll_ctx); +} + +static int blk_bio_poll_io(struct request_queue *q, + struct io_context *submit_ioc, + struct io_context *poll_ioc) +{ + struct blk_bio_poll_ctx *submit_ctx = submit_ioc->data; + struct blk_bio_poll_ctx *poll_ctx = poll_ioc->data; + int ret; + + if (unlikely(atomic_read(&poll_ioc->nr_tasks) > 1)) { + mutex_lock(&poll_ctx->pq_lock); + ret = __blk_bio_poll_io(q, submit_ctx, poll_ctx); + mutex_unlock(&poll_ctx->pq_lock); + } else { + ret = __blk_bio_poll_io(q, submit_ctx, poll_ctx); + } + return ret; +} + +static bool blk_bio_ioc_valid(struct task_struct *t) +{ + if (!t) + return false; + + if (!t->io_context) + return false; + + if (!t->io_context->data) + return false; + + return true; +} + +static int __blk_bio_poll(struct request_queue *q, blk_qc_t cookie) +{ + struct io_context *poll_ioc = current->io_context; + pid_t pid; + struct task_struct *submit_task; + int ret; + + pid = (pid_t)cookie; + + /* io poll often share io submission context */ + if (likely(current->pid == pid && blk_bio_ioc_valid(current))) + return blk_bio_poll_io(q, poll_ioc, poll_ioc); + + submit_task = find_get_task_by_vpid(pid); + if (likely(blk_bio_ioc_valid(submit_task))) + ret = blk_bio_poll_io(q, submit_task->io_context, + poll_ioc); + else + ret = 0; + + put_task_struct(submit_task); + + return ret; +} + static int blk_bio_poll(struct request_queue *q, blk_qc_t cookie, bool spin) { + long state; + + /* no need to poll */ + if (cookie == 0) + return 0; + /* * Create poll queue for storing poll bio and its cookie from * submission queue */ blk_create_io_context(q, true); + state = current->state; + do { + int ret; + + ret = __blk_bio_poll(q, cookie); + if (ret > 0) { + __set_current_state(TASK_RUNNING); + return ret; + } + + if (signal_pending_state(state, current)) + __set_current_state(TASK_RUNNING); + + if (current->state == TASK_RUNNING) + return 1; + if (ret < 0 || !spin) + break; + cpu_relax(); + } while (!need_resched()); + + __set_current_state(TASK_RUNNING); return 0; } @@ -3893,7 +4047,7 @@ int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin) struct blk_mq_hw_ctx *hctx; long state; - if (!blk_qc_t_valid(cookie) || !blk_queue_poll(q)) + if (!blk_queue_poll(q) || (queue_is_mq(q) && !blk_qc_t_valid(cookie))) return 0; if (current->plug) diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index a1bcade4bcc3..53f64eea9652 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -304,6 +304,9 @@ enum { BIO_CGROUP_ACCT, /* has been accounted to a cgroup */ BIO_TRACKED, /* set if bio goes through the rq_qos path */ BIO_REMAPPED, + BIO_END_BY_POLL, /* end by blk_bio_poll() explicitly */ + /* set when bio can be ended, used for bio with BIO_END_BY_POLL */ + BIO_DONE, BIO_FLAG_LAST }; From patchwork Tue Mar 16 03:15:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 12141163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58AF6C433E6 for ; Tue, 16 Mar 2021 03:20:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3268465098 for ; Tue, 16 Mar 2021 03:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233343AbhCPDT3 (ORCPT ); Mon, 15 Mar 2021 23:19:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46310 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234850AbhCPDTT (ORCPT ); Mon, 15 Mar 2021 23:19:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615864758; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+D7R0dmx1EexdXy1yf5Y6TiIr7C7M/actiCutRe5+Uw=; b=cQFjm7xZfv0Rnb78eaez4FR9t0biLb1/IIoiZL/R0XyRIozjvLypJNn0oemUM4Q1MvaCiP BTjngbXF1TzCjsMNjuCcf8GTIIzeeAPV3qVAZnp+3dpuyIzE6VdRGx9V83gjpxIbEwMfHO JSM1wUDvlyGitbUhWifwcxPtY9Yp4G4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-568-wjPZQHAhO9KijrDqmE0quw-1; Mon, 15 Mar 2021 23:19:14 -0400 X-MC-Unique: wjPZQHAhO9KijrDqmE0quw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E97118015BD; Tue, 16 Mar 2021 03:19:12 +0000 (UTC) Received: from localhost (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8C6E60C0F; Tue, 16 Mar 2021 03:19:04 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Jeffle Xu , Mike Snitzer , dm-devel@redhat.com Subject: [RFC PATCH 09/11] block: add queue_to_disk() to get gendisk from request_queue Date: Tue, 16 Mar 2021 11:15:21 +0800 Message-Id: <20210316031523.864506-10-ming.lei@redhat.com> In-Reply-To: <20210316031523.864506-1-ming.lei@redhat.com> References: <20210316031523.864506-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Jeffle Xu Sometimes we need to get the corresponding gendisk from request_queue. It is preferred that block drivers store private data in gendisk->private_data rather than request_queue->queuedata, e.g. see: commit c4a59c4e5db3 ("dm: stop using ->queuedata"). So if only request_queue is given, we need to get its corresponding gendisk to get the private data stored in that gendisk. Signed-off-by: Jeffle Xu Reviewed-by: Mike Snitzer --- include/linux/blkdev.h | 2 ++ include/trace/events/kyber.h | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 89a01850cf12..bfab74b45f15 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -686,6 +686,8 @@ static inline bool blk_account_rq(struct request *rq) dma_map_page_attrs(dev, (bv)->bv_page, (bv)->bv_offset, (bv)->bv_len, \ (dir), (attrs)) +#define queue_to_disk(q) (dev_to_disk(kobj_to_dev((q)->kobj.parent))) + static inline bool queue_is_mq(struct request_queue *q) { return q->mq_ops; diff --git a/include/trace/events/kyber.h b/include/trace/events/kyber.h index c0e7d24ca256..f9802562edf6 100644 --- a/include/trace/events/kyber.h +++ b/include/trace/events/kyber.h @@ -30,7 +30,7 @@ TRACE_EVENT(kyber_latency, ), TP_fast_assign( - __entry->dev = disk_devt(dev_to_disk(kobj_to_dev(q->kobj.parent))); + __entry->dev = disk_devt(queue_to_disk(q)); strlcpy(__entry->domain, domain, sizeof(__entry->domain)); strlcpy(__entry->type, type, sizeof(__entry->type)); __entry->percentile = percentile; @@ -59,7 +59,7 @@ TRACE_EVENT(kyber_adjust, ), TP_fast_assign( - __entry->dev = disk_devt(dev_to_disk(kobj_to_dev(q->kobj.parent))); + __entry->dev = disk_devt(queue_to_disk(q)); strlcpy(__entry->domain, domain, sizeof(__entry->domain)); __entry->depth = depth; ), @@ -81,7 +81,7 @@ TRACE_EVENT(kyber_throttled, ), TP_fast_assign( - __entry->dev = disk_devt(dev_to_disk(kobj_to_dev(q->kobj.parent))); + __entry->dev = disk_devt(queue_to_disk(q)); strlcpy(__entry->domain, domain, sizeof(__entry->domain)); ), From patchwork Tue Mar 16 03:15:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 12141165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47B70C433DB for ; Tue, 16 Mar 2021 03:20:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21BC665094 for ; Tue, 16 Mar 2021 03:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234788AbhCPDTa (ORCPT ); Mon, 15 Mar 2021 23:19:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41152 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233371AbhCPDTU (ORCPT ); Mon, 15 Mar 2021 23:19:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615864759; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kjaGyaqA/Zc0rF6PsrYol9YHFVkAp/HbPbJkCZlDhpw=; b=Wp4wuLsOn//8+j8A58zQ0oKfsw7i7yvgTdggTUy20t51OeNuNg6MDaYunH0PoqUVDpZMyw uW+XVo03oqL2E6ttO32oZJGP8GuHiX1plJwNWNFDP47hT4+kuTCrRL16q3RUsVz/3wdRy0 inYVdD/fSK+AOntyO2nmcHvnHuV/Xkk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-46-odpdhO4xM0uZ-mY2_NzR7A-1; Mon, 15 Mar 2021 23:19:17 -0400 X-MC-Unique: odpdhO4xM0uZ-mY2_NzR7A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7420100C61F; Tue, 16 Mar 2021 03:19:15 +0000 (UTC) Received: from localhost (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB54860C0F; Tue, 16 Mar 2021 03:19:14 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Jeffle Xu , Mike Snitzer , dm-devel@redhat.com Subject: [RFC PATCH 10/11] block: add poll_capable method to support bio-based IO polling Date: Tue, 16 Mar 2021 11:15:22 +0800 Message-Id: <20210316031523.864506-11-ming.lei@redhat.com> In-Reply-To: <20210316031523.864506-1-ming.lei@redhat.com> References: <20210316031523.864506-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Jeffle Xu This method can be used to check if bio-based device supports IO polling or not. For mq devices, checking for hw queue in polling mode is adequate, while the sanity check shall be implementation specific for bio-based devices. For example, dm device needs to check if all underlying devices are capable of IO polling. Though bio-based device may have done the sanity check during the device initialization phase, cacheing the result of this sanity check (such as by cacheing in the queue_flags) may not work. Because for dm devices, users could change the state of the underlying devices through '/sys/block//io_poll', bypassing the dm device above. In this case, the cached result of the very beginning sanity check could be out-of-date. Thus the sanity check needs to be done every time 'io_poll' is to be modified. Signed-off-by: Jeffle Xu --- block/blk-sysfs.c | 14 +++++++++++--- include/linux/blkdev.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 0f4f0c8a7825..367c1d9a55c6 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -426,9 +426,17 @@ static ssize_t queue_poll_store(struct request_queue *q, const char *page, unsigned long poll_on; ssize_t ret; - if (!q->tag_set || q->tag_set->nr_maps <= HCTX_TYPE_POLL || - !q->tag_set->map[HCTX_TYPE_POLL].nr_queues) - return -EINVAL; + if (queue_is_mq(q)) { + if (!q->tag_set || q->tag_set->nr_maps <= HCTX_TYPE_POLL || + !q->tag_set->map[HCTX_TYPE_POLL].nr_queues) + return -EINVAL; + } else { + struct gendisk *disk = queue_to_disk(q); + + if (!disk->fops->poll_capable || + !disk->fops->poll_capable(disk)) + return -EINVAL; + } ret = queue_var_store(&poll_on, page, count); if (ret < 0) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index bfab74b45f15..a46f975f2a2f 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1881,6 +1881,7 @@ struct block_device_operations { int (*report_zones)(struct gendisk *, sector_t sector, unsigned int nr_zones, report_zones_cb cb, void *data); char *(*devnode)(struct gendisk *disk, umode_t *mode); + bool (*poll_capable)(struct gendisk *disk); struct module *owner; const struct pr_ops *pr_ops; }; From patchwork Tue Mar 16 03:15:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 12141169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01A47C433DB for ; Tue, 16 Mar 2021 03:20:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C9B1965093 for ; Tue, 16 Mar 2021 03:20:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231309AbhCPDUD (ORCPT ); Mon, 15 Mar 2021 23:20:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26959 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234765AbhCPDTa (ORCPT ); Mon, 15 Mar 2021 23:19:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615864769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8Pi4isQ4p1z5in4o0Y+/H4NZqFcKCveDzivrRliTjko=; b=RhT8d3YosTkgwm6wXJ1EQKYsJL7ZyrpNGPex6twYGr6AcTi1ztLHJKzbnEYBK8keJGscBL Py3fofNvAnqOWyHQXhF5TRsO/u+P75CzsfbLK7VDk7qTJbdqXzpFTHogStcGb2B7U0y2UM 52gCdtd+zUrFotTl7/cA4oRURCnU4Ko= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-176-owImDeVeOFyZeSKht9SmUw-1; Mon, 15 Mar 2021 23:19:26 -0400 X-MC-Unique: owImDeVeOFyZeSKht9SmUw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8DFDA100C624; Tue, 16 Mar 2021 03:19:25 +0000 (UTC) Received: from localhost (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1FC11B472; Tue, 16 Mar 2021 03:19:18 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Jeffle Xu , Mike Snitzer , dm-devel@redhat.com, Ming Lei Subject: [RFC PATCH 11/11] dm: support IO polling for bio-based dm device Date: Tue, 16 Mar 2021 11:15:23 +0800 Message-Id: <20210316031523.864506-12-ming.lei@redhat.com> In-Reply-To: <20210316031523.864506-1-ming.lei@redhat.com> References: <20210316031523.864506-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Jeffle Xu IO polling is enabled when all underlying target devices are capable of IO polling. The sanity check supports the stacked device model, in which one dm device may be build upon another dm device. In this case, the mapped device will check if the underlying dm target device supports IO polling. Signed-off-by: Jeffle Xu Signed-off-by: Ming Lei --- drivers/md/dm-table.c | 24 ++++++++++++++++++++++++ drivers/md/dm.c | 14 ++++++++++++++ include/linux/device-mapper.h | 1 + 3 files changed, 39 insertions(+) diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 95391f78b8d5..a8f3575fb118 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1509,6 +1509,12 @@ struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector) return &t->targets[(KEYS_PER_NODE * n) + k]; } +static int device_not_poll_capable(struct dm_target *ti, struct dm_dev *dev, + sector_t start, sector_t len, void *data) +{ + return !blk_queue_poll(bdev_get_queue(dev->bdev)); +} + /* * type->iterate_devices() should be called when the sanity check needs to * iterate and check all underlying data devices. iterate_devices() will @@ -1559,6 +1565,11 @@ static int count_device(struct dm_target *ti, struct dm_dev *dev, return 0; } +int dm_table_supports_poll(struct dm_table *t) +{ + return !dm_table_any_dev_attr(t, device_not_poll_capable, NULL); +} + /* * Check whether a table has no data devices attached using each * target's iterate_devices method. @@ -2079,6 +2090,19 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, dm_update_keyslot_manager(q, t); blk_queue_update_readahead(q); + + /* + * Check for request-based device is remained to + * dm_mq_init_request_queue()->blk_mq_init_allocated_queue(). + * For bio-based device, only set QUEUE_FLAG_POLL when all underlying + * devices supporting polling. + */ + if (__table_type_bio_based(t->type)) { + if (dm_table_supports_poll(t)) + blk_queue_flag_set(QUEUE_FLAG_POLL, q); + else + blk_queue_flag_clear(QUEUE_FLAG_POLL, q); + } } unsigned int dm_table_get_num_targets(struct dm_table *t) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 50b693d776d6..fe6893b078dc 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1720,6 +1720,19 @@ static blk_qc_t dm_submit_bio(struct bio *bio) return ret; } +static bool dm_bio_poll_capable(struct gendisk *disk) +{ + int ret, srcu_idx; + struct mapped_device *md = disk->private_data; + struct dm_table *t; + + t = dm_get_live_table(md, &srcu_idx); + ret = dm_table_supports_poll(t); + dm_put_live_table(md, srcu_idx); + + return ret; +} + /*----------------------------------------------------------------- * An IDR is used to keep track of allocated minor numbers. *---------------------------------------------------------------*/ @@ -3132,6 +3145,7 @@ static const struct pr_ops dm_pr_ops = { }; static const struct block_device_operations dm_blk_dops = { + .poll_capable = dm_bio_poll_capable, .submit_bio = dm_submit_bio, .open = dm_blk_open, .release = dm_blk_close, diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index 7f4ac87c0b32..31bfd6f70013 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -538,6 +538,7 @@ unsigned int dm_table_get_num_targets(struct dm_table *t); fmode_t dm_table_get_mode(struct dm_table *t); struct mapped_device *dm_table_get_md(struct dm_table *t); const char *dm_table_device_name(struct dm_table *t); +int dm_table_supports_poll(struct dm_table *t); /* * Trigger an event.