From nobody Sun May 24 18:43:53 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 7B2462FE057 for ; Fri, 22 May 2026 14:16:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779459412; cv=none; b=N37vI5cgX1ZQVMMWV2PvrrJXM2TJHtiAXkf2i4TjTz0iWdkT92DOoC/cj67SltUb0ew3JNQcejFpvallJBDVaeQYeLZHBKQJUolajXtQWgctPpGLhAn0pLtOXPPB9t6rlT1CZF90XMjYgaCmbtoMufYsZOZu/riWRONLDNqvZwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779459412; c=relaxed/simple; bh=omLfhd9P8ZMzbrFN/bvkQuKDPR19lEwO9vI8Cxa2iaA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=d3FpWeV4i82dNmk4q+FoDMX/g6fhTyD+k3yrFZK4yIEgSNhNi3A7gQd4TNoOKJkLHHkdXZAij/AX3jos06qsdXbqnwO3sfEC28HC6P2RivmtAcTmYSzOue7V6lBhllcAym1WazCTsopm9QCMO48ziw8hiNH8rAJv2hklUiOlZ78= 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=FKjGAX2W; arc=none smtp.client-ip=209.85.214.177 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="FKjGAX2W" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2bea7176c72so13617565ad.0 for ; Fri, 22 May 2026 07:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopee.com; s=shopee.com; t=1779459404; x=1780064204; 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=sm5g6roIH5VbkZ70IevzPDKMpg3vptkkzH9aFt0FTL4=; b=FKjGAX2WPIZvSC5rjXyySBZAuCpgUnuFbzmgX1MgNV63L6tdEciiP9gYE3sS2Uk+1L gtx4GYJ8jXUtmIFwLteDeGVq9nKgOEgUXSCn+FfU7GbvQMtylG5rb2XGtj9eWayEsy/2 cfgPPAJqyANMRtCeQ9n4gRNDrV5EP9t8/hUY3RzktJ+TQEUvlaE80ljdfihgFZjCPwI8 YGzzFV8Jy196fipZlt+NzUbff7UWqItnCfHBVggV+XBRXLy1qZAOJqqkYtc9e4DA0M5V OLXmYXii5axszjw+bb9trwdzI/LKo0H748VZHscEJqF3ErEtyNV1RL4+D4nM/KnnpamZ ma2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779459404; x=1780064204; 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=sm5g6roIH5VbkZ70IevzPDKMpg3vptkkzH9aFt0FTL4=; b=XIP1rz1BDpdGkxR+Nbes3Ze+JYfqni0quPjlBtsk39DKqHRhy7ozJCjbpgltubArl3 ciH/noD7K3PDbI8dyN7tUu84PfhMGwCutJyqHMcqoJQ5GaZ/sRaOVzwHPDanIFpIWlPO 3JP4ikd5yelHt9EqpcsGFg4m2bHtEIRLaKXsULBTcSQu8ijs4GtFlXBzty8RWqWojcC9 r16CaOK+sNb1d3bWHuO/xWs97AN3idfs+9xT5R7vbA8rvAGm486KDxGPl8sHwnVmcxDO V4xMvGE72MojWkFFiUdXpj9K6kiaG53xpbtCLR+leoqpxGEswyg5JXXBmQKSMsx+gsAL K7Ng== X-Forwarded-Encrypted: i=1; AFNElJ9lbki0w375ndr+wTjv8jo92iTg+z1QWVpYNJY2GuQpbzej5GG03mUe59lAp0Q7r8ooKoX4m2Ahx5JQRso=@vger.kernel.org X-Gm-Message-State: AOJu0Yzf5VLyFbsrhghg/j4P3OALv1wlSwHBsxG68iGLFuuiyehjVOls 3Ozyh+/0Fvavn6BEiyNz4xi8CV2EOHYRqGsK1rG7+XsnYMPzENXVqiu3fxg5UHwgP0g= X-Gm-Gg: Acq92OHAfMGStQ+nlPkKTCLi3QX26Ud5NWHQuQkSiqbNzW2lqxXZVHI/XM2FVDvxYV8 /emrRFQ3Db3xEK+SLgTyybkZH4RV+SItE8dQ3vZYOk3HxLQmluI3vyAyQTizWYjSWhaUq5uR7PL Hpck3SzhxqQeoJRdsvZLCvN4D2bXrP9fT+MAYGOZe6GRzAc+7o4WXFhuYj4CNbukRRklKzNbbQe xbfQw+YaV07pwbkauwIU9ZhWiWPCZwcLzQfEz589Do97dMQkQyXQOGsqjW6eZVjxGh75Cipi0O7 Ezh83ouo5TtszJTf2L2VxqicCYTJ/XaI7LARKab22ALlXmIkeXZW/kUO2JIMUFtp5sSHsZKgGpQ gq5cIYaiGIonQp+WebbQhZVp6O8UPsF1c5waVum302lfF/NIDtFIMSHhHDlFdWVYOcNfpfHeAiu 3SkeRxVI73CvqPV2BSSnY= X-Received: by 2002:a17:902:d4d1:b0:2bd:a5f:1d04 with SMTP id d9443c01a7336-2beb05bf787mr40573715ad.9.1779459404474; Fri, 22 May 2026 07:16:44 -0700 (PDT) Received: from localhost.localdomain ([147.136.157.1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2beb5695a75sm28387505ad.14.2026.05.22.07.16.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 07:16:43 -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 v5] block: propagate in_flight to whole disk on partition I/O Date: Fri, 22 May 2026 22:16:38 +0800 Message-ID: <20260522141638.298530-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") Suggested-by: Leon Hwang Signed-off-by: Tang Yizhou Reviewed-by: Christoph Hellwig --- v2: Update commit message. v3: Take Christoph's advice and factor the common code into two helpers. v4: Remove my redundant new line in blk.h. Add Christoph's Reviewed-by tag. v5: Remove the changelog from the commit message. block/blk-core.c | 4 ++-- block/blk-mq.c | 5 ++--- block/blk.h | 21 +++++++++++++++++++++ 3 files changed, 25 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..11245a494c43 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 @@ -485,6 +486,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