From nobody Tue Jun 9 01:00:50 2026 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 B027E13B293 for ; Mon, 25 May 2026 02:19:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779675565; cv=none; b=VQXjNaj633VkqWMnTk21xCXBVihphPNWmsruTIV9OBVTq+Nu2GfwOO9ezl3pZ1Eq2697DMWBhuQJBGTE7aDflmrLAMwMWUcKt49KuhXR8IkLK2L1aTFJ4o8KW1QTKoFXKI61466mGHymZwkh1qy/+TPKmTFyl31AZnT+YqBsHk4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779675565; c=relaxed/simple; bh=zReoTNQHuCqcKjkBzIWRBpEKu5UKFc50Fud645+nme4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=uW8n5NuWIupPculELBuNhu07UgWS8uA/tP9t206PWt+7v5A2yHMJea25tXugWvtshzhdsy2YadM//rUbe+mbeT9nliaenTjwyugsIsHYyxBgpICukrBGiqyIwpNZFE89u+Ezo8iYs6QRu9SlBsSoCEabdMGDYNkO8JeW9tmvnOA= 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=Boe0NcUX; arc=none smtp.client-ip=209.85.214.181 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="Boe0NcUX" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2bd2051167eso43812185ad.1 for ; Sun, 24 May 2026 19:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopee.com; s=shopee.com; t=1779675563; x=1780280363; 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=yw2pRdAsIvFX8ugAdOnRGn1wklNSpi51u1Gkz1tBy7w=; b=Boe0NcUXiG6UAMypy6W0H6ngvN8712yCNqv/WrGROdu9Im7hGdnEnL+L/gCk3vzMbT 4WbcqP9z9D8b96oyh1q2qGPHk13AEvJJo/nhchTAp2QL33jrRtwmymXo4XR8VvM+y0K/ 8OpBW+KVTHHuJa2+HGLGJscVf7nJK77OxocO7Iz0he/SJOcG7Htc+poa17tsTr0kn4Ou jbOzMi9i9x6ayqx0VIVXuLhd9EPBPitve8mK7gv5XfwkAmEytINOSKxaGMQD6oF9pw/v BBtXAQeGAnFZ8k6DVwK5jRIR8G/MzLn96FWg3Au7+LFt1RDgSWMTHNnUNuVt9vKgVJDy GCFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779675563; x=1780280363; 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=yw2pRdAsIvFX8ugAdOnRGn1wklNSpi51u1Gkz1tBy7w=; b=Y9bMV+utUPm2OaAvkGuH4IqXhbzL7nHkUzat5xIZFmbNadYnHLkpqYBVZ/r7UtMAFK PoRbUGa9RbzXJQ0fe6JgzSrt9YflcxlndNQTHFCZhn8TDk95msFrFMVL6tCIld/QSaGi TdYfn3Hrzz553LJSQypU1R1fZbF1h+nuVLe2L3goor3atgeyyVdjn7zIJaw4oaQzSEW3 5hWKLs3xKAIMcTCsS31UPnnDYRkKMglHFvxQTXApJVYOrHx6c9w/E6hNWy/PrnHuofnj 5DLSqU8L6NhAN5DzcGvrBABZ6WTKF+7X7tS0U/pbpfDeSyPVcA56LednIAdszou5frft 2aWQ== X-Forwarded-Encrypted: i=1; AFNElJ8NqfefTVjUqtbZ1PH1ajXsCHYbFiOz8bcyukTlq40Iaa3e4GFqmFluiVUzCalAOgCtPp+s7l2raKEo+iQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxKAC3Yij6G1EBXRjc/yQvmT/IFKBTBMD7Wj+Z+LS5Zi+agkvaY ZrftzsZ27Jw5x7jMnB+JSdXdWzEe2qEpb7ia9RNSLrA+wvjueyd/nZo78mN4nOD/YZY= X-Gm-Gg: Acq92OFaFxhc341wV+I4LquyC+hgcky4IK8aCQ1tYAlsRMhp6lzyNJi+QlYcl1a7EGS pIil8t4Og/gKfgxYKPi1gSbAGTLzD8c9TOMRrB2JAL20NV/nghOi8flrU+lzsIhIELKFujNF8br cxGRSfADyCyz9Af1IzH1VHRe+tGftYSy91RVqh+r2BOq/Np/MHhNJUpvHVeHs2WD6r7yn9pgkMy 9Jde0eC5E38RX47qBDi8pYmovPFtlf49wTkgZlRj++mfMxkIsD0Dsax0pWH9NkrsonaEQ4PW+TF iqtI5z4NdwtRYHatRlBvdtVhJPQ2aJXnQD5iv0PT72Z7oA0Is80YoHIB8794VL7Y8vObtgpC9VV ioTdfBQqpvGM2PBRhWRHwHr+xQfJXFjcXUNokzGINrHObRF44UyVh7Bdy5bS1RkVjSiebycqfXh 9wYGAjHgE1pfkIVhlMw2Y= X-Received: by 2002:a17:903:3c28:b0:2bd:3c1a:473e with SMTP id d9443c01a7336-2beb038b83amr135531425ad.14.1779675562898; Sun, 24 May 2026 19:19:22 -0700 (PDT) Received: from localhost.localdomain ([147.136.157.3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2beb58b303bsm79652165ad.38.2026.05.24.19.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2026 19:19:22 -0700 (PDT) From: Tang Yizhou X-Google-Original-From: Tang Yizhou To: axboe@kernel.dk, hch@lst.de, kbusch@kernel.org Cc: yukuai@fnnas.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Tang Yizhou , Leon Hwang Subject: [PATCH v6] block: propagate in_flight to whole disk on partition I/O Date: Mon, 25 May 2026 10:19:17 +0800 Message-ID: <20260525021917.273190-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. v6: Accept Keith's suggestion and fix the bug in bdev_end_io_acct(). 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..cee4e4a37503 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_dec_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