From patchwork Wed Dec 21 14:54:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suwan Kim X-Patchwork-Id: 13078841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 056F9C10F1B for ; Wed, 21 Dec 2022 14:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230330AbiLUOz4 (ORCPT ); Wed, 21 Dec 2022 09:55:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233349AbiLUOzs (ORCPT ); Wed, 21 Dec 2022 09:55:48 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57B0F140C9 for ; Wed, 21 Dec 2022 06:55:45 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id o8-20020a17090a9f8800b00223de0364beso2509926pjp.4 for ; Wed, 21 Dec 2022 06:55:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oIgIdejzi7kfMhcYcxmjgpZ21/ag/3NGf2L7s06JKrM=; b=fhsx/Eglgb14WGP+LMD47jzl2H2vn5PJC5spDY9blUZ5D2SbIyHphhQx4kerdbIUWt 03YaYqmASeaji5b6McX/HF490B1Z43sdpb0rxAkZLsP4I5zhH29ztmysaFk2ijIxmvam gdXuGLCXePT9XP9lI6HwS13UltM3PjXFqRTxFiZKKi7sCZ2vfpzik+a+dJxS7CQ4DdL9 fJ5XsJHzswJGjRNKekUUquZcRWu/S3AkJXDGaBP7AnmicJSsrFcj6KoYYDh2YcaQgvGq 88JYaSWwN5bQkjBEm/sVe+iOj985oNkmBZw8UA0FjAldQP0xN9VoF+/zpwTWiLNjrKqJ cT4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oIgIdejzi7kfMhcYcxmjgpZ21/ag/3NGf2L7s06JKrM=; b=cM8niv4jmwJqLcGMPnwyJjdUrRrc+yocePwPLWRzTp91/2kj5om45KD2o/Hf7Q/PCF zxnm5cPKKYBBXBQOWTiAYXcrBp1nwKWAkVy92kW7DC/YrQFC+xqaxO1g6CVfy88OfS8z ijgrzbL8sGtCGCZP+8dcFwiENwYhOIMGcV3RhKrzP3oCKO1mOrzxgzxaNUxnTZjL4X+7 KZ2dHdQzvOJHPIcB+kXUD+AFGLD9/ejwy0CgUnuvCZRy74xchEDTxgOGapUPDT+DCzo/ Dl+QkHhd3pVlgdxALTer8VqjlgRAX/Op01mTvIcpgoNA6jtbHP54hfWr8a75RRc+xv8m EITQ== X-Gm-Message-State: AFqh2koi2+vrnu1XKKdX97/FVLFi4RzCMx7YWNke9lr5LY3OAD3l1Q0j rLgsOAJWdeUfPfflXKpRPn8= X-Google-Smtp-Source: AMrXdXtaN42XXjnWwlUAOAs2jxqdf7XWBSUtSAcXvD+xayLtvLOx4uggx8Bu8CU2QJEBBxPDn4tA7g== X-Received: by 2002:a17:902:7c95:b0:190:ee85:b25f with SMTP id y21-20020a1709027c9500b00190ee85b25fmr2023713pll.48.1671634545341; Wed, 21 Dec 2022 06:55:45 -0800 (PST) Received: from localhost.localdomain ([114.200.4.15]) by smtp.googlemail.com with ESMTPSA id d9-20020a170903230900b00176dc67df44sm11573994plh.132.2022.12.21.06.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 06:55:44 -0800 (PST) From: Suwan Kim To: mst@redhat.com, jasowang@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, hch@infradead.org, axboe@kernel.dk Cc: virtualization@lists.linux-foundation.org, linux-block@vger.kernel.org, Suwan Kim , Christoph Hellwig Subject: [PATCH v3 1/2] virtio-blk: set req->state to MQ_RQ_COMPLETE after polling I/O is finished Date: Wed, 21 Dec 2022 23:54:55 +0900 Message-Id: <20221221145456.281218-2-suwan.kim027@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20221221145456.281218-1-suwan.kim027@gmail.com> References: <20221221145456.281218-1-suwan.kim027@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Driver should set req->state to MQ_RQ_COMPLETE after it finishes to process req. But virtio-blk doesn't set MQ_RQ_COMPLETE after virtblk_poll() handles req and req->state still remains MQ_RQ_IN_FLIGHT. Fortunately so far there is no issue about it because blk_mq_end_request_batch() sets req->state to MQ_RQ_IDLE. In this patch, virblk_poll() calls blk_mq_complete_request_remote() to set req->state to MQ_RQ_COMPLETE before it adds req to a batch completion list. So it properly sets req->state after polling I/O is finished. Fixes: 4e0400525691 ("virtio-blk: support polling I/O") Signed-off-by: Suwan Kim Reviewed-by: Christoph Hellwig --- drivers/block/virtio_blk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 19da5defd734..75ee51aba964 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -858,9 +858,10 @@ static int virtblk_poll(struct blk_mq_hw_ctx *hctx, struct io_comp_batch *iob) struct request *req = blk_mq_rq_from_pdu(vbr); found++; - if (!blk_mq_add_to_batch(req, iob, vbr->status, + if (!blk_mq_complete_request_remote(req) && + !blk_mq_add_to_batch(req, iob, vbr->status, virtblk_complete_batch)) - blk_mq_complete_request(req); + virtblk_request_done(req); } if (found) From patchwork Wed Dec 21 14:54:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suwan Kim X-Patchwork-Id: 13078842 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25FD8C4332F for ; Wed, 21 Dec 2022 14:56:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233777AbiLUO4I (ORCPT ); Wed, 21 Dec 2022 09:56:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233747AbiLUOzw (ORCPT ); Wed, 21 Dec 2022 09:55:52 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E51C183BD for ; Wed, 21 Dec 2022 06:55:50 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id o1-20020a17090a678100b00219cf69e5f0so2531638pjj.2 for ; Wed, 21 Dec 2022 06:55:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/bCgZvA0kqp3iSuTat4yeXBgIoJ3hCErb5UDQaWVxOQ=; b=LUv7t/n9y3cadzgqZM+SQEQ5hZel/Ezp/bUxg/fkpb60ty+YjJfQOy/42bNkh92zsS pFiX+hX4yUzHSUbLqIJvXHFhD8HOdkI3uOxk8FTw3KbU5yib33ok1pPKAStBOD/wN9l1 4PQ6//I5SJSbb6X8XCstL+fKF2uimT5i5CmBRZZQyE6PgKn6Hj4kiHE3OaKgABSRGFku sRyfQT7VlL7Qt18EPtDkB3NSxJHmGsGN1PtnEuRO0Ku+Bfk8pA74l9WA+CCDv0O9Ja/4 ssm6ngKM6PqANWv+csjHukdO/pqv7/6Xup1J3ZxmwMTj/i3OyK7xNPBwsjTkr166k9Lz MmyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/bCgZvA0kqp3iSuTat4yeXBgIoJ3hCErb5UDQaWVxOQ=; b=WgLHMnzPvBrgT0jU8WSkXsoV/+F3bghghP8hAYhDaF1GaOMBAmgCA/aj3Dsw0ZHamJ JvfHfVS9HXuYCR1JHGBKTgl73uVUXHIWqksQjLwgvGp6pgPEylAP5yMqg7f4/gziSn5O y5XW3ZmdujYiav/PfUUJauOUP5hJEzfj3n0ybeneE4LA0NlZ599IAC2oPmhmGNo6T/ZR gkD3PQJkJe/CMsn6BsDJUuQcQ3TdD1QOotzN3Ne5BamViJdtypPGUl/NqrSeeLume+VZ ZUjkcJTDXViCT6WAdlv4tqsPMnoANpv9LuppJ4STNF/7CeXXi2jOEvRyEV5Vulv2vrHC T7BA== X-Gm-Message-State: AFqh2kpYxS4Pziut1kozOkaoD3P3oKW2gJanNsUk2ZAAAE6132xDAwAW xOpfHze8OnyFhCNhFuDhlH8= X-Google-Smtp-Source: AMrXdXugVAi0jT6JSdeS6WDHGu5GGoho7GdqWhBnBh5GQYhGWi1IEJPuFeJ302A09cltYH0NBzagWQ== X-Received: by 2002:a17:903:30d2:b0:186:e426:ff33 with SMTP id s18-20020a17090330d200b00186e426ff33mr1987441plc.20.1671634549688; Wed, 21 Dec 2022 06:55:49 -0800 (PST) Received: from localhost.localdomain ([114.200.4.15]) by smtp.googlemail.com with ESMTPSA id d9-20020a170903230900b00176dc67df44sm11573994plh.132.2022.12.21.06.55.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 06:55:49 -0800 (PST) From: Suwan Kim To: mst@redhat.com, jasowang@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, hch@infradead.org, axboe@kernel.dk Cc: virtualization@lists.linux-foundation.org, linux-block@vger.kernel.org, Suwan Kim , Christoph Hellwig Subject: [PATCH v3 2/2] virtio-blk: support completion batching for the IRQ path Date: Wed, 21 Dec 2022 23:54:56 +0900 Message-Id: <20221221145456.281218-3-suwan.kim027@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20221221145456.281218-1-suwan.kim027@gmail.com> References: <20221221145456.281218-1-suwan.kim027@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org This patch adds completion batching to the IRQ path. It reuses batch completion code of virtblk_poll(). It collects requests to io_comp_batch and processes them all at once. It can boost up the performance by 2%. To validate the performance improvement and stabilty, I did fio test with 4 vCPU VM and 12 vCPU VM respectively. Both VMs have 8GB ram and the same number of HW queues as vCPU. The fio cammad is as follows and I ran the fio 5 times and got IOPS average. (io_uring, randread, direct=1, bs=512, iodepth=64 numjobs=2,4) Test result shows about 2% improvement. 4 vcpu VM | numjobs=2 | numjobs=4 ----------------------------------------------------------- fio without patch | 367.2K IOPS | 397.6K IOPS ----------------------------------------------------------- fio with patch | 372.8K IOPS | 407.7K IOPS 12 vcpu VM | numjobs=2 | numjobs=4 ----------------------------------------------------------- fio without patch | 363.6K IOPS | 374.8K IOPS ----------------------------------------------------------- fio with patch | 373.8K IOPS | 385.3K IOPS Signed-off-by: Suwan Kim Reviewed-by: Christoph Hellwig --- drivers/block/virtio_blk.c | 82 +++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 75ee51aba964..91f1e008d6ab 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -272,33 +272,63 @@ static inline void virtblk_request_done(struct request *req) blk_mq_end_request(req, virtblk_result(vbr)); } +static void virtblk_complete_batch(struct io_comp_batch *iob) +{ + struct request *req; + + rq_list_for_each(&iob->req_list, req) { + virtblk_unmap_data(req, blk_mq_rq_to_pdu(req)); + virtblk_cleanup_cmd(req); + } + blk_mq_end_request_batch(iob); +} + +static int virtblk_handle_req(struct virtio_blk_vq *vq, + struct io_comp_batch *iob) +{ + struct virtblk_req *vbr; + int req_done = 0; + unsigned int len; + + while ((vbr = virtqueue_get_buf(vq->vq, &len)) != NULL) { + struct request *req = blk_mq_rq_from_pdu(vbr); + + if (likely(!blk_should_fake_timeout(req->q)) && + !blk_mq_complete_request_remote(req) && + !blk_mq_add_to_batch(req, iob, vbr->status, + virtblk_complete_batch)) + virtblk_request_done(req); + req_done++; + } + + return req_done; +} + static void virtblk_done(struct virtqueue *vq) { struct virtio_blk *vblk = vq->vdev->priv; - bool req_done = false; - int qid = vq->index; - struct virtblk_req *vbr; + struct virtio_blk_vq *vblk_vq = &vblk->vqs[vq->index]; + int req_done = 0; unsigned long flags; - unsigned int len; + DEFINE_IO_COMP_BATCH(iob); - spin_lock_irqsave(&vblk->vqs[qid].lock, flags); + spin_lock_irqsave(&vblk_vq->lock, flags); do { virtqueue_disable_cb(vq); - while ((vbr = virtqueue_get_buf(vblk->vqs[qid].vq, &len)) != NULL) { - struct request *req = blk_mq_rq_from_pdu(vbr); + req_done += virtblk_handle_req(vblk_vq, &iob); - if (likely(!blk_should_fake_timeout(req->q))) - blk_mq_complete_request(req); - req_done = true; - } if (unlikely(virtqueue_is_broken(vq))) break; } while (!virtqueue_enable_cb(vq)); - /* In case queue is stopped waiting for more buffers. */ - if (req_done) + if (req_done) { + if (!rq_list_empty(iob.req_list)) + iob.complete(&iob); + + /* In case queue is stopped waiting for more buffers. */ blk_mq_start_stopped_hw_queues(vblk->disk->queue, true); - spin_unlock_irqrestore(&vblk->vqs[qid].lock, flags); + } + spin_unlock_irqrestore(&vblk_vq->lock, flags); } static void virtio_commit_rqs(struct blk_mq_hw_ctx *hctx) @@ -832,37 +862,15 @@ static void virtblk_map_queues(struct blk_mq_tag_set *set) } } -static void virtblk_complete_batch(struct io_comp_batch *iob) -{ - struct request *req; - - rq_list_for_each(&iob->req_list, req) { - virtblk_unmap_data(req, blk_mq_rq_to_pdu(req)); - virtblk_cleanup_cmd(req); - } - blk_mq_end_request_batch(iob); -} - static int virtblk_poll(struct blk_mq_hw_ctx *hctx, struct io_comp_batch *iob) { struct virtio_blk *vblk = hctx->queue->queuedata; struct virtio_blk_vq *vq = get_virtio_blk_vq(hctx); - struct virtblk_req *vbr; unsigned long flags; - unsigned int len; int found = 0; spin_lock_irqsave(&vq->lock, flags); - - while ((vbr = virtqueue_get_buf(vq->vq, &len)) != NULL) { - struct request *req = blk_mq_rq_from_pdu(vbr); - - found++; - if (!blk_mq_complete_request_remote(req) && - !blk_mq_add_to_batch(req, iob, vbr->status, - virtblk_complete_batch)) - virtblk_request_done(req); - } + found = virtblk_handle_req(vq, iob); if (found) blk_mq_start_stopped_hw_queues(vblk->disk->queue, true);