Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp321256ybg; Tue, 9 Jun 2020 01:11:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1FVikVJ1UIpdsd3Mfasft0vCMw9G0D7iLu8wGnBc/qG7jewVuGisA9c3jooH4Y5Q+e5Vc X-Received: by 2002:a17:906:6888:: with SMTP id n8mr23776924ejr.526.1591690263898; Tue, 09 Jun 2020 01:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591690263; cv=none; d=google.com; s=arc-20160816; b=v94Qx8uxSwPe4FPmHlSnLewKD3UwjX0zU8xI4oqTQX+IFlC74XgexAd3Q9+DpyJh3z wNl4oVcORzWBaoSaGtv4hwsh/Wwvc4Fpz3o838375fW7SC1cB2drUcWDBvsoNtYGb4t4 ooKsjkimW7rS0wzPQh/hyEzMl+UVmEhIkR8kSFRhGWrl2d8Hf8mZvtCMzzN5hMIC6hkc Mg0EKv8E8kxybR1hLoFtZDXefNBTjim+WXuCeuEZKq6QrRBG1i/nmgLxDZvM2v68dsLd W+LAkAdxFrWXVeSgi8voQFpwN1alfBlpywmByXzr5csOVpBioIT7cx5q8uTtdXuDZBof HJkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=7ahInagcs9feFsW/SRSfMWTw6AkLwWZT798daR2SDEg=; b=0GTHHMnUCI18UjkGHyxLS8nbhNef9e9sBXVNqPrbZfyNRyV379BzUUYFvM6nwkJktw mB7MABg6ClLB3dB+gWRp1iLgavfY4wZNiaMQ5dA8Lr/FpncZg8nCFBOtmBGXpshNi8Cq ODTF93gWUWSB50mB5OGQJIt9iTDqcEtHMqkXXFZptGRpFtbIPmqeAPBSJZWoKxcviNnT Kxe81KeIpJx03WlGf/9rmT1c3kCueBpe2JodYZKLvIMl+9bLzdW0rtopYWkA7RApXD88 V0noiApzD/cqMvEsj+B24F85QhfbADzmtGyUoW2rzs5eWKTMvFGDEGZ87CWyf09IVqXB oZBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Re3yPg4w; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si1780925edr.276.2020.06.09.01.10.41; Tue, 09 Jun 2020 01:11:03 -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=@redhat.com header.s=mimecast20190719 header.b=Re3yPg4w; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728161AbgFIIIl (ORCPT + 99 others); Tue, 9 Jun 2020 04:08:41 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:29845 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728149AbgFIIIj (ORCPT ); Tue, 9 Jun 2020 04:08:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591690118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7ahInagcs9feFsW/SRSfMWTw6AkLwWZT798daR2SDEg=; b=Re3yPg4wHBDSDTEex5WcUGI39/bdKrQH1dGuqe33yOfrQ9llfjy/srMeA0aH/Sh7duUjLs XEWSCUQdu5wVIm2rRwgaNboTxjJCjHVBsVLA6PpN5h5sZu7Zj4Qzyu6rPVd6rOCQGek3Br 8ZULgbZlVGup2QaEQsGnvR7kJbAM5Wo= 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-490-s5cgG3OxMeW2xbgVBgR6Cw-1; Tue, 09 Jun 2020 04:08:35 -0400 X-MC-Unique: s5cgG3OxMeW2xbgVBgR6Cw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B69B6108BD0A; Tue, 9 Jun 2020 08:08:33 +0000 (UTC) Received: from T590 (ovpn-13-202.pek2.redhat.com [10.72.13.202]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8EF6090320; Tue, 9 Jun 2020 08:08:13 +0000 (UTC) Date: Tue, 9 Jun 2020 16:08:08 +0800 From: Ming Lei To: Josh Snyder Cc: Jens Axboe , Mikulas Patocka , Mike Snitzer , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Josh Snyder Subject: Re: [RFC 1/2] Eliminate over- and under-counting of io_ticks Message-ID: <20200609080808.GA270404@T590> References: <20200609040724.448519-1-joshs@netflix.com> <20200609040724.448519-2-joshs@netflix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200609040724.448519-2-joshs@netflix.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 08, 2020 at 09:07:23PM -0700, Josh Snyder wrote: > Previously, io_ticks could be under-counted. Consider these I/Os along > the time axis (in jiffies): > > t 012345678 > io1 |----| > io2 |---| In current way, when io2 is done, io tickes should be 5, since 1 tick is added for two io start. > > Under the old approach, io_ticks would count up to 6, like so: > > t 012345678 > io1 |----| > io2 |---| > stamp 0 45 8 > io_ticks 1 23 6 Before commit 5b18b5a73760("block: delete part_round_stats and switch to less precise counting"), io tick is calculated accurately, which is basically: (4 - 0) + (5 - 4) + (8 - 5) = 8 > > With this change, io_ticks instead counts to 8, eliminating the > under-counting: > > t 012345678 > io1 |----| > io2 |---| > stamp 0 5 8 > io_ticks 0 5 8 > > It was also possible for io_ticks to be over-counted. Consider a > workload that issues I/Os deterministically at intervals of 8ms (125Hz). > If each I/O takes 1ms, then the true utilization is 12.5%. The previous > implementation will increment io_ticks once for each jiffy in which an > I/O ends. Since the workload issues an I/O reliably for each jiffy, the > reported utilization will be 100%. This commit changes the approach such > that only I/Os which cross a boundary between jiffies are counted. With > this change, the given workload would count an I/O tick on every eighth > jiffy, resulting in a (correct) calculated utilization of 12.5%. > > Signed-off-by: Josh Snyder > Fixes: 5b18b5a73760 ("block: delete part_round_stats and switch to less precise counting") > --- > block/blk-core.c | 20 +++++++++++++------- > 1 file changed, 13 insertions(+), 7 deletions(-) > > diff --git a/block/blk-core.c b/block/blk-core.c > index d1b79dfe9540..a0bbd9e099b9 100644 > --- a/block/blk-core.c > +++ b/block/blk-core.c > @@ -1396,14 +1396,22 @@ unsigned int blk_rq_err_bytes(const struct request *rq) > } > EXPORT_SYMBOL_GPL(blk_rq_err_bytes); > > -static void update_io_ticks(struct hd_struct *part, unsigned long now, bool end) > +static void update_io_ticks(struct hd_struct *part, unsigned long now, unsigned long start) > { > unsigned long stamp; > + unsigned long elapsed; > again: > stamp = READ_ONCE(part->stamp); > if (unlikely(stamp != now)) { > - if (likely(cmpxchg(&part->stamp, stamp, now) == stamp)) > - __part_stat_add(part, io_ticks, end ? now - stamp : 1); > + if (likely(cmpxchg(&part->stamp, stamp, now) == stamp)) { > + // stamp denotes the last IO to finish > + // If this IO started before stamp, then there was overlap between this IO > + // and that one. We increment only by the non-overlap time. > + // If not, there was no overlap and we increment by our own time, > + // disregarding stamp. Linux kernel's comment style is '/**/' > + elapsed = now - (start < stamp ? stamp : start); > + __part_stat_add(part, io_ticks, elapsed); Looks this way of only sampling IO done is smart, io ticks becomes much more accurate than before. > + } > } > if (part->partno) { > part = &part_to_disk(part)->part0; > @@ -1439,7 +1447,7 @@ void blk_account_io_done(struct request *req, u64 now) > part_stat_lock(); > part = req->part; > > - update_io_ticks(part, jiffies, true); > + update_io_ticks(part, jiffies, nsecs_to_jiffies(req->start_time_ns)); jiffies and req->start_time_ns may be from different clock sources, so I'd suggest to merge the two patches into one. Thanks, Ming