Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp1026085ybs; Mon, 25 May 2020 05:31:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfXOC09FfAw9TOUy82HZu1ILCiqznYTRv4trZR2Y1soldbVWYd78onXjqSd0YjQl+7UkEU X-Received: by 2002:a05:6402:1ca6:: with SMTP id cz6mr5715256edb.381.1590409870371; Mon, 25 May 2020 05:31:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590409870; cv=none; d=google.com; s=arc-20160816; b=C+MleUdN+Ia8skb2XXLpKaYyj5z6zgx5JrXUqg/seUdv0tiBcDIh5w4JYHsy1O0V6u mEAM3yio8mLWNiIeespjt45iqIS5acaWu91fBAGioV7M0LKAKyRF/LFaINMyibc7LQRL 7+Gv84AdV0zCZdeQe+U1xacVe2Gu2rkzt4X6nHT5+8TTlZzzvbhITw5fG5yj89GfAZNa r3AS2xCsNiX8HROKNBOvdKzM/R4aVBG8GtD4YUnQmZa1O74pzBqew4e8e8XAUfa/EsKt zhpRZw00z+tnlW5yyJRH2s9BH2BJyspQAEl8hnQJNPs/WXqoTmfkQNd26jrD+lnWcweT XeIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=YEG4z8qEcvv8kNO2YGjz6EufWfplHbPF3VC80TUbdQE=; b=JissNkwdSo/pTnODJzW9VcyHV3e5vtuUAc3D88m4dDqqoh2+ZeML9nQT44m+bpXQLQ /pjiIs/kuYLdoiNumXPexnY5Zc3Y4PEE9n+zHzRPCGiHXW8/a8I2QwGxSF9MPos8d1DI 5p10udnT5G5fo03LJ2FT5t4E+1FdYmm41sHkXosGlf6YYwXRCJhV00a5RscOLR1e6X/I z0SRh813YZZpByVHpV35WZarjWOmao6sK2+CO6LeLqyhbr2QIWn+lAl3DBaslOZWmfDn rxBgDJuvsGbCqH+y6a5xc1cXBilikeLacB/pG1DNHpMo+Ul11jji+8OW0qy6UqmvEl2u oHBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=bl+2kqRC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hb15si9581251ejb.451.2020.05.25.05.30.46; Mon, 25 May 2020 05:31:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=bl+2kqRC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390590AbgEYM2P (ORCPT + 99 others); Mon, 25 May 2020 08:28:15 -0400 Received: from forwardcorp1j.mail.yandex.net ([5.45.199.163]:43432 "EHLO forwardcorp1j.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390500AbgEYM2N (ORCPT ); Mon, 25 May 2020 08:28:13 -0400 Received: from mxbackcorp1j.mail.yandex.net (mxbackcorp1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::162]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 9EE2C2E1382; Mon, 25 May 2020 15:28:09 +0300 (MSK) Received: from vla1-81430ab5870b.qloud-c.yandex.net (vla1-81430ab5870b.qloud-c.yandex.net [2a02:6b8:c0d:35a1:0:640:8143:ab5]) by mxbackcorp1j.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id DQMsTfsjhQ-S7TS4oeT; Mon, 25 May 2020 15:28:09 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1590409689; bh=YEG4z8qEcvv8kNO2YGjz6EufWfplHbPF3VC80TUbdQE=; h=In-Reply-To:Message-ID:From:Date:References:To:Subject:Cc; b=bl+2kqRCQsVFwc9oTK+K5T3oNcaVdrBTh8bHsU39tv2jjpDgfTTU+DaYxax9ko5mr GkBjjARumtZaYQY+WluCS9B++huWYaI+1Kc/c/bUZQJoKuhSB7l6BMJKR9h9hxWZez IRPdeajMC85tfdsFdxT0QjpQeA4oHy6Rq/6jCKlc= Authentication-Results: mxbackcorp1j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:603::1:c]) by vla1-81430ab5870b.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 2d5hQC4EbC-S7Xq4M1X; Mon, 25 May 2020 15:28:07 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Subject: Re: [PATCH 01/16] block: add disk/bio-based accounting helpers To: Christoph Hellwig , Jens Axboe Cc: Minchan Kim , Nitin Gupta , dm-devel@redhat.com, linux-block@vger.kernel.org, drbd-dev@lists.linbit.com, linux-bcache@vger.kernel.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org References: <20200525113014.345997-1-hch@lst.de> <20200525113014.345997-2-hch@lst.de> From: Konstantin Khlebnikov Message-ID: Date: Mon, 25 May 2020 15:28:07 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200525113014.345997-2-hch@lst.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-CA Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25/05/2020 14.29, Christoph Hellwig wrote: > Add two new helpers to simplify I/O accounting for bio based drivers. > Currently these drivers use the generic_start_io_acct and > generic_end_io_acct helpers which have very cumbersome calling > conventions, don't actually return the time they started accounting, > and try to deal with accounting for partitions, which can't happen > for bio based drivers. The new helpers will be used to subsequently > replace uses of the old helpers. > > The main function is the bio based wrappes in blkdev.h, but for zram > which wants to account rw_page based I/O lower level routines are > provided as well. > > Signed-off-by: Christoph Hellwig > --- > block/blk-core.c | 34 ++++++++++++++++++++++++++++++++++ > include/linux/blkdev.h | 26 ++++++++++++++++++++++++++ > 2 files changed, 60 insertions(+) > > diff --git a/block/blk-core.c b/block/blk-core.c > index 77e57c2e8d602..8973104f88d90 100644 > --- a/block/blk-core.c > +++ b/block/blk-core.c > @@ -1432,6 +1432,40 @@ void blk_account_io_start(struct request *rq, bool new_io) > part_stat_unlock(); > } > > +unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, > + unsigned int op) > +{ > + struct hd_struct *part = &disk->part0; > + const int sgrp = op_stat_group(op); > + unsigned long now = READ_ONCE(jiffies); > + > + part_stat_lock(); > + update_io_ticks(part, now, 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; > +} > +EXPORT_SYMBOL(disk_start_io_acct); > + > +void disk_end_io_acct(struct gendisk *disk, unsigned int op, > + unsigned long start_time) > +{ > + struct hd_struct *part = &disk->part0; > + const int sgrp = op_stat_group(op); > + unsigned long now = READ_ONCE(jiffies); > + unsigned long duration = now - start_time; I think it would be better to leave this jiffies legacy nonsense in callers and pass here request duration in nanoseconds. So rewriting them to nanoseconds later wouldn't touch generic code. > + > + part_stat_lock(); > + update_io_ticks(part, now, true); > + part_stat_add(part, nsecs[sgrp], jiffies_to_nsecs(duration)); > + part_stat_local_dec(part, in_flight[op_is_write(op)]); > + part_stat_unlock(); > +} > +EXPORT_SYMBOL(disk_end_io_acct); > + > /* > * Steal bios from a request and add them to a bio list. > * The request must not have been partially completed before. > diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h > index 7d10f4e632325..76d01a8a13b80 100644 > --- a/include/linux/blkdev.h > +++ b/include/linux/blkdev.h > @@ -1892,4 +1892,30 @@ static inline void blk_wake_io_task(struct task_struct *waiter) > wake_up_process(waiter); > } > > +unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, > + unsigned int op); > +void disk_end_io_acct(struct gendisk *disk, unsigned int op, > + unsigned long start_time); > + > +/** > + * bio_start_io_acct - start I/O accounting for bio based drivers > + * @bio: bio to start account for > + * > + * Returns the start time that should be passed back to bio_end_io_acct(). > + */ > +static inline unsigned long bio_start_io_acct(struct bio *bio) > +{ > + return disk_start_io_acct(bio->bi_disk, bio_sectors(bio), bio_op(bio)); > +} > + > +/** > + * bio_end_io_acct - end I/O accounting for bio based drivers > + * @bio: bio to end account for > + * @start: start time returned by bio_start_io_acct() > + */ > +static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time) > +{ > + return disk_end_io_acct(bio->bi_disk, bio_op(bio), start_time); > +} > + > #endif >