From nobody Wed Apr 8 02:48:24 2026 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 B8A5931AAB8 for ; Tue, 10 Mar 2026 15:21:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773156106; cv=none; b=uCVQaywc6klKBlJLBO32GRLys2QeENXnOTJASja8bWDiICL7Up8zJ/wboETCisW+DB2yVJGd/urhMyDbH3sMoZBz7yCSgCrlLOpr4ibCvMu44iJx0vEIq6X0+PRq8csq3NqGTxILn6FUhrV2L0pSrT4znTrtgygRlH5hl77Ygok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773156106; c=relaxed/simple; bh=a4SUs8qMuXXHM1t8guQeueTRui0y9gPBso+1YHa+pog=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=djqhrnhQhb/LaJciE79E7D3EyPYB7a1rVq2DTFN8uwTTFmbcraVCNP5x/GXeIZUK9df0s0/tMHxmOMRg/XKa1DI1NTjVXlIS8ea+tpy6MahqpZcOFp+StGjYJk/sywLP7fvFDEme/jW/Rphlhiib4hQQ9D3PUJHDMDaMNTHzXuw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UsrGUaZB; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UsrGUaZB" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-356337f058aso7546037a91.2 for ; Tue, 10 Mar 2026 08:21:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773156104; x=1773760904; 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=G/5shUmHKZJdAAILThpahH7gKBK4Ce2xfPZA25CEF+0=; b=UsrGUaZBNKldoU6BP4ffTsg8qLIots2Gd/dAWca23iejJvrB/us6sDjSUZq2dwp68T qy3gznrP4y0hzff02H/3Bn3jipXx/2pijanyt7rmA8ROT35iyFbZExiT/uX1b1KNCndO eiCmGiwmeUsRD1Esocnr/pph0ocrlQ3ankZxiVBDyZv6K5SSGATIb0epIDeMPygtyYcJ DiLBTJdWieqSjXHtTAtEHAvjBwKg6u3PgcG0TW9MZR1hy7+Xogu0P49NQbTgt+G4Qv17 1JOGak63wnEgfZMkZy5QSAk1zQ5u9ikJHRP8//qUxdfeWdUeqOmru12FD4VEkiTBeh7a tCog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773156104; x=1773760904; 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=G/5shUmHKZJdAAILThpahH7gKBK4Ce2xfPZA25CEF+0=; b=baTZlwEHAAAdMRBpGeE1SH+Ih7Ca/Z207+iyvadZqjmyHI7EO4dhjdb5pAMAsjlIPm vfbSWswYSKF4h1WhOh2WxDijXs1Ia2Y1wS+zHr03Bjt8s3bnXlXca+9H192/cP0Bjj9V i85uiRAoakxb1KXnVJDvs8N8YN/zbV1GRUUYJygS+BHZBz/+jVUJOE/isqxySC31HjC7 oDFobnxAn8+Dn+UvlpHLgTqXQlaTOzdWCYwZelh4aLA4WwezqqEpcS9uHuaOSLO0mjhB qrEsim0a/bDOlER0xvH/b989K++e78gwWymKeV20k1+5beK5evwhsI/Z+JPxRvO5S0pb Lk4w== X-Gm-Message-State: AOJu0YweaX4Ro2ff/QUxLTNP6B0A3b1l3EFteleUSXVrS5pA+nIoubOn wkzUHHBdDan+/mTgzm2IP64wdSbmuCyosOWvgItj6UJMilUcyBSIYvYDQqZ6uw== X-Gm-Gg: ATEYQzzzHMqvwkei+gNCoZhB8l7wJPyo8CcB6wnyoaUb7/5zAM7z+7BYRmqEtjOx8Zh u7ALdTHSl84rzDIMfXz5KT7jCxxn177Tf6tPoiew12dR05KR7KNLqExzbjp0opLgcpPmOsYtU31 xWYZ0pxGrmjW1HtbxOBZD8t4IC1jHXtC5Y4yC4mzJ++9XarDikg7C3pDUaTj3CBRP6pB7WoGwLw HmSig7EW2a1UYAt4Ae1B59rj23zA/b52r7W3MlSawkxADBqQ/kJrrvtyT+kl8WhDe3kZRZx6PHd eMASp4z1XiXRfs2yWDZJwQwZ3Np8HPw3wN46tsLR5Sxp7WP6QC7B8aYyA2rSNVKoprGOMdKn37y r0Bt7rNmY9qD3z0ZmCTau9i2Iu/BV8URFH8heS5vVNi0IJDXN7CO1Y+tKTDGWBztlhTK7dDgSRQ T8Rz3394Bp9vdv//LC8Iz+8Sis+OfFDRsGatt9odhxhXUvy4Bw X-Received: by 2002:a17:90b:28ce:b0:359:79d1:60f4 with SMTP id 98e67ed59e1d1-359be2823e2mr14240732a91.15.1773156103812; Tue, 10 Mar 2026 08:21:43 -0700 (PDT) Received: from localhost.localdomain ([240f:34:212d:1:42d1:111d:2b5b:9957]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-359f080dd89sm3206594a91.10.2026.03.10.08.21.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2026 08:21:43 -0700 (PDT) From: Akinobu Mita To: linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, Akinobu Mita , Yury Norov , Rasmus Villemoes Subject: [PATCH] lib/find_bit_benchmark: avoid clearing randomly filled bitmap in test_find_first_bit() Date: Wed, 11 Mar 2026 00:21:26 +0900 Message-ID: <20260310152126.6919-1-akinobu.mita@gmail.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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" test_find_first_bit() searches for a set bit from the beginning of the test bitmap and clears it repeatedly, eventually clearing the entire bitmap. After test_find_first_bit() is executed, test_find_first_and_bit() and test_find_next_and_bit() are executed without randomly reinitializing the cleared bitmap. In the first phase (testing find_bit() with a random-filled bitmap), test_find_first_bit() only operates on 1/10 of the entire size of the testing bitmap, so this isn't a big problem. However, in the second phase (testing find_bit() with a sparse bitmap), test_find_first_bit() clears the entire test bitmap, so the subsequent test_find_first_and_bit() and test_find_next_and_bit() will not find any set bits. This is probably not the intended benchmark. To fix this issue, test_find_first_bit() operates on a duplicated bitmap and does not clear the original test bitmap. The same is already done in test_find_first_and_bit(). While we're at it, add const qualifiers to the bitmap pointer arguments in the test functions. Signed-off-by: Akinobu Mita Cc: Yury Norov Cc: Rasmus Villemoes --- lib/find_bit_benchmark.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/find_bit_benchmark.c b/lib/find_bit_benchmark.c index 402e160e7186..00d9dc61cd46 100644 --- a/lib/find_bit_benchmark.c +++ b/lib/find_bit_benchmark.c @@ -30,18 +30,20 @@ static DECLARE_BITMAP(bitmap, BITMAP_LEN) __initdata; static DECLARE_BITMAP(bitmap2, BITMAP_LEN) __initdata; =20 /* - * This is Schlemiel the Painter's algorithm. It should be called after - * all other tests for the same bitmap because it sets all bits of bitmap = to 1. + * This is Schlemiel the Painter's algorithm. */ -static int __init test_find_first_bit(void *bitmap, unsigned long len) +static int __init test_find_first_bit(const void *bitmap, unsigned long le= n) { + static DECLARE_BITMAP(cp, BITMAP_LEN) __initdata; unsigned long i, cnt; ktime_t time; =20 + bitmap_copy(cp, bitmap, BITMAP_LEN); + time =3D ktime_get(); for (cnt =3D i =3D 0; i < len; cnt++) { - i =3D find_first_bit(bitmap, len); - __clear_bit(i, bitmap); + i =3D find_first_bit(cp, len); + __clear_bit(i, cp); } time =3D ktime_get() - time; pr_err("find_first_bit: %18llu ns, %6ld iterations\n", time, cnt); @@ -49,7 +51,8 @@ static int __init test_find_first_bit(void *bitmap, unsig= ned long len) return 0; } =20 -static int __init test_find_first_and_bit(void *bitmap, const void *bitmap= 2, unsigned long len) +static int __init test_find_first_and_bit(const void *bitmap, const void *= bitmap2, + unsigned long len) { static DECLARE_BITMAP(cp, BITMAP_LEN) __initdata; unsigned long i, cnt; --=20 2.43.0