From patchwork Fri Jan 28 15:58:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 12728690 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 89B4DC433FE for ; Fri, 28 Jan 2022 15:58:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349800AbiA1P6v (ORCPT ); Fri, 28 Jan 2022 10:58:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:39627 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245032AbiA1P6r (ORCPT ); Fri, 28 Jan 2022 10:58:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643385526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=feoZP+F8CU+MhuuvBnIaQ56CdERUV6n68Kc4W9BEtGU=; b=g3F94lnge+RwRqyHrcfOsAtScS9MdiIRrsYPW3YyBvUt4Fxlvvomr22g+7gS+8bl+ZGCug Qo6UE8INXKdES0VuFvWIJaegxnQdGSUwIXFHYwmBcOIckXknbDGznwJrlSpARsKhC+yd7X MleYPzqVN9bCGpw8K/rlZnvWjtIgTUw= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-115-7ooOfIh7MIGv-QAUs3zOnQ-1; Fri, 28 Jan 2022 10:58:45 -0500 X-MC-Unique: 7ooOfIh7MIGv-QAUs3zOnQ-1 Received: by mail-qt1-f199.google.com with SMTP id c20-20020ac84e14000000b002d198444921so4784237qtw.23 for ; Fri, 28 Jan 2022 07:58:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=feoZP+F8CU+MhuuvBnIaQ56CdERUV6n68Kc4W9BEtGU=; b=kXjKymwQFfLANK6DuHMokK/U9/HfeXvYc+ICVT8gSbmG7hltqFBZ/IS1NtIPGIh1ED Fdm1RZZ+U1ZDai3086KyKOz9iaHLQycWOMwnkDhwzjeaL2tY2gcn2Ai+ckXUMTR+9gn7 bClPVO/6cg2RMICHB6p5OIPuFeQV2Pzbsm2Qq9uwAM0vLMI7EaOSUJmqMmVRBEiRSpwx QZjxC5WZNHzTsAnWLPAKqc7BZcbHMOikaZb9E2GwJKjzbM4y9PnjYn7iVw9KQlH3rfpR w9jZgw6lY2w4byTPuIsohFs6iQt18LIt02z0jbtmdCHtkeUafineV9ByLk15z9fsKphP rODA== X-Gm-Message-State: AOAM533auHgiLu9+2utC09a1OsWytcDL7e9jMir4rw01OhLhBELk96SJ U5CX5isqUy8j3qYmEW5ZEemQDVn8onGaelHILe8OhEmoFlXsRRy1O6t+AwIDNF8r4YOS4lMT3J5 o7K/LAWF5vRN6dqiPxT/vfw== X-Received: by 2002:a37:454d:: with SMTP id s74mr5909293qka.405.1643385524656; Fri, 28 Jan 2022 07:58:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwuxz2dMV0PAXdD547KZ6/o97ih+oVUp28N/1DDUc/W/RNqad0W7Yx08YDHw8QRriC+il69ug== X-Received: by 2002:a37:454d:: with SMTP id s74mr5909286qka.405.1643385524475; Fri, 28 Jan 2022 07:58:44 -0800 (PST) Received: from localhost (pool-68-160-176-52.bstnma.fios.verizon.net. [68.160.176.52]) by smtp.gmail.com with ESMTPSA id w3sm3005092qta.13.2022.01.28.07.58.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jan 2022 07:58:44 -0800 (PST) From: Mike Snitzer To: axboe@kernel.dk Cc: hch@lst.de, dm-devel@redhat.com, linux-block@vger.kernel.org Subject: [PATCH v4 1/3] block: add bio_start_io_acct_time() to control start_time Date: Fri, 28 Jan 2022 10:58:39 -0500 Message-Id: <20220128155841.39644-2-snitzer@redhat.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20220128155841.39644-1-snitzer@redhat.com> References: <20220128155841.39644-1-snitzer@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org bio_start_io_acct_time() interface is like bio_start_io_acct() that allows start_time to be passed in. This gives drivers the ability to defer starting accounting until after IO is issued (but possibily not entirely due to bio splitting). Reviewed-by: Christoph Hellwig Signed-off-by: Mike Snitzer --- block/blk-core.c | 25 +++++++++++++++++++------ include/linux/blkdev.h | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 97f8bc8d3a79..d93e3bb9a769 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1061,20 +1061,32 @@ void update_io_ticks(struct block_device *part, unsigned long now, bool end) } static unsigned long __part_start_io_acct(struct block_device *part, - unsigned int sectors, unsigned int op) + unsigned int sectors, unsigned int op, + unsigned long start_time) { const int sgrp = op_stat_group(op); - unsigned long now = READ_ONCE(jiffies); part_stat_lock(); - update_io_ticks(part, now, false); + update_io_ticks(part, start_time, false); part_stat_inc(part, ios[sgrp]); part_stat_add(part, sectors[sgrp], sectors); part_stat_local_inc(part, in_flight[op_is_write(op)]); part_stat_unlock(); - return now; + return start_time; +} + +/** + * bio_start_io_acct_time - start I/O accounting for bio based drivers + * @bio: bio to start account for + * @start_time: start time that should be passed back to bio_end_io_acct(). + */ +void bio_start_io_acct_time(struct bio *bio, unsigned long start_time) +{ + __part_start_io_acct(bio->bi_bdev, bio_sectors(bio), + bio_op(bio), start_time); } +EXPORT_SYMBOL_GPL(bio_start_io_acct_time); /** * bio_start_io_acct - start I/O accounting for bio based drivers @@ -1084,14 +1096,15 @@ static unsigned long __part_start_io_acct(struct block_device *part, */ unsigned long bio_start_io_acct(struct bio *bio) { - return __part_start_io_acct(bio->bi_bdev, bio_sectors(bio), bio_op(bio)); + return __part_start_io_acct(bio->bi_bdev, bio_sectors(bio), + bio_op(bio), jiffies); } EXPORT_SYMBOL_GPL(bio_start_io_acct); unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, unsigned int op) { - return __part_start_io_acct(disk->part0, sectors, op); + return __part_start_io_acct(disk->part0, sectors, op, jiffies); } EXPORT_SYMBOL(disk_start_io_acct); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 9c95df26fc26..f35aea98bc35 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1258,6 +1258,7 @@ unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, void disk_end_io_acct(struct gendisk *disk, unsigned int op, unsigned long start_time); +void bio_start_io_acct_time(struct bio *bio, unsigned long start_time); unsigned long bio_start_io_acct(struct bio *bio); void bio_end_io_acct_remapped(struct bio *bio, unsigned long start_time, struct block_device *orig_bdev); From patchwork Fri Jan 28 15:58:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 12728691 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 66750C4332F for ; Fri, 28 Jan 2022 15:59:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349817AbiA1P65 (ORCPT ); Fri, 28 Jan 2022 10:58:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46746 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349786AbiA1P6s (ORCPT ); Fri, 28 Jan 2022 10:58:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643385528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=tQTNouHLD2pqrJUsY0rGuooqQ0qZGduHNcta+zU07XE=; b=FZtUa77uXrV0INRVKWvDwSVylDmoAcFP8Yw4ipfLS9rzHgTjERJnkxa8thVAar1lUJKeSe xYOcJ5HND69Ov5njDk3V5/ah6dx1NG5ZvgimJbNxam3NXPzZjclZHdrIL2W2rzVAXmdEx/ dA8O0EcdOpR3G/kXleYNwFYQc5RGvRo= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-352-RbTfwYyyP5alMs-oWNVrng-1; Fri, 28 Jan 2022 10:58:46 -0500 X-MC-Unique: RbTfwYyyP5alMs-oWNVrng-1 Received: by mail-qt1-f200.google.com with SMTP id c20-20020ac84e14000000b002d198444921so4784285qtw.23 for ; Fri, 28 Jan 2022 07:58:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tQTNouHLD2pqrJUsY0rGuooqQ0qZGduHNcta+zU07XE=; b=GUKw0sypuiCHeof58KAOp2hVVIfZubTyHxG+ciqwtIeuh+RldDNBmggZX/603Ewyd8 TB/qaEgsitLBshxvpX+J3IqcCBel5q2gzsON3xsdJxiIHuCuO8KsPTV/Q1lDCREU+AOQ /1Z+M+na7TeQNSAYkmgMuOwyjGo6ReiDgAvUmjg0vOEC4mTqQTfBTjbT3g5JIeSLjvte LvBpeVMXga9PpvBU2koCjLGFIXCuOtFQHA2lUf5FEobuq/ulyOvmMxnA17tibqrUPo0f AjAvvmmeKjXjvbrtuZIY+V4gsCLz7GwZA6yOp4+JDYsWo4fxZG6/MnyGtv+a7PjiaKnq dOdQ== X-Gm-Message-State: AOAM5311+Bk/IyDKn1Y7L7QVK4dz+E4esGPjCAdvEfqu8Vc2A0bIEmN4 f4kZdULr8x2PoMlGt/sP+fRotxroUGiqPNk+2JmekUylN3Ewn3BkgYkHIsfQo1b6ZoTxu3ylhD7 Cyu5XB3f9MxSHGxK2+gQ/eA== X-Received: by 2002:a05:622a:1c3:: with SMTP id t3mr6038271qtw.351.1643385525968; Fri, 28 Jan 2022 07:58:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNHfNKSXr+1lep/iO1OnUsy2vGC9QMAcEvKoGaf9wMxmW0wA7F9StMPgHCj0D2VwKmmzABRA== X-Received: by 2002:a05:622a:1c3:: with SMTP id t3mr6038262qtw.351.1643385525788; Fri, 28 Jan 2022 07:58:45 -0800 (PST) Received: from localhost (pool-68-160-176-52.bstnma.fios.verizon.net. [68.160.176.52]) by smtp.gmail.com with ESMTPSA id w20sm3650313qkp.102.2022.01.28.07.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jan 2022 07:58:45 -0800 (PST) From: Mike Snitzer To: axboe@kernel.dk Cc: hch@lst.de, dm-devel@redhat.com, linux-block@vger.kernel.org Subject: [PATCH v4 2/3] dm: revert partial fix for redundant bio-based IO accounting Date: Fri, 28 Jan 2022 10:58:40 -0500 Message-Id: <20220128155841.39644-3-snitzer@redhat.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20220128155841.39644-1-snitzer@redhat.com> References: <20220128155841.39644-1-snitzer@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Reverts a1e1cb72d9649 ("dm: fix redundant IO accounting for bios that need splitting") because it was too narrow in scope (only addressed redundant 'sectors[]' accounting and not ios, nsecs[], etc). Cc: stable@vger.kernel.org Signed-off-by: Mike Snitzer --- drivers/md/dm.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index c0ae8087c602..9849114b3c08 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1442,9 +1442,6 @@ static void init_clone_info(struct clone_info *ci, struct mapped_device *md, ci->sector = bio->bi_iter.bi_sector; } -#define __dm_part_stat_sub(part, field, subnd) \ - (part_stat_get(part, field) -= (subnd)) - /* * Entry point to split a bio into clones and submit them to the targets. */ @@ -1480,18 +1477,6 @@ static void __split_and_process_bio(struct mapped_device *md, GFP_NOIO, &md->queue->bio_split); ci.io->orig_bio = b; - /* - * Adjust IO stats for each split, otherwise upon queue - * reentry there will be redundant IO accounting. - * NOTE: this is a stop-gap fix, a proper fix involves - * significant refactoring of DM core's bio splitting - * (by eliminating DM's splitting and just using bio_split) - */ - part_stat_lock(); - __dm_part_stat_sub(dm_disk(md)->part0, - sectors[op_stat_group(bio_op(bio))], ci.sector_count); - part_stat_unlock(); - bio_chain(b, bio); trace_block_split(b, bio->bi_iter.bi_sector); submit_bio_noacct(bio); From patchwork Fri Jan 28 15:58:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 12728692 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 C8EAFC4167D for ; Fri, 28 Jan 2022 15:59:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349828AbiA1P7B (ORCPT ); Fri, 28 Jan 2022 10:59:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35178 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349795AbiA1P6u (ORCPT ); Fri, 28 Jan 2022 10:58:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643385529; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=c3s11MYpaHLkMPB6MRaVylhz5gNk+Yl6C2qy7I40rZo=; b=WZSwZ1AMD8jyZfhdrCSDDw58m/jIAfBSzrde0okAxb26NdYtNsaynVyIwNS3+cdep+ffQ3 ejXyyE7x8iTROujlpaMazZNmwOW+I2UOsOTj+yMSUNVP8lp11WiuiTTnZLGt+Sj43C7FpX LEWhyETbhaYC55UsH7ju6vsPlmYVOWA= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-358-muXGK68SMAShArU2ulTiww-1; Fri, 28 Jan 2022 10:58:48 -0500 X-MC-Unique: muXGK68SMAShArU2ulTiww-1 Received: by mail-qt1-f197.google.com with SMTP id y22-20020ac87c96000000b002d1bfdbd86dso4792920qtv.20 for ; Fri, 28 Jan 2022 07:58:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=c3s11MYpaHLkMPB6MRaVylhz5gNk+Yl6C2qy7I40rZo=; b=acbDsb68BVvq0/zX13NQyAXIo37xmBFvK02bFDPlYN04pdroSkKD35aoI61jMUGgvd yUpbSK6CWmy+CujT6pSir3zb3o0XOQorms40t4/itGmjv5PfKZje7Aijf5WutFAw9rVP pL8nrMrOW3ZvbVFHL3jDUVfQk5tOb2hfP6yMHh2kfwQ7bMxWqf/l51s5JYb7HX0qqkmZ FnAckJmEmeRk5Xrq2UmTcJudtTI+/LYYn2gnR+qB/4vmjTxkd+/5xnTidCZC9LM8/7ls jFc8l3g4KrlxvnQ/TDF6FmlC3SaaWnUHTquX3Dqf18VpAd7biieUCizbWIKwRxxHn9vU ZnoQ== X-Gm-Message-State: AOAM531PXIcqlLYr1/pponggpYZnqPcZBOvSqpBTlhUVsK6vp/dFu8x+ 0ipmTY+15EFSHJjJQuDIvAvzppKAhvd2h+r7qCky+gmTngfboe16Fsc1ZZarS0W7J66XJXf4WMX uZf9hUzSvPBB9Hkxa1iiCmA== X-Received: by 2002:ad4:5c4f:: with SMTP id a15mr7612218qva.37.1643385527769; Fri, 28 Jan 2022 07:58:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJyicgWAEB6ayWqMlLhzSn7kxy+IJwfePHjuqVVRWhOwQ3qf8gee6U9e8wmQ3bOt09J6PLJR5w== X-Received: by 2002:ad4:5c4f:: with SMTP id a15mr7612210qva.37.1643385527577; Fri, 28 Jan 2022 07:58:47 -0800 (PST) Received: from localhost (pool-68-160-176-52.bstnma.fios.verizon.net. [68.160.176.52]) by smtp.gmail.com with ESMTPSA id l11sm3665173qkp.86.2022.01.28.07.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jan 2022 07:58:47 -0800 (PST) From: Mike Snitzer To: axboe@kernel.dk Cc: hch@lst.de, dm-devel@redhat.com, linux-block@vger.kernel.org Subject: [PATCH v4 3/3] dm: properly fix redundant bio-based IO accounting Date: Fri, 28 Jan 2022 10:58:41 -0500 Message-Id: <20220128155841.39644-4-snitzer@redhat.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20220128155841.39644-1-snitzer@redhat.com> References: <20220128155841.39644-1-snitzer@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Record the start_time for a bio but defer the starting block core's IO accounting until after IO is submitted using bio_start_io_acct_time(). This approach avoids the need to mess around with any of the individual IO stats in response to a bio_split() that follows bio submission. Reported-by: Bud Brown Reviewed-by: Christoph Hellwig Cc: stable@vger.kernel.org Depends-on: 1073e8492f88 ("block: add bio_start_io_acct_time() to control start_time") Signed-off-by: Mike Snitzer --- drivers/md/dm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 9849114b3c08..dcbd6d201619 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -489,7 +489,7 @@ static void start_io_acct(struct dm_io *io) struct mapped_device *md = io->md; struct bio *bio = io->orig_bio; - io->start_time = bio_start_io_acct(bio); + bio_start_io_acct_time(bio, io->start_time); if (unlikely(dm_stats_used(&md->stats))) dm_stats_account_io(&md->stats, bio_data_dir(bio), bio->bi_iter.bi_sector, bio_sectors(bio), @@ -535,7 +535,7 @@ static struct dm_io *alloc_io(struct mapped_device *md, struct bio *bio) io->md = md; spin_lock_init(&io->endio_lock); - start_io_acct(io); + io->start_time = jiffies; return io; } @@ -1482,6 +1482,7 @@ static void __split_and_process_bio(struct mapped_device *md, submit_bio_noacct(bio); } } + start_io_acct(ci.io); /* drop the extra reference count */ dm_io_dec_pending(ci.io, errno_to_blk_status(error));