From nobody Sun May 24 18:43:17 2026 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD1103603D8 for ; Fri, 22 May 2026 13:14:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779455659; cv=none; b=M4kKGU4PbMdBZzpeEUscEQw8R7zux01vEZBVNLNN+SpYEFnM76s3U0zXI6PilTvgGSvkKBo5rdcOmi9z5Dw9KEmk9kQCVwxl/Dwb6hrsQXBlU1ZIm2iEbrM1djuKi49lgbmohn8bQujkcvgvK1DXf8/YnMKyCdUxsYaiZAtwuZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779455659; c=relaxed/simple; bh=YSAciv9TDQClx2IMLcHJIqG7XiH7Ty8bOhwekIMEN50=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=e7QnViiFZGMhHIrnDEPECZlTL/4eOougZpnRz474ZRUItYrWDhybHwW5hPz8LVVGQFwfybUS0dxvMsIAFcWM2iiD90mmdgGjXW2comHGUU76nvMUXyeD6DoVW7Uxyh3IAWIzMU6VOXgATbsyNBuXGofga8BA6jjAmHqA4B6kinI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=shopee.com; spf=pass smtp.mailfrom=shopee.com; dkim=pass (2048-bit key) header.d=shopee.com header.i=@shopee.com header.b=TtyiNMVu; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=shopee.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shopee.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=shopee.com header.i=@shopee.com header.b="TtyiNMVu" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-839dc688d6cso3285476b3a.2 for ; Fri, 22 May 2026 06:14:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopee.com; s=shopee.com; t=1779455657; x=1780060457; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=5auOG1877ywlMK3+iSMdUow3qmNazPx9wYUImkm+Qrw=; b=TtyiNMVu/Ilxh82WFB/zXNZQOtoZdhSumNqHMKeNlHdkeC/qThEgAkjX3zi2zCqPH3 2eqwG3f3hedF4rmtpLCgIVkwZAyZp29Hi05NeI6ugGdNqkXiAr6ATIUVvRIYLXj+2YDm MklY0lDt0PP321F8gRuli58Znfb3YS31+rbgwgmucN5IsGIjEar5HAdv6KPx6fEzrbZZ HUwHymLaxyKK3/fy5Bo6+m4pJJZU4Dc72yv/f1UTo23VlBzdebqXUUuJmJLXlwZOyECy mSlJ0PdJ+/HgcVfEtgoVswzZB3rBLazJT2beGkx3YkG0WwgVmIjdQoODhh01rjWwh6a8 1UZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779455657; x=1780060457; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5auOG1877ywlMK3+iSMdUow3qmNazPx9wYUImkm+Qrw=; b=W4A9/x3nxqlOYLpuuXP/EfALexRp+zKpnYl3XrW8Imtq3CtjiTQ9ewERyztpnliJU3 RpBwUO7bnf7MsgiHoNY0Zu/rWViyInhCvbm/S3DCqc47lBnfA5KH3SYddylWfaEwIml/ wfbbCekLdeZzo+FA5vhx8vAdow64YeGXVpFVssAwry8x/5nO+fYJgVfiSOxxqE6Mxo8Q OWpZdlx5MotnS485kPWcjhOd7hOswj1mG31lXhmUc5NM3PvtjeLFsO8nbW3k64spSL+S BBChmDrIgYpaaa73EY3MALmjrE5ZJO/2zYbeE9n83aEhkqqZ9/lcE5+JZckDjsYQJ4/E PqEg== X-Forwarded-Encrypted: i=1; AFNElJ9OiyVD/3nzYONxpRZNHtncTNpa4oKsnOgfKRHQ++6J/DaICUQhYZJcr20B0H6i/F578HyljdQ52YkA2zA=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1fKUNet3VTxnEsQZzXT7bF8ao5eJgMikvqLOKOI9DMYEWo8gG gn86IvBg2Cj4XnWdGgE/TuxboMymL+IZ/hQ+Pi1fzJfRrDVw6ryLerAIID1pj/gRw+E= X-Gm-Gg: Acq92OFj/Yp4KqrrXbP1x+UZ5keh1/X3Mh5cy3qUpTzP1l29GSsCskzan5lkP2isSTn AzSXh9YgGWBv/bYgcZbDuqFUKbwagNk1cIgkYqUR34R6um6T5w60BY4YI+cVJNiwdNtqXfT0lzW jYifhIzv5gmmPvBFte8U0f2QO7DdCAFiFcf0FGDHSVHe5mLDn6JOXaOOV0y7u8HX1yGD9tMiGTc GBPehPhsB4+qSSRYhjdYeHqfiHZW6WWXMbyaKOs/XjLr0WdM9BCnUwmCurrHllaRAwVo4uICo9t TwXQBcr/LWV0xBZNxg+c7ytQrTBJ7HaPg409DFlSWZ7Tgbtjpq5HBIKOhXoIhFQGUdbuenZf8vh wswhJOQdsy/hhZu2wZz6HjWciX5goIT16QAtmONpxFOfVaprSTVwMga+2FmHTqY3A0WMtkxxq2u fOYKM5xVu59WPjK9ZATzg= X-Received: by 2002:a05:6a00:e8b:b0:835:cc47:6fe8 with SMTP id d2e1a72fcca58-8415f3bcffamr3913828b3a.46.1779455656963; Fri, 22 May 2026 06:14:16 -0700 (PDT) Received: from localhost.localdomain ([147.136.157.0]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84165009852sm2030340b3a.59.2026.05.22.06.14.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 06:14:16 -0700 (PDT) From: Tang Yizhou X-Google-Original-From: Tang Yizhou To: axboe@kernel.dk, hch@lst.de Cc: yukuai@fnnas.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Tang Yizhou , Leon Hwang Subject: [PATCH v3] block: propagate in_flight to whole disk on partition I/O Date: Fri, 22 May 2026 21:14:09 +0800 Message-ID: <20260522131409.261259-1-yizhou.tang@shopee.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Tang Yizhou Now when I/O is submitted to a partition, the per-CPU in_flight[] counter is incremented only on the partition's block_device, not on the underlying whole disk. This leads to a problem which can be shown by a fio test: lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS mydev 252:1 0 20G 0 disk =E2=94=94=E2=94=80mydev1 259:0 0 10G 0 part iostat -xp 1 Device r/s rkB/s ... aqu-sz %util mydev 128153.00 512612.00 ... 13.22 72.20 mydev1 128154.00 512616.00 ... 13.22 100.00 %util is different between mydev and mydev1, which is unexpected. This is the cumulative effect of a series of patches. The root cause is commit e016b78201a2 ("block: return just one value from part_in_flight"), which deleted the branch in part_in_flight() that aggregated the whole-disk in_flight count on top of the partition's. Then the second commit is commit 10ec5e86f9b8 ("block: merge part_{inc,dev}_in_flight into their only callers"), which folded the whole-disk in_flight accounting into generic_start_io_acct() and generic_end_io_acct(). Those two helpers were then removed by commit e722fff238bb ("block: remove generic_{start,end}_io_acct"), and from that point on the whole disk's in_flight is no longer accounted at all. In update_io_ticks(), if calling bdev_count_inflight() finds that the inflight value of the whole device is 0, the accumulation of io_ticks will be skipped, causing the reported util% value to be underestimated. Fix it by restoring the whole-disk in_flight accounting. Fixes: e016b78201a2 ("block: return just one value from part_in_flight") v2: Update commit message. v3: Take Christoph's advice and factor the common code into two helpers. Suggested-by: Leon Hwang Signed-off-by: Tang Yizhou Reviewed-by: Christoph Hellwig --- block/blk-core.c | 4 ++-- block/blk-mq.c | 5 ++--- block/blk.h | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 17450058ea6d..81b322b8a385 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1042,7 +1042,7 @@ unsigned long bdev_start_io_acct(struct block_device = *bdev, enum req_op op, { part_stat_lock(); update_io_ticks(bdev, start_time, false); - part_stat_local_inc(bdev, in_flight[op_is_write(op)]); + bdev_inc_in_flight(bdev, op); part_stat_unlock(); =20 return start_time; @@ -1073,7 +1073,7 @@ void bdev_end_io_acct(struct block_device *bdev, enum= req_op op, part_stat_inc(bdev, ios[sgrp]); part_stat_add(bdev, sectors[sgrp], sectors); part_stat_add(bdev, nsecs[sgrp], jiffies_to_nsecs(duration)); - part_stat_local_dec(bdev, in_flight[op_is_write(op)]); + bdev_inc_in_flight(bdev, op); part_stat_unlock(); } EXPORT_SYMBOL(bdev_end_io_acct); diff --git a/block/blk-mq.c b/block/blk-mq.c index d0c37daf568f..6bdfe642bd93 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1082,8 +1082,7 @@ static inline void blk_account_io_done(struct request= *req, u64 now) update_io_ticks(req->part, jiffies, true); part_stat_inc(req->part, ios[sgrp]); part_stat_add(req->part, nsecs[sgrp], now - req->start_time_ns); - part_stat_local_dec(req->part, - in_flight[op_is_write(req_op(req))]); + bdev_dec_in_flight(req->part, req_op(req)); part_stat_unlock(); } } @@ -1143,7 +1142,7 @@ static inline void blk_account_io_start(struct reques= t *req) =20 part_stat_lock(); update_io_ticks(req->part, jiffies, false); - part_stat_local_inc(req->part, in_flight[op_is_write(req_op(req))]); + bdev_inc_in_flight(req->part, req_op(req)); part_stat_unlock(); } =20 diff --git a/block/blk.h b/block/blk.h index b998a7761faf..05099aab6863 100644 --- a/block/blk.h +++ b/block/blk.h @@ -4,6 +4,7 @@ =20 #include #include +#include #include #include /* for max_pfn/max_low_pfn */ #include @@ -11,6 +12,7 @@ #include #include "blk-crypto-internal.h" =20 + struct elv_change_ctx; =20 /* @@ -485,6 +487,26 @@ static inline void req_set_nomerge(struct request_queu= e *q, struct request *req) q->last_merge =3D NULL; } =20 +static inline void bdev_inc_in_flight(struct block_device *bdev, + enum req_op op) +{ + bool rw =3D op_is_write(op); + + part_stat_local_inc(bdev, in_flight[rw]); + if (bdev_is_partition(bdev)) + part_stat_local_inc(bdev_whole(bdev), in_flight[rw]); +} + +static inline void bdev_dec_in_flight(struct block_device *bdev, + enum req_op op) +{ + bool rw =3D op_is_write(op); + + part_stat_local_dec(bdev, in_flight[rw]); + if (bdev_is_partition(bdev)) + part_stat_local_dec(bdev_whole(bdev), in_flight[rw]); +} + /* * Internal io_context interface */ --=20 2.43.0