From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 CAD5135201B for ; Mon, 22 Jun 2026 09:56:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782122216; cv=none; b=VQv0SSl1cJZoK66NH0afTM+kPrhkJOeyRdvCrX8vURMVk4czMbe/Gqv1QUs4jqbVWXHMYNQaJBMKC+FIyWGhPMXW1mEGFmhtsep2K9D1Spq2RjM4THEsyuMgUONj22zq7WqpQRUIdE6vLZbgOdbPXYT6ouq72whBHtxIRvsssbU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782122216; c=relaxed/simple; bh=fOes4u6YPlCysgI3j9WKo5U8oWbuUbAxkoBbRu0Y9uI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=pgAhzefxwDKD82nZFR+Jt6hqyLQxcZd3bpqCXsXPcWgq+DB1VDb6G/MJWKaGaIHd0V6uD0XuTU0arYCQPhol9LOC31RDDT3azZVWzmX/GkRN71rQanJW0mtJeXbVEXg84f6daiFKrlde+vk64qG/8cK7OzrkMZuOiDosZzCtkuU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=mina86.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HtTvWNBa; arc=none smtp.client-ip=209.85.218.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=mina86.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="HtTvWNBa" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-bed2195323cso645172566b.1 for ; Mon, 22 Jun 2026 02:56:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782122213; x=1782727013; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=jNPs0n7LW3JDVVH575egJ1f2yasTba5O4TY5MoneO8U=; b=HtTvWNBaBGZQQAbt8ChJVjovcKdAAn1QUvNGAcV1/Wuza+ajYZSwK1nt4bh/ZDMry+ 5RRta3rcG8Saq9Q3+4ex5hC4jAriWkOm0kyFUwn6EV5P8R4i9qC0qrHgCzedH93gSnF2 cmEO0onxX0s9fJs76KDyKFK4en+joer5FzAlA/Sio7iskdhPrjR2/Ynk3bp3rO+1udtO UQ5X4sveTmS9xff1dGgoPwcdAim9S3J5g5XL6qczyWQzhPuVoes49pdbde0Te9CQvGSJ NA9DIh/k2mO23O2IAfvzNDVL/22yM+U1/pCHyof9lELYh8IehJMipQkeClxCnIdGODck ep7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782122213; x=1782727013; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:sender:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jNPs0n7LW3JDVVH575egJ1f2yasTba5O4TY5MoneO8U=; b=IG8hdSvhzdjqwSkBNiNfLWfMW9J9pWOYHnhN8H50jLzqyiuhe2dcd7X530rYOCLHM6 eiyCHfUpY5ZWrDL5pGw3PwZ4hqPXgu7map2t+MKt8oIcSQDm2vY+j9XkoTCnG7JyFSmX p7BANHdmILi/t45NKp0s7lA0Ikim42cFBFmJKctKjdYMj11C6S8XRH2aRObbRwClmWEq HTytkKht2Ut5cVJoUWnzmxJnj4yG0c9Xzl81Uj1X1OyKuO+4d1lb910YPvZ4MdfRZS6K NV0PWYWVsAvy0PMsIZhU+yIt+anciwhAaF3VEajjn2SStaU4p15/QVovlJZWZGWgAjas lJog== X-Forwarded-Encrypted: i=1; AFNElJ+q01GiN73+AAXR3JsW4BtpErgOG16hDz+TJ6Hfw8aDFAiIxMff3oBBMwBtCaqknc5fgqYU3V1d8i6aKMQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwyibMxPVlUd8HtL6vpSieY8xHeRuQkrKNfuu13MQGoced4xhy/ F/dORDxORRn+HzDRivIi/SOwbTfqMQfchb3dDo35u5MAx5c+1JXUJW3j X-Gm-Gg: AfdE7clBBln5Nsa5jCxcnSkSdy65oiuKbSzY2uc8gq7WqkbmhrqfT7Z6eeulOiEk0RH kY8JsezasSqxD2vyk8EQtNmSgGh8G/2t+2geGgLeg87O3So8o6WWjqY5yGU9fywqT4ONRQid8XS 2BYvl7TecpxwY6IDmgEW/NpgN3G7kO1INiML305TJIOjbmjO57KcGwVb+kj/O/tnNreI68uLBZi 5XdbRE4JHJmslb8iGICzZ29NtvWbO+mSSDxhNj7QGZy5ERcyzKIgxI3TFGYIgYXdjLGRh2jr53w lFjF5uiwDgXQlU4qLtYHA6o09NhoHPQhHple7nJhdnUS9n0YETPHpCfLzQPVIZ9nb8AQFLCVuGG Tnt+g73Bkjm84ecrLHF/dS4JYRIZRdfv3LWBYLYcNkfqx8PswMoRI5wAlEEHlliHtGJTibNpTDK Xz9oKqdXrwd8rq0pq4+CyZM0z8iBsTbcxmM0ZXCDc= X-Received: by 2002:a17:906:f5a2:b0:c07:9e7a:4b60 with SMTP id a640c23a62f3a-c0b75487180mr592983166b.44.1782122213042; Mon, 22 Jun 2026 02:56:53 -0700 (PDT) Received: from erwin (109241130011.warszawa.vectranet.pl. [109.241.130.11]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c0c610de4b5sm323049466b.42.2026.06.22.02.56.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2026 02:56:52 -0700 (PDT) Sender: =?UTF-8?Q?Micha=C5=82_Nazarewicz?= From: =?utf-8?Q?Micha=C5=82?= Nazarewicz To: Yi Sun , yury.norov@gmail.com Cc: yi.sun@unisoc.com, 279644543@qq.com, akpm@linux-foundation.org, akinobu.mita@gmail.com, linux-kernel@vger.kernel.org, tjmercier@google.com, fvdl@google.com, tglx@kernel.org, song@kernel.org, hch@lst.de, minchan@kernel.org, jstultz@google.com Subject: Re: [PATCH v7 2/2] lib: bitmap: optimize bitmap_find_next_zero_area_off() In-Reply-To: <20260622030036.1744080-3-yi.sun@unisoc.com> References: <20260622030036.1744080-1-yi.sun@unisoc.com> <20260622030036.1744080-3-yi.sun@unisoc.com> Date: Mon, 22 Jun 2026 11:56:51 +0200 Message-ID: <78yemtv2gix92wc9z7d08rfw@mina86.com> 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 On Mon, Jun 22 2026, Yi Sun wrote: > Finding a contiguous free region in a highly fragmented > bitmap is not easy and may require many repeated attempts. > Therefore, find_next_bit(map, end, index) is not the optimal choice. > This is because there may be multiple scattered free regions > within the range [index, end) and none of them will meet the length > requirement of @nr. > Instead, it's sufficient to directly find the last bit within > the range [index, end), thus reducing unnecessary repeated calls. [=E2=80=A6] > Co-developed-by: Yury Norov > Signed-off-by: Yury Norov > Signed-off-by: Yi Sun Acked-by: Micha=C5=82 Nazarewicz > --- > lib/bitmap.c | 31 ++++++++++++++++--------------- > 1 file changed, 16 insertions(+), 15 deletions(-) > > diff --git a/lib/bitmap.c b/lib/bitmap.c > index b9bfa157e095..a00a71f2b7bb 100644 > --- a/lib/bitmap.c > +++ b/lib/bitmap.c > @@ -432,22 +432,23 @@ unsigned long bitmap_find_next_zero_area_off(unsign= ed long *map, > unsigned long align_mask, > unsigned long align_offset) > { [=E2=80=A6] > + unsigned long end, i, off; > + > + for_each_clear_bit_from(start, map, size) { > + start =3D __ALIGN_MASK(start + align_offset, align_mask) - align_offse= t; > + end =3D start + nr; > + if (end > size) > + break; > + > + off =3D round_down(start, BITS_PER_LONG); > + i =3D find_last_bit(map + start / BITS_PER_LONG, end - off) + off; > + if (i >=3D end || i < start) > + return start; > + > + start =3D i; Gotta be honest, I=E2=80=99m not a fan of `for_each_clear_bit_from` the way= it=E2=80=99s used here. It hides the `start++` that happens at end of each loop. The code works either way, but I find the current form harder to read than an infinite loop. Having said that, Yury is the maintainer here so if he prefers that, I=E2= =80=99m obviously not gonna fight it. > } > - return index; > + > + return size; > } > EXPORT_SYMBOL(bitmap_find_next_zero_area_off); --=20 Best regards =E3=83=9F=E3=83=8F=E3=82=A6 =E2=80=9C=F0=9D=93=B6=F0=9D=93=B2=F0=9D=93=B7= =F0=9D=93=AA86=E2=80=9D =E3=83=8A=E3=82=B6=E3=83=AC=E3=83=B4=E3=82=A3=E3=83= =84 =C2=ABIf at first you don=E2=80=99t succeed, give up skydiving=C2=BB