From patchwork Fri Jan 28 04:17:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 12727911 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 B3BF9C433FE for ; Fri, 28 Jan 2022 04:17:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345964AbiA1ER6 (ORCPT ); Thu, 27 Jan 2022 23:17:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:42121 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236875AbiA1ER6 (ORCPT ); Thu, 27 Jan 2022 23:17:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643343477; 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=LPT/xXbA8dMnjNDPrd3foEhpTUzqW1ZlXYJLQcHQMDc=; b=IWw27skig7vTTsjsuyw07AtIx+PfRVzbIs8XXmObRMqgNE0tV5hPMXnQ0CpjPC8ynUH+Z6 Gas4EEked27Nh9T344WqIanyc/zXHyFNZ+ufELx72QU5eOXC+B2WR607C76GtYZQl2RoNC iiKL86vFfb07hbaXSQC+vJn63nzdNes= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-347-PQGmj2gNOXi3vL-ZsY_BCg-1; Thu, 27 Jan 2022 23:17:56 -0500 X-MC-Unique: PQGmj2gNOXi3vL-ZsY_BCg-1 Received: by mail-qv1-f70.google.com with SMTP id u15-20020a0cec8f000000b00425d89d8be0so2586640qvo.20 for ; Thu, 27 Jan 2022 20:17:56 -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=LPT/xXbA8dMnjNDPrd3foEhpTUzqW1ZlXYJLQcHQMDc=; b=x9/YsV6c/1Z+2a4XM4Tl/Di9lRCKr7/NWqY90tWlUUx4N4TtmORNDA6UvYQ0ICHnQE OIqXcmp/1lmERbhorUTCDpEfw6I/v/dTTh5Zkx+odli/XRNfoN2BiVpZiP0jYx3phNfP KPLI8WCGpBQ+ngu+tqiepdzMXipEqqak6upAR6IJmLaYNgfap7V5Ho89sQGryaGkgjc3 xYr4tILWfTeTVj0jha3YQrdx78p0OuLoB/vvikoPPnT73ClfXS5f8Y5mEabY+AZvOBHe FRBdkVLFmnVAOw6701bGS+t1NRoJIJ2fPVWvphEPyS7VPz0Bkw+5Ys34SQ8q0oqHyhc4 irEA== X-Gm-Message-State: AOAM5338JadSw9R8KXmurEM1jsDw+ZXRzeN9Eb1PXjkMmmtp2/oo+zia mxrh8vG4IuaTeY5VS3C9fZrIIcv9YEMZjoN5TFKYP1QAcigdv17y8khrvJcp1MzA2Tmzuf6ZfpL U1TXIbs+GcLUqdgYJgZITJw== X-Received: by 2002:a05:622a:2ca:: with SMTP id a10mr2856217qtx.298.1643343475936; Thu, 27 Jan 2022 20:17:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJz5RF7BzncHiFMVWiTMxZmqy6R9FtGtyMp3kV52MUk+7hmiCaTdZrq/spDha5BE/Q8LIfYHBA== X-Received: by 2002:a05:622a:2ca:: with SMTP id a10mr2856214qtx.298.1643343475751; Thu, 27 Jan 2022 20:17:55 -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 d13sm2318189qtx.35.2022.01.27.20.17.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 20:17:55 -0800 (PST) From: Mike Snitzer To: axboe@kernel.dk Cc: hch@lst.de, dm-devel@redhat.com, linux-block@vger.kernel.org Subject: [PATCH v3 1/3] block: add bio_start_io_acct_time() to control start_time Date: Thu, 27 Jan 2022 23:17:51 -0500 Message-Id: <20220128041753.32195-2-snitzer@redhat.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20220128041753.32195-1-snitzer@redhat.com> References: <20220128041753.32195-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). Signed-off-by: Mike Snitzer Reviewed-by: Christoph Hellwig --- 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 04:17:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 12727912 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 15F3CC433EF for ; Fri, 28 Jan 2022 04:18:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345966AbiA1ESA (ORCPT ); Thu, 27 Jan 2022 23:18:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55512 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236875AbiA1ER7 (ORCPT ); Thu, 27 Jan 2022 23:17:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643343479; 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=ihfiXyDRszgTqM/vMjBa+fUrUfekzTmJn30V/35pSu9CJu9SapQ7zLcYhhHWPJ0OkPmO+s bsE5QdYFMB7RjGyXJkHdryXhjW4FSxcjFmodWHPeluhHQv05gTUgBaztcWKb8RoxxQgBHH Wu+fkJ/S+PrT6cRVlwPN1TcHNa83a+A= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-70-6BIVMDstMYaCcZRfQPhxlA-1; Thu, 27 Jan 2022 23:17:58 -0500 X-MC-Unique: 6BIVMDstMYaCcZRfQPhxlA-1 Received: by mail-qk1-f197.google.com with SMTP id l23-20020a37f517000000b0049b8b31c76cso4008162qkk.4 for ; Thu, 27 Jan 2022 20:17:58 -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=l0hGCor+FjbyJPTk263r9XKzRfny/a5KJVBetTN4d1JZ9ZKE8JMCALYyX8ckrLPx/0 XxkvFUObHbNDQiXB0SfHv3EKpabiuwZl1ZkskOf2JbB+MvLJ45zDIx247yuOFLS/baeT Bq0gzwgE4/1j3jRU2tuot+utBiBkajtCaeP+Qr9Go6lEmfbE4UEOmjSajtRNHPz/LjHl sv/D2wqocqEXgpJFX2ILfs/1zP6VSIjTCSsvdn6GQVzyVKbfizH7sKODKl+onlvWRpBV /89h+bF24oYvotF4skibH24Yzv9RMc5VdePjb9o65Nfze62le5UK03ifG+uoksi2OU3b B+bw== X-Gm-Message-State: AOAM533yHX0S6eFJO4+R9aFK1v93Cu+Dxfe97XUSTjv+PXgBLrkLgwfz LMHjvlQ7LdnYM3fDvRezHFY3soCF+89E0sv7RjixPUnvzK7LUvjDYUMXpzMm/sNe1WV2c5musyZ jYgQF40+QUCjR7vbk9fF9aA== X-Received: by 2002:ac8:7d0a:: with SMTP id g10mr4992286qtb.449.1643343477327; Thu, 27 Jan 2022 20:17:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzUbkSikg1u7V0kLUzFH1wyiqaoX9jOQQFHcVBPR42iTH4UoZhdUYJg81QtQgJlbjB1W2H6Q== X-Received: by 2002:ac8:7d0a:: with SMTP id g10mr4992279qtb.449.1643343477149; Thu, 27 Jan 2022 20:17:57 -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 o19sm2353114qta.40.2022.01.27.20.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 20:17:56 -0800 (PST) From: Mike Snitzer To: axboe@kernel.dk Cc: hch@lst.de, dm-devel@redhat.com, linux-block@vger.kernel.org Subject: [PATCH v3 2/3] dm: revert partial fix for redundant bio-based IO accounting Date: Thu, 27 Jan 2022 23:17:52 -0500 Message-Id: <20220128041753.32195-3-snitzer@redhat.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20220128041753.32195-1-snitzer@redhat.com> References: <20220128041753.32195-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 04:17:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 12727913 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 B0EB6C433F5 for ; Fri, 28 Jan 2022 04:18:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345959AbiA1ESC (ORCPT ); Thu, 27 Jan 2022 23:18:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21799 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236875AbiA1ESB (ORCPT ); Thu, 27 Jan 2022 23:18:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643343481; 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=1Bf1EUJyPBU3hvoZbXvQhOBhlizP0JEsfYBCXPFM+6E=; b=GQwOWeAaHvWDNkPm21HhRPjCbRrp16YIHb59CgMt3zd6VYwxr4x6wcq3rq1WN6a36n8v5F gF2VxcEP8c+72nvIRwAozbyp3K9Sg8uxVVTDNiZbWdalORXOpc5CqzywC12n2w0b8B88Oc x74VPRRAdkhA+hyXbX1KZhdICyk9obU= 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-478-vAOjgSBvPB22UCHhqMXVoQ-1; Thu, 27 Jan 2022 23:17:59 -0500 X-MC-Unique: vAOjgSBvPB22UCHhqMXVoQ-1 Received: by mail-qt1-f199.google.com with SMTP id b7-20020ac85bc7000000b002b65aee118bso3702182qtb.13 for ; Thu, 27 Jan 2022 20:17:59 -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=1Bf1EUJyPBU3hvoZbXvQhOBhlizP0JEsfYBCXPFM+6E=; b=2y48mDSDxRNotL8jsH5hGCSSSTnmrzp7REqPTA+BbPAtGzo5Vs3Qib7Jq+bACpOmDW WeHUeDS+yPBU5kTUkFg8SJd6JkYzMjZRl7VFmDhN2uxGB45iTikxQWObOK7AWlQo4A1D OWKE2SUlRauk50J/nG6oIzasgR078LuAyw3BtgR/x/khpL6GOLeRH6na+t7suLa9RZQq Hmk6DfWMbqdjzS2Ik4hBMy7i4evVuPagP+PuMGUH5c3j/Fjz5egit5m/v3/EgEg7NhbU IW/zirJ/h+gSo83tXZFbjdNzz5xKvftvox+mWjy8NeAHtOaNfskalVcGeFWn2EM3cmNe cVZQ== X-Gm-Message-State: AOAM532FrfSKVwwzX9C1BukiZDa5S87UdOMqWmBCpljhH1J71IJfWcuU QWJ4VPTNDG1bIvRGcgZICqFSyJvC0UViG2anUKFEcA/JbKKb10kApZwtAT77nP+/bWChuDRc3Fo tkRYcdmXJY6SyKrR5mwGiBg== X-Received: by 2002:a05:622a:1109:: with SMTP id e9mr4938778qty.668.1643343479100; Thu, 27 Jan 2022 20:17:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjblMjZCrb4E1TKOCdtECb10lLL2MgcX9OKfcprTLIoUEorrr6OxHrIKHsSSiLf39WEBf2SQ== X-Received: by 2002:a05:622a:1109:: with SMTP id e9mr4938772qty.668.1643343478907; Thu, 27 Jan 2022 20:17:58 -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 u9sm2578258qkp.37.2022.01.27.20.17.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 20:17:58 -0800 (PST) From: Mike Snitzer To: axboe@kernel.dk Cc: hch@lst.de, dm-devel@redhat.com, linux-block@vger.kernel.org Subject: [PATCH v3 3/3] dm: properly fix redundant bio-based IO accounting Date: Thu, 27 Jan 2022 23:17:53 -0500 Message-Id: <20220128041753.32195-4-snitzer@redhat.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20220128041753.32195-1-snitzer@redhat.com> References: <20220128041753.32195-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 Cc: stable@vger.kernel.org Depends-on: f9893e1da2e3 ("block: add bio_start_io_acct_time() to control start_time") Signed-off-by: Mike Snitzer Reviewed-by: Christoph Hellwig --- 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..144436301a57 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 = READ_ONCE(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));