From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazon11012061.outbound.protection.outlook.com [40.107.200.61]) (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 0BC0B2E542C for ; Thu, 14 May 2026 16:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.200.61 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778777379; cv=fail; b=Ld8nDO5eP+nawrtwwGiJO8b/O/03/+WHuRP/CIWOBTBZMx9FjpUTVDVtbztGAVQroCA9nYXmz9wLenNFo2Zp8XdF6XRrgnaj4Cn2m+Lv55ahZj6w8jE3mURJXUYs/oxA7JSgcCwumBql+3LX0OKvyUGrTr7/5O8WoRNV5B5SfA8= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778777379; c=relaxed/simple; bh=ZgI72XraOG7KG8PqP2VNxrZqxp8seI1C8GL9i8NvI/Y=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=re5xuyeKToP5y9r7+/b3IYumpHVg/hnI4IUZnmqKYhCJGjA9FwX2eEWMwuEqqPd+CYDqNwgKoSLQVeuyGCpvxMauNLeHEalSuoyklb3PSeAr9QLdk/BdMkV3DRkf1YYzYKfhkBpd1aQAh+OC/1fYhb5WZzQfoabcyoaXn6fF0PQ= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=PwqJWXO+; arc=fail smtp.client-ip=40.107.200.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="PwqJWXO+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VZavzzy+7q4Euq4pYMWDixXQs6bGnnmiaKI2AwqSf3KJwSa5IErVT+GP541apIceGD5n3k+23WMRagsPVlJpuIxpFQpzyeqngRTk9hyoVMVUmL3XUFWjJ2jGyronyRGP9apoPCu6TU1YF5gr+DlCpmT8eo3lB/HAiRi4jLFApkrl6FlqUrHw7f0xtN5dIrwZq8wFThnPCta50y4Wk4wdwslEY9xZyh11kg+M13/4UoecDltjNItctYvX2jG0FQ887pK66v1yvNIdMpCVZgXSmUwovArSV6BZd2Bv8XdkJWKW16lTt+GdjuYRSNk8vwt+U38B7lrr+95N16+0KiyVsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vjJ50UBhHaEHlMUG8bd31HIwpPYU6fna6pMbhBM3iu4=; b=j6a/dL/jSCtNIR5nT2daHPB6EmaHnPyusj5woTV/DGQYivY9YnO7c5c6ev5yn1fwf3My6VeLqJXkVx+PfTqvUl9j8tZYCtC9JsYhVrt0ndIzbiz0IFU/NHafTAFbtQv9y6OfMR9E2JQplsMNWLrCqxkDrJtI0t+ne8kR5jOC1hS2Dv83+wXTg/l7aOduegZIjM9JiTTtwiMDfi0mh8q4DewWxxTb50OGTPEhb5W8Xgem7XKO+t5kSz2roNWQmFqj82X3ghar9bPSy435oA3LeJM+SvYow3C02dHsrv3k/z3TSeGeizb434Jzf3RCOc/sKsLwqvyUkQEi5G08ChkHxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vjJ50UBhHaEHlMUG8bd31HIwpPYU6fna6pMbhBM3iu4=; b=PwqJWXO+WZlYsXGS7Jj/CWg5CbG6y8VTZ+udNgk2wrzgZMVA9W0CrcV3SfmdhYYTCSjBCAD0Zgdsup9NJGfwSTRSRuE8I0XSCw91epnTO7yr2XPu+CDybuCMBa1w3MdZD4T+FsL1IocTvIloM5GEYo+vEyirA595SS6UJYyRL8wG4NOcB1/FeBpQuVlziY6CgXsvSv9cJRCnu7LWWyENO65dM7gItSTrY2XYTIT8yuBvOzu9ozry5Xj05CgYxJEv9kV5FDHeg2xy0uQHZo1n9heXkC2PJhar+ZbgiaoH0tlkDO6GIFFPrs7ysYSoBi/vN5vg5M4wr0Pv1p31hQAiYw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY8PR12MB8300.namprd12.prod.outlook.com (2603:10b6:930:7d::16) by PH7PR12MB5653.namprd12.prod.outlook.com (2603:10b6:510:132::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9913.11; Thu, 14 May 2026 16:49:31 +0000 Received: from CY8PR12MB8300.namprd12.prod.outlook.com ([fe80::ce75:8187:3ac3:c5de]) by CY8PR12MB8300.namprd12.prod.outlook.com ([fe80::ce75:8187:3ac3:c5de%3]) with mapi id 15.20.9913.009; Thu, 14 May 2026 16:49:30 +0000 Date: Thu, 14 May 2026 12:49:28 -0400 From: Yury Norov To: Yi Sun Cc: yury.norov@gmail.com, mnazarewicz@gmail.com, akpm@linux-foundation.org, mina86@mina86.com, akinobu.mita@gmail.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/2] lib: bitmap: add find_last_bit_from() and _find_last_bit_from() Message-ID: References: <20260514090607.231387-1-yi.sun@unisoc.com> <20260514090607.231387-2-yi.sun@unisoc.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260514090607.231387-2-yi.sun@unisoc.com> X-ClientProxiedBy: BY5PR04CA0005.namprd04.prod.outlook.com (2603:10b6:a03:1d0::15) To CY8PR12MB8300.namprd12.prod.outlook.com (2603:10b6:930:7d::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR12MB8300:EE_|PH7PR12MB5653:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b786660-4c87-47b7-4772-08deb1d8c4ca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|10070799003|11063799003|22082099003|18002099003|56012099003|4143699003; X-Microsoft-Antispam-Message-Info: yuk7J4XraKK31EjdVSuyZh6dXTTi0YkuCnQLENAz2UrPsvI771WVmJ4j51wHFOZ4PvOI0FZh76hR+qVLY4amLEUn1/kjmNEJWz0kx/Sb1BrGYg9OyRXiPpH0pNiHno1j0Y2kL/n4y38QdYot5eBFuh2/9gi5KIue55YbomWuVamFkKk/hwv8D7e9RloJ7s9Bv7nduKA1edKujOIMuxYqQm/3dwKI+DKaXf1LN94lD0bZlgc/qEj3PNhydcJh42AuCbrOKskaQ8psKznN1wiOl7K5dq8rKgMKLU8v4FPtq1iJSNquYXamXF1eqpa3i8ymNxRrWejCZ20/zTDb/ghD05pIkVDsmfSHK/az8x7FhP+WHaM8NZIIb0sD6nY9nU64N1fZD1CDqkn3lVRIPL/PnUMazLPf5k8PKkwVkPq4JUitqcrq8IiFTHcHZSP95yAq8rg8iESEg3ZfFCdcYm5UxYtZuOmtQ8DgJVd6mo+jXnOKdlAol7j+fBeyfnpK0vhhjbDcE7HgiZ4vXm69BVUcNL29HnaeZUoLkt2VwU5bsi0yDFUJIzYrslm+7m92AuBGmTsKFkKIU0T+AjtmwavZZTbv2PELBoCtlneLE1fvBsAHgOQ1mKBfCcp6yrAxOLj5MqJuP7UL2ziPaJipETvgFE0iR88vTUZGhi+1OPPoaLRhvDTahAOF5nnkzT/0Czbu X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY8PR12MB8300.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(10070799003)(11063799003)(22082099003)(18002099003)(56012099003)(4143699003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?dRZjbRQp2geYmJ2W3rhA3k0vv6OFMLY+iewO506KHqs4bK67xk62b3oUWzcB?= =?us-ascii?Q?/upvrfJXSlWgM5law/xqHLI5cYMXZpPxJfTCyZO32JImXXKVAyJlP2rAsKkr?= =?us-ascii?Q?Wetg8impn4RUQ6CXG4qpLeVz+tXtgn+W/ZuF8gX2yetE4g0mTUsPjbe8Caap?= =?us-ascii?Q?tSqRQaFtBhzdyr7pxU69cKIG5Ye+03XnDSepy7vplMQ7KTZMVLl4VDzzX/2F?= =?us-ascii?Q?qpBc3fV6DBhPKzxAOkKusYb2fCdvgErxvmlFaGfuq7/aIy8vewOdVAykJx1E?= =?us-ascii?Q?2biDdkl0UBl4yYd+552vuQXzBs2197qrtyA3RYM4lWMNwESZKSL2ItHV2srV?= =?us-ascii?Q?yaMQlnTqPISx7cd0qVLK8btPTUtuid7zLpZ4FtFiZqjrxCbdqU1kmDbmsOn4?= =?us-ascii?Q?ABBsHYWfv+jvcVOTFOIWXizn2pGKv6usO6fNrAbYRlD2Wijms/4fDSzvCVHx?= =?us-ascii?Q?R39iQZ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aGDW9OtRq9p0UE+8u2vam?= =?us-ascii?Q?HeNlQKzOFGvF6htfeFNkx+PJWOc2KDnh0rvbM9ysKuSuyme69LiGhSSxc7jh?= =?us-ascii?Q?TCBo+8b7dEu+rG1ab900VN2xxUvtRpPgp6PTu0c5/NT4g3S6TwSWQYfigUfO?= =?us-ascii?Q?VNci64XW2vEufFEAKTgtyD4FDt5Z/N8ISNshc08P5cJXHk9uXlDo7dx98BmU?= =?us-ascii?Q?s+1SfgkmCISQo7G9H/SBEQQKlkwfV5mig2VSsyWVigimw0x4SlQ7J0zs2Q8S?= =?us-ascii?Q?sI1UYLrln7DnBCMU2Kgr4YYWAH34wLtd/Hp83vNdlAjewL2nFwRGWyZwrLdg?= =?us-ascii?Q?kjcnnSm4XHb3AX/Lq5TGOHT8Jk4t+SWrasR2JqLwjhFSQ37eKsJCyxi+1AWC?= =?us-ascii?Q?+CsTZxCrYnvxy+U4bXyGW+S0HTAjPSO4y1AUtYK4KQi0wKJubCwr?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b786660-4c87-47b7-4772-08deb1d8c4ca X-MS-Exchange-CrossTenant-AuthSource: CY8PR12MB8300.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2026 16:49:30.8491 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: hSDvKgwZFkzJkLbt0wvINcOrUHUqCFWxxqmr45dGaIkMB6cwzsQ9SuBPMSzHHdS18RJvp/NM8bRuqDs0ETHsXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5653 On Thu, May 14, 2026 at 05:06:06PM +0800, Yi Sun wrote: > In some scenarios, it's not desirable to keep searching through the > beginning of the bitmap, but rather to search within a specific part. > The newly added function can accomplish this quickly. > > Signed-off-by: Yi Sun On the previous round you said: find_last_bit_range() is only used here for now, but I believe it will be useful in the future. And didn't let me answer by outdating that discussion with two new versions. Please don't do like that. So my answer to the sentence above is: unless that bright future comes true, the find_last_bit_range() is unused, except for one in-house case. This makes it questionable if we really need the new exposed API at all... There are 63 references of the find_last_bit(). Please inspect them all. If there will be another user, this question will be out of the table. > --- > include/linux/find.h | 33 +++++++++++++++++++++++++++++++++ > lib/find_bit.c | 22 ++++++++++++++++++++++ > 2 files changed, 55 insertions(+) > > diff --git a/include/linux/find.h b/include/linux/find.h > index 6c2be8ca615d..17f1db7b41fb 100644 > --- a/include/linux/find.h > +++ b/include/linux/find.h > @@ -33,6 +33,8 @@ unsigned long _find_first_and_and_bit(const unsigned long *addr1, const unsigned > const unsigned long *addr3, unsigned long size); > extern unsigned long _find_first_zero_bit(const unsigned long *addr, unsigned long size); > extern unsigned long _find_last_bit(const unsigned long *addr, unsigned long size); > +extern unsigned long _find_last_bit_from(const unsigned long *addr, unsigned long size, > + unsigned long offset); > > #ifdef __BIG_ENDIAN > unsigned long _find_first_zero_bit_le(const unsigned long *addr, unsigned long size); > @@ -413,6 +415,37 @@ unsigned long find_last_bit(const unsigned long *addr, unsigned long size) > } > #endif > > +/** > + * find_last_bit_from - find the last set bit in a memory region > + * @addr: The address to base the search on > + * @size: The bitmap size in bits > + * @offset: The bit number to start searching at > + * > + * Compared to the find_last_bit(), > + * find_last_bit_from() has an additional parameter @offset, > + * so it can search within a specific range of the bitmap, > + * just like the find_next_bit(). > + * > + * Returns the bit number of the last set bit, or size. > + */ > +static __always_inline > +unsigned long find_last_bit_from(const unsigned long *addr, unsigned long size, > + unsigned long offset) > +{ > + if (small_const_nbits(size)) { > + unsigned long val; > + > + if (unlikely(offset >= size)) > + return size; > + > + val = *addr & GENMASK(size - 1, offset); > + > + return val ? __fls(val) : size; > + } > + > + return _find_last_bit_from(addr, size, offset); > +} On the previous round I suggested the implementation based on find_last_bit(), so that you don't need to create an outline _find_last_bit_from() function and expose it. Can you compare the implementations for the performance impact. If they are on par, I'd stick to one re-using the existing code. Thanks, Yury > + > /** > * find_next_and_bit_wrap - find the next set bit in both memory regions > * @addr1: The first address to base the search on > diff --git a/lib/find_bit.c b/lib/find_bit.c > index 5ac52dfce730..196b946dafff 100644 > --- a/lib/find_bit.c > +++ b/lib/find_bit.c > @@ -237,6 +237,28 @@ unsigned long _find_last_bit(const unsigned long *addr, unsigned long size) > EXPORT_SYMBOL(_find_last_bit); > #endif > > +unsigned long _find_last_bit_from(const unsigned long *addr, unsigned long size, > + unsigned long offset) > +{ > + unsigned long val, idx, start_idx; > + > + if (unlikely(offset >= size)) > + return size; > + > + start_idx = offset / BITS_PER_LONG; > + idx = (size - 1) / BITS_PER_LONG; > + val = addr[idx] & BITMAP_LAST_WORD_MASK(size); > + > + while (!val && idx > start_idx) > + val = addr[--idx]; > + > + if (idx == start_idx) > + val &= BITMAP_FIRST_WORD_MASK(offset); > + > + return val ? idx * BITS_PER_LONG + __fls(val) : size; > +} > +EXPORT_SYMBOL(_find_last_bit_from); > + > unsigned long find_next_clump8(unsigned long *clump, const unsigned long *addr, > unsigned long size, unsigned long offset) > { > -- > 2.34.1