From nobody Sat Jul 25 19:28:29 2026 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 163783783C1 for ; Tue, 14 Jul 2026 10:30:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784025046; cv=none; b=KWT15Vle9DQNH16p82+Sbq4hLmTNtL1bSvuFbPLYN3ZlZyJeAt9L6KuGMyAZ0lSMuxqdR/CtOleFtuT03s57rtDckD3No1YFI9ZTdyz5oWULGyNLNxQXMWoiMXdoMsRG8AEufF8B1fgnnJmtFQq05mhZ3Nd3rXPLIV0ZdblEJxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784025046; c=relaxed/simple; bh=n7uUnAsByIjvSgaZQkwQiCfH1Ys8honPYx+MozQ4Pg4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q/tdRcRc8Ji3dxGsmrUVhTHWZOKXFKHZso6EOf81RxMkzqQ3W+P7VxpUkMD5cGT14sMF1i6Pod1TNLxD82FQA/bDh+I6Vb7eiybgOyip5zyZ4shTvK7HG7RP+1oud7UDfvq5Xhvxu9SQf8N/E25qu3YATmGqV3CuLHyeJM8bArg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=d+vIPa9i; arc=none smtp.client-ip=91.218.175.185 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) header.d=linux.dev header.i=@linux.dev header.b="d+vIPa9i" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784025043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m/u7naX1aPgWaBFngKTQYarR31o9MXmyDdVdpFnIeS8=; b=d+vIPa9i1s8p6qSV0TrH4u+qccCQe5ntPIXvm3qUR9EVyWZ1PQh1+ijqc1/j1yHxftdNjA yw33ivNTTpcNGupo17itWaRhOhZhS+TFuVWMEcR4OGk/FoFMCm80BKqVei7oWyVcQmyl5J z92H3ugX5kfuH0Uybl327Fk06qWWWrs= From: Tao Cui To: axboe@kernel.dk, tj@kernel.org, josef@toxicpanda.com Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Tao Cui Subject: [PATCH 1/2] blk-throttle: avoid ilog2(0) in calculate_bytes_allowed() Date: Tue, 14 Jul 2026 18:30:27 +0800 Message-ID: <20260714103028.1334831-2-cui.tao@linux.dev> In-Reply-To: <20260714103028.1334831-1-cui.tao@linux.dev> References: <20260714103028.1334831-1-cui.tao@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Tao Cui __tg_update_carryover() can call calculate_bytes_allowed() with a zero jiffy_elapsed right after a slice starts. The overflow guard if (ilog2(bps_limit) + ilog2(jiffy_elapsed) - ilog2(HZ) > 62) relies on ilog2(0) =3D=3D -1 (fls64(0) - 1) to stay below the threshold so that the subsequent mul_u64_u64_div_u64(bps, 0, HZ) =3D=3D 0 is reached. That works, but the ilog2(0) dependency is non-obvious. Add an explicit early return for jiffy_elapsed =3D=3D 0, which is equivalent (mul_u64_u64_div_u64(bps_limit, 0, HZ) =3D=3D 0) and removes the reliance on ilog2(0). No behavior change. Signed-off-by: Tao Cui --- block/blk-throttle.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index ffc3b70065d4..f37911abefdd 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -603,6 +603,10 @@ static unsigned int calculate_io_allowed(u32 iops_limi= t, =20 static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elap= sed) { + /* 0 elapsed =3D> 0 bytes allowed; also avoids ilog2(0) below. */ + if (!jiffy_elapsed) + return 0; + /* * Can result be wider than 64 bits? * We check against 62, not 64, due to ilog2 truncation. --=20 2.43.0 From nobody Sat Jul 25 19:28:29 2026 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E207937FF75 for ; Tue, 14 Jul 2026 10:30:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784025049; cv=none; b=UNVeW/wHaM7BrMpG3Cahk6Uh52HrNASLudgTv+twAUWUjY9A1reRJa42qJJIhsHvROGgskOqa6dFjGZWH2uL/Nkgi0yY6RZI47PiJ2AoTd39OmRlx9ebp2jHjnFCAbBI8CiBz5jivPPfSc4UDYpxU5QKOfgQUpFpPsuiP0txqsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784025049; c=relaxed/simple; bh=puc9YALtWziqYkBJbt5VOrrHc69KiWlEH9pttLkhJhw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pKJU53YB+qMr5uEb+3iLZaxgy2T6oTYpLL6iXVX1aWm/5UcHJzmudUQqBj/kcut+hXtwgtZQVpQQ9P2dJjjVBe8/YIiyisVKvR5h3RQPpKTIh4/4RtGU80cay/fJFPGHeA6vVAus+c8jT7oqMEbk9L1Z1yB+kfuSEilriTaT6Ks= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cbG7teos; arc=none smtp.client-ip=91.218.175.180 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) header.d=linux.dev header.i=@linux.dev header.b="cbG7teos" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784025046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f8dzd6NP/vphjF8glzA850rGTiei5MmL1QvD+Zjdb/s=; b=cbG7teos1hPq/2TFO72otOkBg17nt399lz2/mE6osxSraceZHUh1d7yLZZRUFEjaqtrX7b sVjO7JvS5KAmQgirArF47Foy4N26Mc2kIkegqc0l7B1h3xM99YnmyfhnX6ZXdX8XvjDv4y ngLNarmPlRPfU9FjbLZTJrGv8IjrJPE= From: Tao Cui To: axboe@kernel.dk, tj@kernel.org, josef@toxicpanda.com Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Tao Cui Subject: [PATCH 2/2] blk-throttle: factor out limit field printing in tg_prfill_limit() Date: Tue, 14 Jul 2026 18:30:28 +0800 Message-ID: <20260714103028.1334831-3-cui.tao@linux.dev> In-Reply-To: <20260714103028.1334831-1-cui.tao@linux.dev> References: <20260714103028.1334831-1-cui.tao@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Tao Cui The four rbps/wbps/riops/wiops blocks in tg_prfill_limit() are identical apart from the key string and whether the limit is 64- or 32-bit. Factor them into tg_prfill_limit_field() and drop the bps_dft / iops_dft alias locals in favor of U64_MAX / UINT_MAX directly. The io.max seq_file output is byte-for-byte unchanged. Signed-off-by: Tao Cui --- block/blk-throttle.c | 48 ++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index f37911abefdd..8f4563acbc16 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -1489,47 +1489,37 @@ static struct cftype throtl_legacy_files[] =3D { { } /* terminate */ }; =20 +static void tg_prfill_limit_field(struct seq_file *sf, const char *key, + u64 val, bool is_uint) +{ + u64 dflt =3D is_uint ? UINT_MAX : U64_MAX; + + if (val =3D=3D dflt) + seq_printf(sf, " %s=3Dmax", key); + else if (is_uint) + seq_printf(sf, " %s=3D%u", key, (unsigned int)val); + else + seq_printf(sf, " %s=3D%llu", key, val); +} + static u64 tg_prfill_limit(struct seq_file *sf, struct blkg_policy_data *p= d, int off) { struct throtl_grp *tg =3D pd_to_tg(pd); const char *dname =3D blkg_dev_name(pd->blkg); - u64 bps_dft; - unsigned int iops_dft; =20 if (!dname) return 0; =20 - bps_dft =3D U64_MAX; - iops_dft =3D UINT_MAX; - - if (tg->bps[READ] =3D=3D bps_dft && - tg->bps[WRITE] =3D=3D bps_dft && - tg->iops[READ] =3D=3D iops_dft && - tg->iops[WRITE] =3D=3D iops_dft) + if (tg->bps[READ] =3D=3D U64_MAX && tg->bps[WRITE] =3D=3D U64_MAX && + tg->iops[READ] =3D=3D UINT_MAX && tg->iops[WRITE] =3D=3D UINT_MAX) return 0; =20 seq_printf(sf, "%s", dname); - if (tg->bps[READ] =3D=3D U64_MAX) - seq_printf(sf, " rbps=3Dmax"); - else - seq_printf(sf, " rbps=3D%llu", tg->bps[READ]); - - if (tg->bps[WRITE] =3D=3D U64_MAX) - seq_printf(sf, " wbps=3Dmax"); - else - seq_printf(sf, " wbps=3D%llu", tg->bps[WRITE]); - - if (tg->iops[READ] =3D=3D UINT_MAX) - seq_printf(sf, " riops=3Dmax"); - else - seq_printf(sf, " riops=3D%u", tg->iops[READ]); - - if (tg->iops[WRITE] =3D=3D UINT_MAX) - seq_printf(sf, " wiops=3Dmax"); - else - seq_printf(sf, " wiops=3D%u", tg->iops[WRITE]); - + tg_prfill_limit_field(sf, "rbps", tg->bps[READ], false); + tg_prfill_limit_field(sf, "wbps", tg->bps[WRITE], false); + tg_prfill_limit_field(sf, "riops", tg->iops[READ], true); + tg_prfill_limit_field(sf, "wiops", tg->iops[WRITE], true); seq_printf(sf, "\n"); return 0; } --=20 2.43.0