From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.1 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795095149; b=y16YLEcMry3/MiMSSJ3RUbC5/4dwsiEmRCVROtdaMbMlxRW2pBJAX4uJrhahLNdv+GZV M+B8oNrZhNIUBM5N+w7MOQFyR7BumR2Ev8te4HXcDT4lub0llRs85XpnqRSMUwoVY8z5Q NmO7tKYZ8MvZ9RwbXMjXBV29zIuW1O8R2A2lH6QmB4KIGU38g4U6WebuRuBznNiUHukYw vcRAb0iYrHlFQcM91d96gcMjBc6OML86Dn4U4PHw7enrNnbyrLa7POhH2o8R40SpN32H/ rhCwjLjC2LGDHxXLKkw8+AaTh9SakoXv1d12Mn6vdzW8G+w21FL+v1XyOcj/PTRuLNg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795095149; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Cc:Subject:To:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=DFGwrWnQzQE9vrv+H5LZUuHjjQZ6GD2VUNZG8z2Jp0U=; b=UT5tyMKVVT0D808c5FfGaNb7w/GU2Hgkm2PGuTLcSqwjsO1TMJzxPmFA9Oo0YRqmCqXF hgjlGYhUsFWssWce66IZvSXn+mB3Ihh2Lo22nTHzrT8G5K+kAYC2esWe5DLjFjXmayp3J 9Ko1/EiolsWRjbjHKAcfBavCf55AV2EBMSR35J+AEZhMaHiryvZA/e4lIDC2vTSXALVXb biHMAxrDyQQEd1+wRZFyCEjqT1dHv6f4JePcdDopi1qPfYiXJ5AJsphoVfPWWzcQBB8J4 1HHJFLndHbrUKSdZyjAD5T9VfAa+Z/1s4i0m0zkOg88/G2X0V2L3cSokxnAMljR/8KA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="ikwNoX/t"; arc=none smtp.remote-ip=91.218.175.1 Received: from mta0.migadu.com (out-1.mta0.migadu.com [91.218.175.1]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11E93606A324 for ; Thu, 19 Nov 2026 13:32:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 11E93606A324 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=ikwNoX/t X-Envelope-To: linux-block@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=ej+6o0oNAldcqtoAyXKCxBACNOZThX+3FaNstOHMsDc=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795095146; v=1; x=1795699946; b=ikwNoX/tWQvvagvIqbXZsFNyApMmdNwrdTic/wQpreajoy5KQWJiS+DCYX7xA15XPzsmT0gg QGgjxglFlRDpKXIhgJCSULHUy4pv2hclysBxMhhJJlxkAl+yNK+V2kqy2+vn1fK0zuZAYN/7G5N h6zCDl64gwnzB+piSqpx3gOY= X-Envelope-To: linux-block@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 2c3cd21c1ab6c765; Thu, 19 Nov 2026 13:32:25 +0000 X-Mizu-Trace-ID: 2c3cd21c1ab6c765 X-Migadu-Flow: FLOW_OUT Message-ID: Date: Thu, 19 Nov 2026 21:32:12 +0800 X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: cui.tao@linux.dev, linux-block@vger.kernel.org Subject: Re: [PATCH 5/7] blk-stat: account for the mean of the source in blk_rq_stat_sum() To: Guixin Liu , Jens Axboe , Christoph Hellwig , Tejun Heo , Josef Bacik , Nilay Shroff , Ming Lei , Hannes Reinecke , Tang Yizhou References: <20261119070548.3125491-1-kanie@linux.alibaba.com> <20261119070548.3125491-6-kanie@linux.alibaba.com> From: Tao Cui In-Reply-To: <20261119070548.3125491-6-kanie@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hello, Guixin, 在 2026/11/19 15:05, Guixin Liu 写道: > blk_rq_stat_sum() folds a src into a dst by combining dst->mean with > src->batch only, so it is only correct while src has never been folded > itself: its mean is then either zero or stale. blk-iolatency folds the > per-cpu stats into a window-local stat first and then folds that result > into iolat->cur_stat, so the second fold drops the whole window and > cur_stat.rqs.mean stays at zero. On rotating disks, where the mean > decides whether the accumulated window meets the latency target, > iolatency_check_latencies() therefore always considers the accumulated > window OK and scales up more aggressively than intended. > > Fold src->mean * src->nr_samples into the result as well. The per-cpu > users keep their mean at zero through blk_rq_stat_init(), so their > behavior is unchanged. > I posted a fix for the same issue before, which Tang Yizhou reviewed: https://lore.kernel.org/all/20260904065426.1281914-1-cui.tao@linux.dev/ Adding him here to take a look at your approach as well. Hope the link helps. Thanks, Tao > Fixes: 451bb7c33197 ("blk-iolatency: keep track of previous windows stats") > Cc: stable@vger.kernel.org > Signed-off-by: Guixin Liu > --- > block/blk-stat.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/block/blk-stat.c b/block/blk-stat.c > index d57c2fc6bf06..6345ae366658 100644 > --- a/block/blk-stat.c > +++ b/block/blk-stat.c > @@ -24,7 +24,10 @@ void blk_rq_stat_init(struct blk_rq_stat *stat) > stat->batch = 0; > } > > -/* src is a per-cpu stat, mean isn't initialized */ > +/* > + * The mean of @src must have been calculated or set to zero by > + * blk_rq_stat_init() before calling this. > + */ > void blk_rq_stat_sum(struct blk_rq_stat *dst, struct blk_rq_stat *src) > { > if (dst->nr_samples + src->nr_samples <= dst->nr_samples) > @@ -33,7 +36,8 @@ void blk_rq_stat_sum(struct blk_rq_stat *dst, struct blk_rq_stat *src) > dst->min = min(dst->min, src->min); > dst->max = max(dst->max, src->max); > > - dst->mean = div_u64(src->batch + dst->mean * dst->nr_samples, > + dst->mean = div_u64(dst->mean * dst->nr_samples + > + src->mean * src->nr_samples + src->batch, > dst->nr_samples + src->nr_samples); > > dst->nr_samples += src->nr_samples;