From nobody Wed Dec 17 23:50:59 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E57B4CE7A8B for ; Mon, 25 Sep 2023 02:38:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231818AbjIYCid (ORCPT ); Sun, 24 Sep 2023 22:38:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231792AbjIYCi3 (ORCPT ); Sun, 24 Sep 2023 22:38:29 -0400 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B286BD3 for ; Sun, 24 Sep 2023 19:38:23 -0700 (PDT) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-59f630612a4so25581757b3.1 for ; Sun, 24 Sep 2023 19:38:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609502; x=1696214302; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8Lu/kA1c3+diLAugHwidaQ6Q88eGZI3aXMjfNbZFH6g=; b=SibPS/DMFvDGC8QAPi9Lm4fZxJB9KR81gZL0dXke2sgf42ZaYjXekq6K7CLq/UfQmV txskI3d2zf5+Mk4DmreOHds8QcI34Xzsdvy9t/5zc17SoDLVYnmIGexMhqGmCgCuiArV mNLBXWPmUFlVxYOeM2fz7ShMyU72QKXOrRASyL5DsG7n3iP0rjoudOx+qqy2KxxjFifC AxrxGLZiLPp5PQz3k1XzYmO1CwDRTLrauLQxzaFpG0d5W5VWjbW3oTiZa0EzLwh52b8U TQiVJv+WhQviv4/vMrcr65FGtUESahUJ2qx5Wts3a6OY20pKzzdECeCANsP/dq8QRkSh qgKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609502; x=1696214302; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8Lu/kA1c3+diLAugHwidaQ6Q88eGZI3aXMjfNbZFH6g=; b=ndpTC5IFNjThXlf4yKLYtrsv00McNsgsPxB12Lo9uAHdqcnLEeYnwvyGSqCM5wCF72 lg9ECvNpo31uabZlgnrs9JHP16lAeEC/Rgr4Ik5TTFHL6MMXIS8Xs5U4uSc7jpGfFdtq rPVStZWRo1Xwc4CKNjJ/PhqfOQbpEqnXJSvKU2tp2K9bwx+/360Ay02Ro4j+2wSatkir fPAhmlhZ+sAjC61qPUbj9wuGsVkyERX3Bl9txKlIiNd1k8q4EsT1EpTH/Yqz6yr08yxD 2FpRy4BO2qm7mij4WJJeVgLXv09EGza3k/HrhVRPbZU9DoHZSEKv7RDE6oChwdT4KPNO hrDg== X-Gm-Message-State: AOJu0YwQVeJuIyO+EhqBAoENAgqSdAaQPqBJpHlhaJXLilpiL2UL1Eta lumXFCf9rrFUevS8d9WTuXxZt2Jr06Y= X-Google-Smtp-Source: AGHT+IHQd/WrqfIdFLXGrAqAPy6y5QVPvNmjXAkSfK5dgcJZr7kOsZiL67oHtVMav2M1V4MykbfzSQ== X-Received: by 2002:a81:91c1:0:b0:595:8499:c5f5 with SMTP id i184-20020a8191c1000000b005958499c5f5mr3283627ywg.26.1695609502416; Sun, 24 Sep 2023 19:38:22 -0700 (PDT) Received: from localhost ([2607:fb90:3eac:cd78:b6b5:ba0f:9e64:f2e1]) by smtp.gmail.com with ESMTPSA id w62-20020a0ded41000000b005837633d9cbsm2147869ywe.64.2023.09.24.19.38.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:38:22 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v5 1/8] bitmap: align __reg_op() wrappers with modern coding style Date: Sun, 24 Sep 2023 19:38:10 -0700 Message-Id: <20230925023817.782509-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925023817.782509-1-yury.norov@gmail.com> References: <20230925023817.782509-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Fix comments so that scripts/kernel-doc doesn't warn, and fix for-loop stype in bitmap_find_free_region(). Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Yury Norov --- lib/bitmap.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index ddb31015e38a..421f2fc384f4 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1234,8 +1234,8 @@ void bitmap_fold(unsigned long *dst, const unsigned l= ong *orig, * some size '1 << order' (a power of two), aligned to that same * '1 << order' power of two. * - * Returns 1 if REG_OP_ISFREE succeeds (region is all zero bits). - * Returns 0 in all other cases and reg_ops. + * Return: 1 if REG_OP_ISFREE succeeds (region is all zero bits). + * 0 in all other cases and reg_ops. */ =20 enum { @@ -1307,14 +1307,14 @@ static int __reg_op(unsigned long *bitmap, unsigned= int pos, int order, int reg_ * a power (@order) of two, aligned to that power of two, which * makes the search algorithm much faster. * - * Return the bit offset in bitmap of the allocated region, + * Return: the bit offset in bitmap of the allocated region, * or -errno on failure. */ int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int = order) { unsigned int pos, end; /* scans bitmap by regions of size order */ =20 - for (pos =3D 0 ; (end =3D pos + (1U << order)) <=3D bits; pos =3D end) { + for (pos =3D 0; (end =3D pos + BIT(order)) <=3D bits; pos =3D end) { if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE)) continue; __reg_op(bitmap, pos, order, REG_OP_ALLOC); @@ -1332,8 +1332,6 @@ EXPORT_SYMBOL(bitmap_find_free_region); * * This is the complement to __bitmap_find_free_region() and releases * the found region (by clearing it in the bitmap). - * - * No return value. */ void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int or= der) { @@ -1349,7 +1347,7 @@ EXPORT_SYMBOL(bitmap_release_region); * * Allocate (set bits in) a specified region of a bitmap. * - * Return 0 on success, or %-EBUSY if specified region wasn't + * Return: 0 on success, or %-EBUSY if specified region wasn't * free (not all bits were zero). */ int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int or= der) --=20 2.39.2 From nobody Wed Dec 17 23:50:59 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B50FFCE7A95 for ; Mon, 25 Sep 2023 02:38:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231834AbjIYCif (ORCPT ); Sun, 24 Sep 2023 22:38:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231801AbjIYCib (ORCPT ); Sun, 24 Sep 2023 22:38:31 -0400 Received: from mail-yw1-x1132.google.com (mail-yw1-x1132.google.com [IPv6:2607:f8b0:4864:20::1132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 935CDE3 for ; Sun, 24 Sep 2023 19:38:25 -0700 (PDT) Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-59c215f2f4aso68791287b3.1 for ; Sun, 24 Sep 2023 19:38:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609504; x=1696214304; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XE9w3X9nRbA61NQ0LUWkuYmpD2CnPoV900gbsiWlryQ=; b=Q/jhw3F3ytD9Zjj1S9Xy66DAPkOQNemYrKgTjpIsd0C+oM4663njBNQUMEMrWl6mvu KsxLyK1K076wUcaPb1/X84Mnf5IZasRrBnefnhuyPRwVzQNnoaDclEsWG5pr8geLqH1L DjCd0OT4ImJhR4mbNjrc4DOlZSAH+SVBrJNULS1w1hgBtZ4rROpQPxpHcF07eXmpzw5W zqcx9u5lgwaCkyt44ahYjaBr/8P8BjhjvWwCoGXyIkA+ss7KRCPu5U5AaV8xBFKsUYRP Y2j9ebOpqI8NeAR8CRT+6dcG183nowBMTCVUoumlq3IpM59K7biPK+ywk8Eq3I81njFP RRtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609504; x=1696214304; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XE9w3X9nRbA61NQ0LUWkuYmpD2CnPoV900gbsiWlryQ=; b=ocSWcLripMy6or0eaRSRvlX5sP+YgktXh9nUt/wVjShvL5+Zb7MPBaq2naVrWb5NEb 9XubNAL0YIyBtAL6MZ2hHPz/dzJHeq+qMPiexxQw4F8QA47lZmaZ1FsBt8FrlcIDesNz Eoh/jp89C4QwuX4PMHkVc6yoow3HDra9FHB9Gn3gvoccDPRD1V+3+pEAz7U8zHkvVNrX VKOQ+nn3UWOTgqe3gXjWtueaoy3qMCDQ7IrTKKy291dOtbxpbc8btOtzFUsSvnW4EKKP gRNCVd3T/8avWOgpR5TiGM1SwCr/iGMmcoJAesZY02uo5HO+gkuEYUgpnk7Q1PF1xnw/ hAsw== X-Gm-Message-State: AOJu0YzQj8qZbfVKyCGW5XP70bfM5m2PmGFlAQxm1IRNjL+syXWaL9eI NNqLplS8dkx/bDtgtMB4Yy3zZ+qeq5k= X-Google-Smtp-Source: AGHT+IGzF4Q7w98WjuHf0tgASXy0SRNIfARuuIlexi27LF7C4ROdp4ixnd+y6KocnavMVTVdXvGfoQ== X-Received: by 2002:a0d:c781:0:b0:59c:aea:d877 with SMTP id j123-20020a0dc781000000b0059c0aead877mr4251199ywd.40.1695609504328; Sun, 24 Sep 2023 19:38:24 -0700 (PDT) Received: from localhost ([2607:fb90:3eac:cd78:b6b5:ba0f:9e64:f2e1]) by smtp.gmail.com with ESMTPSA id c188-20020a0df3c5000000b0059293c8d70csm2182806ywf.132.2023.09.24.19.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:38:24 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v5 2/8] bitmap: add test for bitmap_*_region() functions Date: Sun, 24 Sep 2023 19:38:11 -0700 Message-Id: <20230925023817.782509-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925023817.782509-1-yury.norov@gmail.com> References: <20230925023817.782509-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Test basic functionality of bitmap_{allocate,release,find_free}_region() functions. Reviewed-by: Andy Shevchenko Signed-off-by: Yury Norov --- lib/test_bitmap.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index f2ea9f30c7c5..65f22c2578b0 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -330,6 +330,29 @@ static void __init test_copy(void) expect_eq_pbl("0-108,128-1023", bmap2, 1024); } =20 +static void __init test_bitmap_region(void) +{ + int pos, order; + + DECLARE_BITMAP(bmap, 1000); + + bitmap_zero(bmap, 1000); + + for (order =3D 0; order < 10; order++) { + pos =3D bitmap_find_free_region(bmap, 1000, order); + if (order =3D=3D 0) + expect_eq_uint(pos, 0); + else + expect_eq_uint(pos, order < 9 ? BIT(order) : -ENOMEM); + } + + bitmap_release_region(bmap, 0, 0); + for (order =3D 1; order < 9; order++) + bitmap_release_region(bmap, BIT(order), order); + + expect_eq_uint(bitmap_weight(bmap, 1000), 0); +} + #define EXP2_IN_BITS (sizeof(exp2) * 8) =20 static void __init test_replace(void) @@ -1227,6 +1250,7 @@ static void __init selftest(void) test_zero_clear(); test_fill_set(); test_copy(); + test_bitmap_region(); test_replace(); test_bitmap_arr32(); test_bitmap_arr64(); --=20 2.39.2 From nobody Wed Dec 17 23:50:59 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DE98CE7A8B for ; Mon, 25 Sep 2023 02:38:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231881AbjIYCik (ORCPT ); Sun, 24 Sep 2023 22:38:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231824AbjIYCie (ORCPT ); Sun, 24 Sep 2023 22:38:34 -0400 Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1614AE3 for ; Sun, 24 Sep 2023 19:38:27 -0700 (PDT) Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-59bc956b029so65523557b3.2 for ; Sun, 24 Sep 2023 19:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609506; x=1696214306; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FCnx4Q0U1bWkD4Ey4yVXOeEthgG/6U2DrPecvVm9aaU=; b=AD7KcBZOJNn5Uh+dOGb+nwfML0NTwgblZ+/qA/KtEpBtpNYAR4XjTbpS696piwZGnb vhKAALu+T3w5YBfLhla6Lu2TpvS1JJNfLhdyWgcx6to86v3a3tm6fs42avJpTCJ0xGS+ 8O3Q3o5ZTkvMkimPGstKA6AdTxo0/gXUnOF9/aTspuumBq+va+frFadb/Iv7I8Iv9In5 1VK5JvRIvedkPOWwA69ThGAdmVvxVgNdxR8cUkwd2clsfjZWMXYFIHmA43/dF2P7RQ6g Q/o9mluvkCVXAO7KX8yxMUDTdWNfydDoFy9XXHg2/w6L58e2b8SFOTp83+verhmVH0d4 M/4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609506; x=1696214306; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FCnx4Q0U1bWkD4Ey4yVXOeEthgG/6U2DrPecvVm9aaU=; b=lJY0tVopqu1f3saQhkDdYvgprJbZPxgYNwyCjKG0F+SIpKkGqpnuDVci39+s0KSKmy vIsM/WlLIlsR2qKLaEZS6mvH1Y1IkFufjD/ldMZSdZVeizQA3yOPYtms8EhURACLcXLh 1K5963dnfhBmj1dgy0ZzBxL7bRl1QciXrqSxhoUJ19SATfxl+SovaY0KS22mRHqyFLAz IGUVtZALuUEh4gTWAXTNbcWEkmRPsX6yXr+i18I9+7/wbZ4/h2f00gpzSm8LjnM2D5Vu C7GJ9NPu9H8I4hzasMKWGKmqTPDA9EE0fKA0lc07ihSnwsqKqXQxz9xhaBxI3hPuSu4E FfGQ== X-Gm-Message-State: AOJu0YwYYN8jnnWfZvpw4emf6kECs74sr22AtVg83xnJvriFltB+puhp Opk50DtqHjHbHNNX97Vr9Sua1D2kL3Y= X-Google-Smtp-Source: AGHT+IGxbMojuQk5LyFWvPbjY6wLmYFRlQk4J1JgMzhLjvw7soYqY5b0qphGC88Sbm5e7YmHQoIC4w== X-Received: by 2002:a05:690c:3104:b0:59f:672a:ffd3 with SMTP id fb4-20020a05690c310400b0059f672affd3mr2385361ywb.21.1695609505916; Sun, 24 Sep 2023 19:38:25 -0700 (PDT) Received: from localhost ([2607:fb90:3eac:cd78:b6b5:ba0f:9e64:f2e1]) by smtp.gmail.com with ESMTPSA id t17-20020a818311000000b00589dbcf16cbsm2182481ywf.35.2023.09.24.19.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:38:25 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v5 3/8] bitmap: fix opencoded bitmap_allocate_region() Date: Sun, 24 Sep 2023 19:38:12 -0700 Message-Id: <20230925023817.782509-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925023817.782509-1-yury.norov@gmail.com> References: <20230925023817.782509-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" bitmap_find_region() opencodes bitmap_allocate_region(). Signed-off-by: Yury Norov --- lib/bitmap.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index 421f2fc384f4..cb77b6b0e5e0 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1315,10 +1315,8 @@ int bitmap_find_free_region(unsigned long *bitmap, u= nsigned int bits, int order) unsigned int pos, end; /* scans bitmap by regions of size order */ =20 for (pos =3D 0; (end =3D pos + BIT(order)) <=3D bits; pos =3D end) { - if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE)) - continue; - __reg_op(bitmap, pos, order, REG_OP_ALLOC); - return pos; + if (!bitmap_allocate_region(bitmap, pos, order)) + return pos; } return -ENOMEM; } --=20 2.39.2 From nobody Wed Dec 17 23:50:59 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B445CCE7A94 for ; Mon, 25 Sep 2023 02:38:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231775AbjIYCin (ORCPT ); Sun, 24 Sep 2023 22:38:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231844AbjIYCij (ORCPT ); Sun, 24 Sep 2023 22:38:39 -0400 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC80010C for ; Sun, 24 Sep 2023 19:38:28 -0700 (PDT) Received: by mail-yb1-xb34.google.com with SMTP id 3f1490d57ef6-d867acf14aeso2962075276.1 for ; Sun, 24 Sep 2023 19:38:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609507; x=1696214307; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j2/iJp7YEu8PdZMEKuCIEse1RbUYsD5fSdjQh+4BcHk=; b=NtbkgJiVXkxa5m4QMqJ+LE7r/IMz2j+MPCXDH5+R2ZbD7ZAvDVe/11vpaR8DZKX7/x CJ5RHLbuFOU4h4lNVlTtdLePWgph0NNFd5/NidOVpMTm9IGZlrQETf+VN5Q0rh8DxsLQ XjvVo1SANZRCwX7pjBTZQpTE467UqBf/Az8Cd0xoZ9MsSAxwrosiFQrJrNne09WJQz3O y1opvf2iopJN+UVpsZ7Pub2ob98qiouXy5trxtJNLObju6mLYAHuy0n4NVhrWVlmMBx+ lYUAoznPC/2UpD+S7B+2V7DKNT3x1KPc8CdAHiekHBEEeSbFNf75hva4nKxoCT3gihu/ 231A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609507; x=1696214307; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j2/iJp7YEu8PdZMEKuCIEse1RbUYsD5fSdjQh+4BcHk=; b=kJZGV3UyWyEojrPtfcuKug8LFlUeRIvpMUrohAMsBu9L7kaoaa4+bnfuuYuOpX0bLi L0g4EABMhTm6rVgZ3THg0fE7FJsrc0DmiVJ11DpAflBYyCfflqNO+Qu1zZVgXQAMeZks 25XenBaLb1w3eibPE6JsVqC6HuZ4hAbz+oPPY1pYFGAkOlWFpr+TRuJzQfYizYYu6RT7 l2XmPHPU/aB5r9vNmJa2DyB1Zm9Aos6r0txsoWuiS60ZoztvnkeFx0ZIB7nARrIpuMDF WoMbNMCfHll7WoQ0mSq+ndfkzsOx2Ayj+Ss2/kcgtAhhiv7x7uoqZkNzpXVFt/HVWjYK egSQ== X-Gm-Message-State: AOJu0YyKA7t+HdPX0tgwSw57Zzyw9uYwXn6+gimwjpsW2nzx9liiaffC 7eGQTTOatLWxfuzbUxVXacMBh6Qcm7k= X-Google-Smtp-Source: AGHT+IECTl2sgU+j7IFSg6WmIHV60AB8YagBC945Ygd7a+AfT25UcyZXW/nes8sm96kOdINx9U6FMQ== X-Received: by 2002:a25:aae9:0:b0:d86:66fc:eb19 with SMTP id t96-20020a25aae9000000b00d8666fceb19mr3600356ybi.19.1695609507450; Sun, 24 Sep 2023 19:38:27 -0700 (PDT) Received: from localhost ([2607:fb90:3eac:cd78:b6b5:ba0f:9e64:f2e1]) by smtp.gmail.com with ESMTPSA id q7-20020a5b0f87000000b00d749efa85a1sm1921876ybh.41.2023.09.24.19.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:38:27 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v5 4/8] bitmap: replace _reg_op(REG_OP_ALLOC) with bitmap_set() Date: Sun, 24 Sep 2023 19:38:13 -0700 Message-Id: <20230925023817.782509-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925023817.782509-1-yury.norov@gmail.com> References: <20230925023817.782509-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" _reg_op(REG_OP_ALLOC) duplicates bitmap_set(). Signed-off-by: Yury Norov --- lib/bitmap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index cb77b6b0e5e0..a463125560c3 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1350,9 +1350,12 @@ EXPORT_SYMBOL(bitmap_release_region); */ int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int or= der) { + unsigned int len =3D BIT(order); + if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE)) return -EBUSY; - return __reg_op(bitmap, pos, order, REG_OP_ALLOC); + bitmap_set(bitmap, pos, len); + return 0; } EXPORT_SYMBOL(bitmap_allocate_region); =20 --=20 2.39.2 From nobody Wed Dec 17 23:50:59 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2A43CE7A91 for ; Mon, 25 Sep 2023 02:38:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231905AbjIYCio (ORCPT ); Sun, 24 Sep 2023 22:38:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231862AbjIYCik (ORCPT ); Sun, 24 Sep 2023 22:38:40 -0400 Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FB2A136 for ; Sun, 24 Sep 2023 19:38:30 -0700 (PDT) Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-59c0d329a8bso65663907b3.1 for ; Sun, 24 Sep 2023 19:38:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609509; x=1696214309; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JJbsnopL5cu7DbnphUxyfvgHw2IoJrSW0tHSHF1oQbU=; b=Ztf+/RBK7/DfdKM716gDLwSs7CfJLsddLx3RMIR81Xu+HZvJj9IInORX4iMZfcGOv+ URdbHltuvT4vKu2lNMfIorJcL6Hfup+ZQEGIhkPhZfJ7g375YdTte/rUE7bVnYsvWHTx p3IvWe3wS4zNA1ktV1a8uOvHsOJUc+mvG8HkIiX1XGAWu8pFqVGpZ9qhrK0sQQYq7QaQ WHxNwVZ1zbKoqYNfVsVwksqfgXwXjHKhBunZF7hbmFQaMld8ttNKhE1B0F9iq2wIk/uu g/j9UfejLRRR/7xNlnSRidbqBhxgr7Blc6gvI1nJonPZprtnuyYsVMfTuNWlW2NATbY2 o+nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609509; x=1696214309; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JJbsnopL5cu7DbnphUxyfvgHw2IoJrSW0tHSHF1oQbU=; b=xHNTDMRCYA4qx0t+2XDadJALWYScMDMCAnP6SeBQ8LXzFuQC2hsvD/gOtfRSJHjAiP L8ccJrEt7Yi2VtTY65yxNJj/nrvaYBcGGIcUGuMkm0hkzCxmeGiAj8O06/UKdxnMU9R0 pBQmlgY1B6Xjj8Cv5Qs3yIeZmP5S1yK4RW84DozrB292fC5NdPb0LFStfcy7TGtwvckF lHKjg3+mU62q4404Tbe6cC0Y0pP/AZL3BCaAMhQuT15NGZH3aAeFKSq+aNUN7i2By7yA TXt9je1hYOTO7WSETympOMqukqO3DB07UrpSZgg3PEw4FvutEjoxYwEgYJM8YMYrnBuz w4rg== X-Gm-Message-State: AOJu0Yzrkvy/X/4WG48ZD/r4XDKqdpd8XpGDrfCLp8u5iVnGS6eiNq/U +pojydbAvcqLIGKI1+1Gjw7q28u5BGE= X-Google-Smtp-Source: AGHT+IHEdvAHT1bH+ey90Nwlvx2NR/b9T3G43eoC61WsR2z3FZurWPVSOhy2dPnRIRlNZotV9PHkNg== X-Received: by 2002:a81:4958:0:b0:592:97c3:18d2 with SMTP id w85-20020a814958000000b0059297c318d2mr5260261ywa.15.1695609509188; Sun, 24 Sep 2023 19:38:29 -0700 (PDT) Received: from localhost ([2607:fb90:3eac:cd78:b6b5:ba0f:9e64:f2e1]) by smtp.gmail.com with ESMTPSA id i69-20020a819148000000b005869f734036sm2173971ywg.19.2023.09.24.19.38.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:38:28 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v5 5/8] bitmap: replace _reg_op(REG_OP_RELEASE) with bitmap_clear() Date: Sun, 24 Sep 2023 19:38:14 -0700 Message-Id: <20230925023817.782509-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925023817.782509-1-yury.norov@gmail.com> References: <20230925023817.782509-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" _reg_op(REG_OP_RELEASE) duplicates bitmap_clear(). Signed-off-by: Yury Norov --- lib/bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index a463125560c3..4dba15f2e970 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1333,7 +1333,7 @@ EXPORT_SYMBOL(bitmap_find_free_region); */ void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int or= der) { - __reg_op(bitmap, pos, order, REG_OP_RELEASE); + bitmap_clear(bitmap, pos, BIT(order)); } EXPORT_SYMBOL(bitmap_release_region); =20 --=20 2.39.2 From nobody Wed Dec 17 23:50:59 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00711CE7A8B for ; Mon, 25 Sep 2023 02:38:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231883AbjIYCiv (ORCPT ); Sun, 24 Sep 2023 22:38:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231872AbjIYCik (ORCPT ); Sun, 24 Sep 2023 22:38:40 -0400 Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 581401A5 for ; Sun, 24 Sep 2023 19:38:32 -0700 (PDT) Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-59bebd5bdadso66411917b3.0 for ; Sun, 24 Sep 2023 19:38:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609511; x=1696214311; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q5XEvYirztCmygWgA/YyclPRF8/aR4iz+4trJcZQ1vs=; b=Z1lzMyTdLTGVjUpL1AU94XTKABwqKLX7oujhYDXtiKUiHAmDO21DkkCpltRHJN3Y5b qLYnoZ7T168q+GQmrOmHeeIMVt3lIdjpXRSTFmM2pHQYQrib8tYI3kOa6f/XiOut/L6L ClBdoqzQ1nZD01VLXGEkCvT5geHHtIHgfBaXK7O7vBNQ6VDGZKilv9El695btJykonLV +VMBkcYc4+TQOGce/KHaRM3fO0iOyUSSIpHiuFxJ9pa4vVxogiDN4WtO2ux1QIyy9c/d da2ObZULoQ7oXARvW3oFDLAfoX71rrGTA92xHO1BC26HDNqlPjkLUqGDADklHKp+UHjK jmxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609511; x=1696214311; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q5XEvYirztCmygWgA/YyclPRF8/aR4iz+4trJcZQ1vs=; b=b/vkrw5U0X7cikOP12puC3gjrFQOmWUhB2vzTQrvqX3hS75MmeOKlrJi6fkLnZTm3c F5MlBlMi9G+YcXkCwR+EGgpJ+q9342xFIhtmfo2YfI+I4h/rKR89wHV7WQ1ahnNoRqKS GgxRU4QjjmrVgaVJoETDdLFNPOKDqZYPurF2UDQXkCooHTs+VNoY5v5ntZrsKNPp3MMV euyw6fRWLR03qwv7n6O65X5uR+K/a5KXBcgsOUOE6vMaiYrQ8EQprv+Di4NtSIwJccGC lUBCmrjqb/8/PgBWYStBiuZTRdPcnz879/qBEl0MQHVZQIP4Y5QeOiBmi4twdUZzkrZV xyWQ== X-Gm-Message-State: AOJu0YxXt7sRM6N7fNGldWjtxOjHb7Lh2FElW5IL3oAImdfh97bkZAyp Lkpx36EKQ7C01z4RmJRlB1jX6YF3XZE= X-Google-Smtp-Source: AGHT+IF0GHcs1mVP2hs9Qn4EFWSTl2IaQvlt9Ej6mQTI05TqIPT1Yd/nQgbjSvbJoEGgWE7w1u1eZg== X-Received: by 2002:a05:690c:3685:b0:59f:4c3a:711d with SMTP id fu5-20020a05690c368500b0059f4c3a711dmr5181430ywb.11.1695609510977; Sun, 24 Sep 2023 19:38:30 -0700 (PDT) Received: from localhost ([2607:fb90:3eac:cd78:b6b5:ba0f:9e64:f2e1]) by smtp.gmail.com with ESMTPSA id w62-20020a0ded41000000b005837633d9cbsm2147926ywe.64.2023.09.24.19.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:38:30 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v5 6/8] bitmap: replace _reg_op(REG_OP_ISFREE) with find_next_bit() Date: Sun, 24 Sep 2023 19:38:15 -0700 Message-Id: <20230925023817.782509-7-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925023817.782509-1-yury.norov@gmail.com> References: <20230925023817.782509-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" _reg_op(REG_OP_ISFREE) can be trivially replaced with find_next_bit(). Doing that opens room for potential small_const_nbits() optimization. Signed-off-by: Yury Norov --- lib/bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index 4dba15f2e970..9345a6ffe39d 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1352,7 +1352,7 @@ int bitmap_allocate_region(unsigned long *bitmap, uns= igned int pos, int order) { unsigned int len =3D BIT(order); =20 - if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE)) + if (find_next_bit(bitmap, pos + len, pos) < pos + len) return -EBUSY; bitmap_set(bitmap, pos, len); return 0; --=20 2.39.2 From nobody Wed Dec 17 23:50:59 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A8D7CE7A91 for ; Mon, 25 Sep 2023 02:38:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231983AbjIYCjC (ORCPT ); Sun, 24 Sep 2023 22:39:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231812AbjIYCil (ORCPT ); Sun, 24 Sep 2023 22:38:41 -0400 Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E56ECC2 for ; Sun, 24 Sep 2023 19:38:33 -0700 (PDT) Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-59c0d329a8bso65664497b3.1 for ; Sun, 24 Sep 2023 19:38:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609513; x=1696214313; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=USSwqheS6xjeGLXrIzVAWyRVvgy5mA+TT5DY1kqnK10=; b=OoEMze3KpYE6JRaLsxCH2NT8kHMDu2O7ghGLEYlgZF7BkkAapwkg13kvJNwpw6q7YW TKhLsBcppyjvKvwHPwuAaOACkcfS+1rRw07FuawZlRIO+uF9BCFk/fLuzfWyf7ErrSHf 3RxZiyEbKgo5EC3JPT9ZwT544IX8SDaCcBvDs2X3lxdRgswIWtPzuCu3/zbEoZo/Mk32 j+Dzkg/CYyhMZVRPTvrnwAwToUH/dmA0Y3dZT1pMe2GPVGtbKYeqSfIsV1pSvKQzUEEX P0E8JzlgyRQGqvL4H5QuXJk7mhnjHJegUDUT1RBPXl15nBR+ouemKUQEqAk7E4VGKskF 5vKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609513; x=1696214313; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=USSwqheS6xjeGLXrIzVAWyRVvgy5mA+TT5DY1kqnK10=; b=lcWqDCmaL59A+Q4iZKQd6Rp1kzgbMJda3rlGkpyVsMTJAkVAsrtu8Fg4dWYg4Ku6jE ch3+pJ/zOhYgRyV8CU90TZ0CxSUPiV8oFqY38hidfiQfw/8eKvW+IiloIv3h6HGA6W3s oCwD2s1rTwsbPvsvVL265FHnXFZxvhcQHRKCiVfKzk32vEXdahvvlZG0mNSw22bEcSD/ P2JFI+nacn6K4ROb3gjsdL9NkCK06Rsu+PMSLtJvYgVA60YIIX/1hOtefUn08tmef7mT YXt5LmiOJmt+GlnhoPSTBuwP8ui18cAcUIXt1kN8bmUVzHgEB6SxAWyJT0XnVfF3qa1+ muig== X-Gm-Message-State: AOJu0YwVPEBPyYSqo1ztVKgALG1TSG33D3JnU3wBMivByUlMAJH9FV4I BMVbVMIS4RBzt3ztLKTf4L3ePI16T1k= X-Google-Smtp-Source: AGHT+IGoUFXhlCGy2AGMzphXLvIo8Wswri6KOjhVXNBCobsN1nQ7IxIsPyXt4KQxyGfFufKxJPnpIQ== X-Received: by 2002:a81:7b44:0:b0:570:7b4d:f694 with SMTP id w65-20020a817b44000000b005707b4df694mr5081345ywc.3.1695609512710; Sun, 24 Sep 2023 19:38:32 -0700 (PDT) Received: from localhost ([2607:fb90:3eac:cd78:b6b5:ba0f:9e64:f2e1]) by smtp.gmail.com with ESMTPSA id k128-20020a816f86000000b00583803487ccsm2177190ywc.122.2023.09.24.19.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:38:32 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v5 7/8] bitmap: drop _reg_op() function Date: Sun, 24 Sep 2023 19:38:16 -0700 Message-Id: <20230925023817.782509-8-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925023817.782509-1-yury.norov@gmail.com> References: <20230925023817.782509-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Now that all _reg_op() users are switched to alternative functions, _reg_op() machinery is not needed anymore. Signed-off-by: Yury Norov --- lib/bitmap.c | 76 ---------------------------------------------------- 1 file changed, 76 deletions(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index 9345a6ffe39d..cc6180dd6254 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1220,82 +1220,6 @@ void bitmap_fold(unsigned long *dst, const unsigned = long *orig, } #endif /* CONFIG_NUMA */ =20 -/* - * Common code for bitmap_*_region() routines. - * bitmap: array of unsigned longs corresponding to the bitmap - * pos: the beginning of the region - * order: region size (log base 2 of number of bits) - * reg_op: operation(s) to perform on that region of bitmap - * - * Can set, verify and/or release a region of bits in a bitmap, - * depending on which combination of REG_OP_* flag bits is set. - * - * A region of a bitmap is a sequence of bits in the bitmap, of - * some size '1 << order' (a power of two), aligned to that same - * '1 << order' power of two. - * - * Return: 1 if REG_OP_ISFREE succeeds (region is all zero bits). - * 0 in all other cases and reg_ops. - */ - -enum { - REG_OP_ISFREE, /* true if region is all zero bits */ - REG_OP_ALLOC, /* set all bits in region */ - REG_OP_RELEASE, /* clear all bits in region */ -}; - -static int __reg_op(unsigned long *bitmap, unsigned int pos, int order, in= t reg_op) -{ - int nbits_reg; /* number of bits in region */ - int index; /* index first long of region in bitmap */ - int offset; /* bit offset region in bitmap[index] */ - int nlongs_reg; /* num longs spanned by region in bitmap */ - int nbitsinlong; /* num bits of region in each spanned long */ - unsigned long mask; /* bitmask for one long of region */ - int i; /* scans bitmap by longs */ - int ret =3D 0; /* return value */ - - /* - * Either nlongs_reg =3D=3D 1 (for small orders that fit in one long) - * or (offset =3D=3D 0 && mask =3D=3D ~0UL) (for larger multiword orders.) - */ - nbits_reg =3D 1 << order; - index =3D pos / BITS_PER_LONG; - offset =3D pos - (index * BITS_PER_LONG); - nlongs_reg =3D BITS_TO_LONGS(nbits_reg); - nbitsinlong =3D min(nbits_reg, BITS_PER_LONG); - - /* - * Can't do "mask =3D (1UL << nbitsinlong) - 1", as that - * overflows if nbitsinlong =3D=3D BITS_PER_LONG. - */ - mask =3D (1UL << (nbitsinlong - 1)); - mask +=3D mask - 1; - mask <<=3D offset; - - switch (reg_op) { - case REG_OP_ISFREE: - for (i =3D 0; i < nlongs_reg; i++) { - if (bitmap[index + i] & mask) - goto done; - } - ret =3D 1; /* all bits in region free (zero) */ - break; - - case REG_OP_ALLOC: - for (i =3D 0; i < nlongs_reg; i++) - bitmap[index + i] |=3D mask; - break; - - case REG_OP_RELEASE: - for (i =3D 0; i < nlongs_reg; i++) - bitmap[index + i] &=3D ~mask; - break; - } -done: - return ret; -} - /** * bitmap_find_free_region - find a contiguous aligned mem region * @bitmap: array of unsigned longs corresponding to the bitmap --=20 2.39.2 From nobody Wed Dec 17 23:50:59 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2E49CE7A91 for ; Mon, 25 Sep 2023 02:39:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232034AbjIYCjL (ORCPT ); Sun, 24 Sep 2023 22:39:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231928AbjIYCiw (ORCPT ); Sun, 24 Sep 2023 22:38:52 -0400 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90B3F10B for ; Sun, 24 Sep 2023 19:38:36 -0700 (PDT) Received: by mail-yb1-xb31.google.com with SMTP id 3f1490d57ef6-d868d8363e6so2154086276.2 for ; Sun, 24 Sep 2023 19:38:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695609514; x=1696214314; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jMPtW3pZJxX1hohu3538oy2bndPs8CNuEF5Ud1QaLi0=; b=Y8OEr0O5w+oWE2/XFTJ50v+ShoM5FnB43Y+gyj17GBRlRiFssUqeu1F7RLoqiX4cCo PJV6bXlRyANinbbxuw8UzVOfVWAYAcKRNMnjVAtQLhPZMAMRJJVFHUd3spcS+lYbW2sy RlxC2ZquIAZ9dzlL+B/6laAbpNI9Dr99rOYdvpqXnM64UL9TtSQe7eBjbUUGMVFOWoIa Z9Qfa+/taQZhCIh6T4VH9jAKpYt4C4fTGqNFjKIDD3CeMRwoYyIbUWlxq9wRp1AOMG0I Q+tKVNNVRSpfuR+8pFA8ThoiGYeIG+pO9O5uS3OU+kINhqQXpTwWsa8ksXszO8qsfmJT 20FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695609514; x=1696214314; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jMPtW3pZJxX1hohu3538oy2bndPs8CNuEF5Ud1QaLi0=; b=DjnVaqWSyJHfKriagn8gTGg/HZgcsV/zC3+/gFVk30h9+26vaa/ENavIJbMWE5Yyhc FXds/NXi2zuLV9kGq9/uynLMimBwX9wAgY/ouo8Jwrjy7ed7XG6rfGkyk7DX3BHzEJAt XwolmE7DiMAeLN5L6e1NNOOhzUJoNnjeZ+ahnmV5Vfd2yOecO9RvBSJ48beBGN1DNoW8 eVeeyt+3IkN30h0kh7HRT4ii0qAfc3+JeRzuB1ZGj5SAINNVUYIT+adMBHDM/j4bE/W7 HA/CJ8U0g2lHC4hOOY2FwcglGIpI6afBVrKDtrMeuDa/9OcPp1cQb30r6+TnkMJVR+sE WGcA== X-Gm-Message-State: AOJu0YwBLjoLfjKyttY725W2CKIDNJ+kCg7jzNEluklAmfl4IkCOPIyV hgSjDa/QPqy4qyivA0y1QoyE2RRMpjo= X-Google-Smtp-Source: AGHT+IHKFslh6mrWbC67+VZpVB15LCSjaxV0XuIa5bWEBKeTkcKBVLlw7tHduMoMH4KcrkbwUCnx3Q== X-Received: by 2002:a25:e082:0:b0:d81:41b1:448c with SMTP id x124-20020a25e082000000b00d8141b1448cmr4954181ybg.43.1695609514332; Sun, 24 Sep 2023 19:38:34 -0700 (PDT) Received: from localhost ([2607:fb90:3eac:cd78:b6b5:ba0f:9e64:f2e1]) by smtp.gmail.com with ESMTPSA id v3-20020a25c503000000b00d814d8dfd69sm2001110ybe.27.2023.09.24.19.38.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 19:38:34 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v5 8/8] bitmap: move bitmap_*_region() functions to bitmap.h Date: Sun, 24 Sep 2023 19:38:17 -0700 Message-Id: <20230925023817.782509-9-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925023817.782509-1-yury.norov@gmail.com> References: <20230925023817.782509-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Now that bitmap_*_region() functions are implemented as thin wrappers around others, it's worth to move them to the header, as it opens room for compile-time optimizations. Signed-off-by: Yury Norov --- include/linux/bitmap.h | 63 ++++++++++++++++++++++++++++++++++++++++-- lib/bitmap.c | 63 ------------------------------------------ 2 files changed, 60 insertions(+), 66 deletions(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 03644237e1ef..9b097f83d785 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -216,9 +216,6 @@ void bitmap_onto(unsigned long *dst, const unsigned lon= g *orig, const unsigned long *relmap, unsigned int bits); void bitmap_fold(unsigned long *dst, const unsigned long *orig, unsigned int sz, unsigned int nbits); -int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int = order); -void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int or= der); -int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int or= der); =20 #ifdef __BIG_ENDIAN void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned= int nbits); @@ -518,6 +515,66 @@ static inline void bitmap_next_set_region(unsigned lon= g *bitmap, *re =3D find_next_zero_bit(bitmap, end, *rs + 1); } =20 +/** + * bitmap_release_region - release allocated bitmap region + * @bitmap: array of unsigned longs corresponding to the bitmap + * @pos: beginning of bit region to release + * @order: region size (log base 2 of number of bits) to release + * + * This is the complement to __bitmap_find_free_region() and releases + * the found region (by clearing it in the bitmap). + */ +static inline void bitmap_release_region(unsigned long *bitmap, unsigned i= nt pos, int order) +{ + bitmap_clear(bitmap, pos, BIT(order)); +} + +/** + * bitmap_allocate_region - allocate bitmap region + * @bitmap: array of unsigned longs corresponding to the bitmap + * @pos: beginning of bit region to allocate + * @order: region size (log base 2 of number of bits) to allocate + * + * Allocate (set bits in) a specified region of a bitmap. + * + * Returns: 0 on success, or %-EBUSY if specified region wasn't + * free (not all bits were zero). + */ +static inline int bitmap_allocate_region(unsigned long *bitmap, unsigned i= nt pos, int order) +{ + unsigned int len =3D BIT(order); + + if (find_next_bit(bitmap, pos + len, pos) < pos + len) + return -EBUSY; + bitmap_set(bitmap, pos, len); + return 0; +} + +/** + * bitmap_find_free_region - find a contiguous aligned mem region + * @bitmap: array of unsigned longs corresponding to the bitmap + * @bits: number of bits in the bitmap + * @order: region size (log base 2 of number of bits) to find + * + * Find a region of free (zero) bits in a @bitmap of @bits bits and + * allocate them (set them to one). Only consider regions of length + * a power (@order) of two, aligned to that power of two, which + * makes the search algorithm much faster. + * + * Returns: the bit offset in bitmap of the allocated region, + * or -errno on failure. + */ +static inline int bitmap_find_free_region(unsigned long *bitmap, unsigned = int bits, int order) +{ + unsigned int pos, end; /* scans bitmap by regions of size order */ + + for (pos =3D 0; (end =3D pos + BIT(order)) <=3D bits; pos =3D end) { + if (!bitmap_allocate_region(bitmap, pos, order)) + return pos; + } + return -ENOMEM; +} + /** * BITMAP_FROM_U64() - Represent u64 value in the format suitable for bitm= ap. * @n: u64 value diff --git a/lib/bitmap.c b/lib/bitmap.c index cc6180dd6254..1c5d1f5d2071 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1220,69 +1220,6 @@ void bitmap_fold(unsigned long *dst, const unsigned = long *orig, } #endif /* CONFIG_NUMA */ =20 -/** - * bitmap_find_free_region - find a contiguous aligned mem region - * @bitmap: array of unsigned longs corresponding to the bitmap - * @bits: number of bits in the bitmap - * @order: region size (log base 2 of number of bits) to find - * - * Find a region of free (zero) bits in a @bitmap of @bits bits and - * allocate them (set them to one). Only consider regions of length - * a power (@order) of two, aligned to that power of two, which - * makes the search algorithm much faster. - * - * Return: the bit offset in bitmap of the allocated region, - * or -errno on failure. - */ -int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int = order) -{ - unsigned int pos, end; /* scans bitmap by regions of size order */ - - for (pos =3D 0; (end =3D pos + BIT(order)) <=3D bits; pos =3D end) { - if (!bitmap_allocate_region(bitmap, pos, order)) - return pos; - } - return -ENOMEM; -} -EXPORT_SYMBOL(bitmap_find_free_region); - -/** - * bitmap_release_region - release allocated bitmap region - * @bitmap: array of unsigned longs corresponding to the bitmap - * @pos: beginning of bit region to release - * @order: region size (log base 2 of number of bits) to release - * - * This is the complement to __bitmap_find_free_region() and releases - * the found region (by clearing it in the bitmap). - */ -void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int or= der) -{ - bitmap_clear(bitmap, pos, BIT(order)); -} -EXPORT_SYMBOL(bitmap_release_region); - -/** - * bitmap_allocate_region - allocate bitmap region - * @bitmap: array of unsigned longs corresponding to the bitmap - * @pos: beginning of bit region to allocate - * @order: region size (log base 2 of number of bits) to allocate - * - * Allocate (set bits in) a specified region of a bitmap. - * - * Return: 0 on success, or %-EBUSY if specified region wasn't - * free (not all bits were zero). - */ -int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int or= der) -{ - unsigned int len =3D BIT(order); - - if (find_next_bit(bitmap, pos + len, pos) < pos + len) - return -EBUSY; - bitmap_set(bitmap, pos, len); - return 0; -} -EXPORT_SYMBOL(bitmap_allocate_region); - /** * bitmap_copy_le - copy a bitmap, putting the bits into little-endian ord= er. * @dst: destination buffer --=20 2.39.2