From nobody Sat Feb 7 17:04:41 2026 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 8D73AC83F18 for ; Tue, 29 Aug 2023 02:40:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235435AbjH2Cjx (ORCPT ); Mon, 28 Aug 2023 22:39:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231971AbjH2CjT (ORCPT ); Mon, 28 Aug 2023 22:39:19 -0400 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3514CA for ; Mon, 28 Aug 2023 19:39:16 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-6b9e478e122so2868845a34.1 for ; Mon, 28 Aug 2023 19:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693276755; x=1693881555; 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=5NE27I3CsU4QkkPBH5fYXurm70My+K33B6QZenOIBsA=; b=KvQCDpFJZ1opI3ehAB2jl9X3ERludzMXHIY7OiEF8Pm4w+rhqwwbCav9u2g/rffEb2 ZbaOrenHzfrV6OZi9384i58lZJGNQpUx002T28aasoepfrjYN+qgJOtqNzombEgrb0l0 9GkE/0kAYlLkNNMnbb6e7jpYHE7JpieglR/YYDvbqZCun7R6pARexT4sgy9Z+qkUD272 2rUFsYOOF3iTYUsPWZP2fkVFi/b+abVLW6H3t1DunzB3AjUM7g8LU46u83LBDDowckz3 jFr1ocOSWdrWXtVofsPGF1ltIjqfX1b9JZP90FQfAjusVH1adcIgAV+5/63MPmm3K1z3 jILQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693276755; x=1693881555; 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=5NE27I3CsU4QkkPBH5fYXurm70My+K33B6QZenOIBsA=; b=IFxDRRMXoBUls8Y4pktGRhH+QsA4YjQ3g4PM38UbxjQTuqkuvfPU68cDV84M1nZN3g /hpiwJyj6P3lEf9YiSRmIQHDiwbPkKu88ZrZmCvo5HdniRwS93QmmAHZI4mo01Npn9Uu LKgUH4kcQK8p3xI8DaBMOGiCSh6WPRiUgy0C8Pz6rP+/fDehTLgSSqUtc2pJXHcW8QSD Nz2C6WtMAzdqZcBUHNI/cLTcmXL3PFPYu/Zms5LK1+eqfNF88uW+G7v0bI4XNpY27BLI 5wXlw49rzXVkLwCC5oJfefI2b3bKdpTNywrF5F5GQiCe/wyLxhgkPfnOhO3mYwxRPwzX V+xQ== X-Gm-Message-State: AOJu0Yyi+GB9gnHuNOXFi7KhisXGfsJB6LDlr/kcFSzUv6aW+4ZOr032 6t6TOQeI7QWCL1BndkjiVanScC9s0F4= X-Google-Smtp-Source: AGHT+IEODGxB8695GNUoglx5oPne5IYWXgo+MDk+8WSWIrnVQN/n9ehKW76kAi7TPtV7BGScdf9pvQ== X-Received: by 2002:a05:6830:16cf:b0:6bb:1071:ea72 with SMTP id l15-20020a05683016cf00b006bb1071ea72mr15713974otr.36.1693276755592; Mon, 28 Aug 2023 19:39:15 -0700 (PDT) Received: from localhost ([2600:6c5e:2a00:5805:c222:580f:7592:7110]) by smtp.gmail.com with ESMTPSA id p24-20020a0568301d5800b006af913c1044sm4054188oth.16.2023.08.28.19.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 19:39:15 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v4 1/8] bitmap: align __reg_op() wrappers with modern coding style Date: Mon, 28 Aug 2023 19:39:04 -0700 Message-Id: <20230829023911.64335-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230829023911.64335-1-yury.norov@gmail.com> References: <20230829023911.64335-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(). CC: Andy Shevchenko CC: Rasmus Villemoes Suggested-by: Andy Shevchenko Signed-off-by: Yury Norov Reviewed-by: Andy Shevchenko --- lib/bitmap.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index 935e0f96e785..250715260d95 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 Sat Feb 7 17:04:41 2026 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 CC003C83F1A for ; Tue, 29 Aug 2023 02:40:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235448AbjH2Cj5 (ORCPT ); Mon, 28 Aug 2023 22:39:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232329AbjH2CjV (ORCPT ); Mon, 28 Aug 2023 22:39:21 -0400 Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62857CA for ; Mon, 28 Aug 2023 19:39:18 -0700 (PDT) Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6bd066b0fd4so2649869a34.2 for ; Mon, 28 Aug 2023 19:39:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693276757; x=1693881557; 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=eKyaL6L4bgunsABP04Ms41wHAbdnN+iVX6+0TH71sYQ=; b=X/JzL3Qv7uFXDscK0ih8PDh4PXidjku3vi+73IEaLgriu45KriE7cXTMAaPgB3QSsH OEYalXoIgHwQhYEfzSnco6xby9MimJbiw9H9Kb+fQb7bpu8kNjUNBxrN5C9aVYR1Y2Rk HxW6Fsvuka+CuFxSGPjpMubcH9ODkUwArGmf7b0JQ70EM+mGKE734pVGfZlLmbP26fdw ArNkWNUOhw/amx0QpBIYrduF1IodueK2t/4vV91G94Jb+/xl0T7k21vpNkLS7/FxXT25 2Pkc7ZPoTu1xqDqyn107uWk9TbLRd/m2/vP+jgRNDtAppkgyufbeRLKQNdIdQAdl0qKM GX9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693276757; x=1693881557; 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=eKyaL6L4bgunsABP04Ms41wHAbdnN+iVX6+0TH71sYQ=; b=FMry0yUmvqdkbZnri7R9wERmIUXPbWi3WcZOMPQPCwhdQGkF4YPQUVGcIVnHMGCVqN xyymb68hNQSqjM2z3VXXOqE3sGeFRlG0BxsY0rVgVyIjy5FnD/qt98irEDke9ODzy3Kf /kXxfz2xjgm19Nu7O2pmseOv4WcU+roECX5FRqhZwCqJOgAEOQeI0iCVeN3is5rNmAh3 K9TcOQeFJf8Lf6WPnWZgdSzz0WfCqgyMw/QHYTvII1yozlG61C4/UntUK/kJaDsDOyP+ UorjPxI+o2wKO6D66Q2lgQjHOgz8GrejRAfsfD62sFTGSUggvHKLcElDPWBHGPFJmPVL kn0A== X-Gm-Message-State: AOJu0YwgN/soukdi7C/xwmulmV+FxyFNmmp9msfcvbYtfU6cy4TODjWn xDSZgkRWSbly14B5RVwkqtvgX6GrYpo= X-Google-Smtp-Source: AGHT+IFnzTnWB9ZsD1rGaOSQX00OJfa6VcFJ8CS3D4WVvCgy5iX0g9gmx/r+toCDhs7Ve4WzpcFkDg== X-Received: by 2002:a05:6830:1314:b0:6bd:a47:7bb6 with SMTP id p20-20020a056830131400b006bd0a477bb6mr13322361otq.14.1693276757228; Mon, 28 Aug 2023 19:39:17 -0700 (PDT) Received: from localhost ([2600:6c5e:2a00:5805:c222:580f:7592:7110]) by smtp.gmail.com with ESMTPSA id q24-20020a05683033d800b006b9348b6f51sm3893008ott.54.2023.08.28.19.39.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 19:39:16 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v4 2/8] bitmap: add test for bitmap_*_region() functions Date: Mon, 28 Aug 2023 19:39:05 -0700 Message-Id: <20230829023911.64335-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230829023911.64335-1-yury.norov@gmail.com> References: <20230829023911.64335-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. CC: Andy Shevchenko CC: Rasmus Villemoes Signed-off-by: Yury Norov Reviewed-by: Andy Shevchenko --- 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 Sat Feb 7 17:04:41 2026 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 B28D1C83F17 for ; Tue, 29 Aug 2023 02:40:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235441AbjH2Cj4 (ORCPT ); Mon, 28 Aug 2023 22:39:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233143AbjH2CjW (ORCPT ); Mon, 28 Aug 2023 22:39:22 -0400 Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F0EE13D for ; Mon, 28 Aug 2023 19:39:20 -0700 (PDT) Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-5733aa10291so2668366eaf.3 for ; Mon, 28 Aug 2023 19:39:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693276759; x=1693881559; 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=4VbD+SR5jCur1/t4RnPL1xcIxaeNUhQeZ+KfWJc7SsU=; b=o6vNJy8bdSDXxfI81GjNkpisiD7xoP+4R5TMu+r1JHX6yBbq/I+ZHVzZYqUQvUJn8s Qcq0GUxTOMmu4m/4EDT+eNqdpHqIW3sCT/mK137j9K6thZg2V9GwvD5iszDZS9May/rr HwkvGA00kI6bFLrU1Ds6O7UiVq4R2oZe7CAOEWG05yXoU9Nas94OPbEPGjuniW7seE77 DUiVb2fkDYt7AEcqVZbluhaiqwVYsBRakcSq5O3gA1ShyFQf5ywd+1LtA+Ua+/mmLBh3 JpW5KQHQYD9pFINGsh1NMLRAFCsKqOpiK3AHrKSvYtre3ON+XVSFkQJsVUI1jUT1MEc+ Yayg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693276759; x=1693881559; 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=4VbD+SR5jCur1/t4RnPL1xcIxaeNUhQeZ+KfWJc7SsU=; b=Efzn5mM4vvjMx3Rbm3ueuq3wEEUbsovDRc17PB18WPB+JkGstiHY71NZXGeoEq2B5y giuH2ZCmtvf4GzWa2YqgjnqSKvH1nSItcuE1Hz1YMowYl7vWcqAr91Z1zcoib+AuACzR IrnQ81cJuwUbut/8TxH9yJOQRF8MZXvi0gDmkmPlbT6wGu720u4hyHDvjN0NCHvusGMj CisVVf184VSV9mYduYgp0Inu2PoFIYUEJK0gVclJVcA0AXJZ6aJNTaMFb+SYGyDN1GbN 3Z5Ch4+4JSKjghzyfnltQtH82ATdEuNrvjiyZooXEmGbNyCdtJPtHacAYb1IDbWjr108 A6ew== X-Gm-Message-State: AOJu0Yz+WsBPxjnSR8tnUpgW3odtne0Lq4Ods/whNR9GQpHJ8rqL8lWA EFOCrRBtcezGOc0L+ctd0JkSWU0/3dY= X-Google-Smtp-Source: AGHT+IFHFCIk3gU9oude655DrvwVhztcRTvGKWomnRN7fFsUrjeIqz0YNAddtpGdRs7rwQWa9mJCtw== X-Received: by 2002:a4a:3c5e:0:b0:56c:77b6:6d46 with SMTP id p30-20020a4a3c5e000000b0056c77b66d46mr13666749oof.9.1693276759042; Mon, 28 Aug 2023 19:39:19 -0700 (PDT) Received: from localhost ([2600:6c5e:2a00:5805:c222:580f:7592:7110]) by smtp.gmail.com with ESMTPSA id s15-20020a4aad4f000000b00573a7d8f382sm415075oon.36.2023.08.28.19.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 19:39:18 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v4 3/8] bitmap: fix opencoded bitmap_allocate_region() Date: Mon, 28 Aug 2023 19:39:06 -0700 Message-Id: <20230829023911.64335-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230829023911.64335-1-yury.norov@gmail.com> References: <20230829023911.64335-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(). Fix it. CC: Andy Shevchenko CC: Rasmus Villemoes 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 250715260d95..3c069944dd83 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 Sat Feb 7 17:04:41 2026 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 DF083C83F19 for ; Tue, 29 Aug 2023 02:40:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235456AbjH2Cj6 (ORCPT ); Mon, 28 Aug 2023 22:39:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233999AbjH2CjY (ORCPT ); Mon, 28 Aug 2023 22:39:24 -0400 Received: from mail-oo1-xc2d.google.com (mail-oo1-xc2d.google.com [IPv6:2607:f8b0:4864:20::c2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04427CA for ; Mon, 28 Aug 2023 19:39:22 -0700 (PDT) Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-573449a364fso2194737eaf.1 for ; Mon, 28 Aug 2023 19:39:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693276761; x=1693881561; 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=I1pj4nyvVMsclOEC8h60mitlr/KrWrVEeGq6ZdoiJKc=; b=hbahPkAmYFMKqqd17DEFmNfkL4xDKqyp66AtrlhWPspg84r9hza3Wj8gj8m3fMV60+ 3OR0mlgcXkNRQOVDAgAF/VPpD3LJbV/xN8iR4zr8nyeK1rcGQ9lmrwau867uSPQjNyW8 diexw3nXP7pe0i5WQgBYtnPwLG6BFSTgmpQh3kiQO+rglx4MYpKFvPOvRqDbDbDgGZ18 9gX0iwXF7WKbhLGCq35R8NqLTlxnhMFm9HRXUByCP6Z6+y21LtFhx/TScSLtftuSfNEN D33u0JwD+YfK0ybBUbeDcn5NA7XdZt0JaGe7zOddHEX/bNZCHTa1nhogBR6NknybrKLU 6gXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693276761; x=1693881561; 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=I1pj4nyvVMsclOEC8h60mitlr/KrWrVEeGq6ZdoiJKc=; b=AreG3eW2bfze+RGc2sfnSGu96tHFcbGsr4hb9gxVCkKD6ithL6ugKt4jbczae1BgLA OsC0Ftvg3Qrvg/TMoo8uxpUho85IMmC2cr4sjiuthvih5zsRPkFwV9CbWIjTs+yanoh/ oOeNiD9QCRiZJDH1bOAyINj2uG8CjN6J1z+YSeVs8EUtRyfRBoc8H9O84Oxk/ELvEPMU JD0Bd7wxulsDtQSbA1HeK2x6rI7Zv4+6+j1f0bcs+B6JdHX8ZbxrAJQJkppASgjUPx4T UlzFcTUhgWIxFPy7PP1S+KkI+fhVtuEjTbQccdUkbvqNyFsxRhlFLuWjobJSN/98nnnN SWHw== X-Gm-Message-State: AOJu0Yy52Xf5c9plXkagNDupCw2r2r4AwEKWlYjDVp53uOgpj382vWWF 5I0RNUoFtC6owBwnkj5iIZY3eezguIY= X-Google-Smtp-Source: AGHT+IEAAYCSnfjjlfF1GVf7bPT+V8pDv9iNBsJFEC657DN2xpOpJJcVXZpu/c/F6BT2gLGZhWkVVA== X-Received: by 2002:a4a:281a:0:b0:573:3711:51c4 with SMTP id h26-20020a4a281a000000b00573371151c4mr11265302ooa.8.1693276760876; Mon, 28 Aug 2023 19:39:20 -0700 (PDT) Received: from localhost ([2600:6c5e:2a00:5805:c222:580f:7592:7110]) by smtp.gmail.com with ESMTPSA id l9-20020a4ab0c9000000b0055975f57993sm4271118oon.42.2023.08.28.19.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 19:39:20 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v4 4/8] bitmap: replace _reg_op(REG_OP_ALLOC) with bitmap_set() Date: Mon, 28 Aug 2023 19:39:07 -0700 Message-Id: <20230829023911.64335-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230829023911.64335-1-yury.norov@gmail.com> References: <20230829023911.64335-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(). CC: Andy Shevchenko CC: Rasmus Villemoes 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 3c069944dd83..0fabcb0e4628 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 Sat Feb 7 17:04:41 2026 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 28D41C83F1E for ; Tue, 29 Aug 2023 02:40:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235474AbjH2CkB (ORCPT ); Mon, 28 Aug 2023 22:40:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234266AbjH2Cj0 (ORCPT ); Mon, 28 Aug 2023 22:39:26 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A5C0CA for ; Mon, 28 Aug 2023 19:39:23 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3a8506f5b73so2807441b6e.0 for ; Mon, 28 Aug 2023 19:39:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693276762; x=1693881562; 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=ScVDkb9hH2uA/Tte+J+EKjScTHH6zU1pOaL5akYS0lo=; b=n5xTVdjVTaUVS1MCywVkwZ/7PX31UR+R9X6SnSG4h0DRpAAME8Oms8NeQAFzO+p8w3 rFp0D/hy4rVze5qXKg8y8sKmWV4W3j2FZN76MzYIFZM0h81U8Qy97qC0FJ80UZUaR41u BKSc8lP/o8wYRWgfyZ1M7WfMz+2alvvTxRa3ZVBPioWe/93DrQbLpWDK5G5gLyo47LUk U5fKMpkG8Ofi9KFmgXdKJINs6REpu7P8XWDVeapL7mJrC+uTm89aDwL7d2kev2JGfY6m lPQZ3czelBAbNJe/4TftxJo2H+mAO20BkQ1FdjtaiHFnKqrhy/+AwLYqFlBwQHmSD0O+ gj0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693276762; x=1693881562; 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=ScVDkb9hH2uA/Tte+J+EKjScTHH6zU1pOaL5akYS0lo=; b=EnrfsAauCjpEoWdGqcWD7rVuXf4I+It8q8MRcThKxHz8zhaCa8OH6Ws1Xsyhv2oaWX OsbnIn5YLmQ0QrO7ySrSh+QqxUGdCXrRVtkUwtZRA8APqdosKGEi3BjCxOmeOtfnMB0s /1HHI7xnLTLOrYewP0E26jEZrWwRNniV1Vln9qb+6EQ6qQTpWliAWctiwHIFYFRZbfYP 8kSYI/WokXWVpz8wC25+caCCJu+yNKSUplKfvI8Og/AQunuvjhBDJfPjFW+OKlYSz24B CtvvCFT0G95kCL6AR8vcBI3hudGwNjdVUFkP3/ObM1mk78pmv64ps1c7CIK/jA6cMWyE t6uQ== X-Gm-Message-State: AOJu0Yw4KTBSwMOvfnm+qcXqe5DdDpgH2rrjNreFGUgHSUNuc9A3XT5N yJZmavn97Jdb69o9pp6BAkpZNtvRXgs= X-Google-Smtp-Source: AGHT+IFRGENj1ra4fF4Djf04NbfElx/VkQZv1DCZrB3q0FHakUiW0DXGTb8PA9D7tG5N55saKjudqw== X-Received: by 2002:a05:6808:df4:b0:3a7:725f:476b with SMTP id g52-20020a0568080df400b003a7725f476bmr11845657oic.41.1693276762447; Mon, 28 Aug 2023 19:39:22 -0700 (PDT) Received: from localhost ([2600:6c5e:2a00:5805:c222:580f:7592:7110]) by smtp.gmail.com with ESMTPSA id z8-20020a056808064800b003a3860b375esm4046099oih.34.2023.08.28.19.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 19:39:22 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v4 5/8] bitmap: replace _reg_op(REG_OP_RELEASE) with bitmap_clear() Date: Mon, 28 Aug 2023 19:39:08 -0700 Message-Id: <20230829023911.64335-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230829023911.64335-1-yury.norov@gmail.com> References: <20230829023911.64335-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(). CC: Andy Shevchenko CC: Rasmus Villemoes 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 0fabcb0e4628..56595ce513f5 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, pos + BIT(order)); } EXPORT_SYMBOL(bitmap_release_region); =20 --=20 2.39.2 From nobody Sat Feb 7 17:04:41 2026 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 11C13C83F1B for ; Tue, 29 Aug 2023 02:40:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235469AbjH2CkA (ORCPT ); Mon, 28 Aug 2023 22:40:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235406AbjH2Cj1 (ORCPT ); Mon, 28 Aug 2023 22:39:27 -0400 Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29167CA for ; Mon, 28 Aug 2023 19:39:25 -0700 (PDT) Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3a88e1a5286so2974199b6e.3 for ; Mon, 28 Aug 2023 19:39:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693276764; x=1693881564; 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=DxHdr7gJ1K3Uc14nC1QOYk1MzYVSa0hY81XoEGmet+8=; b=WgLyd2LCehbhZ9P2jI5WAJFV2QrsAkYNbo6sHozidJCCjFgEW5/mj1vtarfKeRLRxl cqbzH0ihKyFWzvr/pILWt7lwQBDENYfhTZc2mCS9hn9IZOSY4zWU+ohgJs1nvm3J5mTA hZ5vV2Hr8LJa9rqM14nuNAxZuVYSJykpWCOHO/qX6J8Bu0fHpwIH6U9Ad6hcx9fpxNxY mQXY0xZIis7S4Ogxr4hELGs0HX4gVCYT8m8l29+H6XImXZaTGcyyS7QFw8DPpdRjaBEH 6Rb07daNwOQ+YvsjFv5AMGZKCFMFwhNOtbo2Dmi/Pjf7Rjp99ACthuTFDF/r0cKrGbbM Pqkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693276764; x=1693881564; 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=DxHdr7gJ1K3Uc14nC1QOYk1MzYVSa0hY81XoEGmet+8=; b=GWknDV8mw/KXBgpqrHayFw/H3LwcQtx5ugYQecBlS7szLHMUhAspBzztatNx6Rm7g+ rCn5nJHvmTaioanBJFYPpVpaSALHK68SX5Qo1EeWzU+kbkc5AezbV6FBeEeIQsu9rlQ+ f03SgxIejAOQdIcWjpHGvMTzzKQl6x+NywfHZRzQdvVgrlCBllkWRnHo4HFLXWmd/BkE F2ZOSUMdIB4uifTr9Gx5sqI9D/QAflMIsTp/jq/W/3puA4vHjGa2R7865QkG54gVEAKD io7FGfLaAimAsPtso2M+/PZS7s491dBftm9hNOuZMkN4EmsRmcjyOQgtJ/bDzAfHuZ3g 1tFg== X-Gm-Message-State: AOJu0YxoIFfltmScLDg5pzNrrEIpIj1ZTYfQixeL9BERcWyJtMfs2qCu WzXD4AsjkqRd1etxnLySsJsGuCTXwLQ= X-Google-Smtp-Source: AGHT+IEAqCdyyfSqOP1+x1XT50fcC0rJqAdABE34AT4toXxNsIpZmwupDCWFDx6Z29wBN+hLlSYIRg== X-Received: by 2002:a05:6808:f91:b0:3a7:4876:6044 with SMTP id o17-20020a0568080f9100b003a748766044mr14754473oiw.52.1693276764105; Mon, 28 Aug 2023 19:39:24 -0700 (PDT) Received: from localhost ([2600:6c5e:2a00:5805:c222:580f:7592:7110]) by smtp.gmail.com with ESMTPSA id q12-20020a056808200c00b003a89019d5fesm4028275oiw.51.2023.08.28.19.39.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 19:39:23 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v4 6/8] bitmap: replace _reg_op(REG_OP_ISFREE) with find_next_bit() Date: Mon, 28 Aug 2023 19:39:09 -0700 Message-Id: <20230829023911.64335-7-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230829023911.64335-1-yury.norov@gmail.com> References: <20230829023911.64335-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. CC: Andy Shevchenko CC: Rasmus Villemoes 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 56595ce513f5..c94340c4ba86 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 Sat Feb 7 17:04:41 2026 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 4774AC83F20 for ; Tue, 29 Aug 2023 02:40:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235506AbjH2CkE (ORCPT ); Mon, 28 Aug 2023 22:40:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235408AbjH2Cja (ORCPT ); Mon, 28 Aug 2023 22:39:30 -0400 Received: from mail-oo1-xc2a.google.com (mail-oo1-xc2a.google.com [IPv6:2607:f8b0:4864:20::c2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E942DCA for ; Mon, 28 Aug 2023 19:39:26 -0700 (PDT) Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-573921661a6so844255eaf.1 for ; Mon, 28 Aug 2023 19:39:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693276766; x=1693881566; 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=iJhbsn7qD8sqFnBkCZdh14WA9jrZUyo54sNK/cY2q/E=; b=XQuYU8dK6jhL7sbKNyo2taeA89OfxRCHksQlhNuhmfftnwQDmyrzGZNwJdUqzWFOv0 XBz6abdDaLKo2eOktGLNEQr3nC3VxHruJ3L+s7iSO46imkb2s6YEWFnMHCD8JzYIFO11 moVxzApqEgAH/jTMD8JUnu2IkX1m1PpAObrfTn2anvL37NM589hPYs/cOM8cDK8xyaSE nfUvtA/GXIsOA9zipxc6Df+htqpHUU65Q7JuljpZQ+pFoqSMAzCSqocsmUFPnGWfqbF1 jexwmQI5iazqEXyeegfWjaA3+boY5nCflzvuHZsXA46JP8lfOQl2vm9iESm+qRC9lbZf mJjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693276766; x=1693881566; 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=iJhbsn7qD8sqFnBkCZdh14WA9jrZUyo54sNK/cY2q/E=; b=kcPT/108J3hXUUnAUVeJVXKxHiinmDHpAbUM6sc8sc50TryVBB6pBSCTldn/M8dOSs 7sky+MKqKSvV+4Xpwo/t6Tuh17DsIJIx9HBw4J0r+WthkWcOejR5xhtGPALS0UrVQ8ZN hgAgeCcqfGtXSdGHwQfhQLFldnEqu7XvHBZvGuWMlezp8THjEKzoiK7b06tqY2B2SNbV 3Lxa6btdW3TMHm81ls4FpdXUa6pVRLTxwpWRl5aowBjM39EhQ1Hi+T/Bcbc4ZmrlpLHV /BwRdGn2TfKcPn06zB1ZJ0h7jbP5RpfoERcwk2R9uxZ+/YNI45l4ONIyoOkxkeeGC/FP rE+Q== X-Gm-Message-State: AOJu0Yyv2MMLmhPx5LQY8kcyCwVZSiDKj36+/L6TyEf52pDxT9aZspSf L8D6z/XDuvt1bgyG3uGi6NYQ86rE7QI= X-Google-Smtp-Source: AGHT+IGpYP8ClbveZocLTNQ1+4Cm1LAZ09Xz+AZEHbOnZqqDlT8S3bOvDYOQkyixb2ZQc8VMP7PmQQ== X-Received: by 2002:a4a:3014:0:b0:573:2312:b3 with SMTP id q20-20020a4a3014000000b00573231200b3mr11605146oof.4.1693276765754; Mon, 28 Aug 2023 19:39:25 -0700 (PDT) Received: from localhost ([2600:6c5e:2a00:5805:c222:580f:7592:7110]) by smtp.gmail.com with ESMTPSA id 4-20020a4a1704000000b0056d361ca33fsm4699375ooe.16.2023.08.28.19.39.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 19:39:25 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v4 7/8] bitmap: drop _reg_op() function Date: Mon, 28 Aug 2023 19:39:10 -0700 Message-Id: <20230829023911.64335-8-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230829023911.64335-1-yury.norov@gmail.com> References: <20230829023911.64335-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. CC: Andy Shevchenko CC: Rasmus Villemoes 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 c94340c4ba86..ab730ce52d21 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 Sat Feb 7 17:04:41 2026 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 383DCC83F1D for ; Tue, 29 Aug 2023 02:40:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235492AbjH2CkC (ORCPT ); Mon, 28 Aug 2023 22:40:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235410AbjH2Cjb (ORCPT ); Mon, 28 Aug 2023 22:39:31 -0400 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9991A139 for ; Mon, 28 Aug 2023 19:39:28 -0700 (PDT) Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3a7ca8720a0so2790329b6e.2 for ; Mon, 28 Aug 2023 19:39:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693276767; x=1693881567; 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=g42DUtsBxnSEETRjQXgjfdgHF/buczC6BRWDqCJjhA0=; b=Cf0JH8p2x8C70jKgyngGTXQiAAL5zCkHB8UYH9IkE2Jzk4REncTiLbetbx5uAYj1hO xiSV13H5JL9F4JCfK8wB67F3xmvTAO80crVUGufVcR3Pw0hfknBHX30m1Qm4YXJcQFeX jbLjlbY/kN6Q7F820xsb+N3RhBuetl/kQ3dC2FpXoSmeqUvsDPcp4k8C38qhU9cBgf8P wLScZlS+1fnkHhfInpEszdosXem4Sez3EDrtgyx+dM5qeDkdLe2en1bYaS2Uh4MlhwvB dfRbXupkOjewicm2RG6EReONyOjQ4IjqzkGi6c1mJHBlh7lYTzhAjG8HZGFZaDZ0cTYn AAlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693276767; x=1693881567; 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=g42DUtsBxnSEETRjQXgjfdgHF/buczC6BRWDqCJjhA0=; b=Q6x+4ae09+lDE2gdad9QF9h6ycfk6FlajHwq1xRMdnae3cuzXxYweCo32EVfkCb7Qf uGWgUomdevqnS0XSJnpMmTQTdYIpD79TTzxDs1c2/8UIIa88lSf5JtcacVePLr7Bf4/0 tY/VST/2UZfwPjwVUtyyyTh3o4tbsJG5w61V1LOo2Sim/WOKqRGv6X6il8DO15wy7fK1 4CA5whEZtSVMQbJshzrE8ud5Gr/FTjiN3N7lvz/UpiHzibaAqEy393VnLeunR4Iz9Onz tIpSng6UCB/5a7KDoDNtCNoBfKbVY39us1t/brMZnqqsF9jlFtfekGY84QlVswVf6hr8 ZwyA== X-Gm-Message-State: AOJu0Ywr4Y+MLb7mSTRIJXr+JHXnXRguaKeJvEUGnHprGEI3SX2yGU5L +SNQjf4l5L4rHp4DR++XOmO5+zr3VxY= X-Google-Smtp-Source: AGHT+IH+AalN1i/+uZ3a1Dai6xtwBR6Sq2P3ovwC6VmsUpQqpY6/UgkpDAWIDLQj4Qmz0JYc8jsd5g== X-Received: by 2002:a05:6808:1a1c:b0:3a4:35bb:edae with SMTP id bk28-20020a0568081a1c00b003a435bbedaemr14573506oib.29.1693276767505; Mon, 28 Aug 2023 19:39:27 -0700 (PDT) Received: from localhost ([2600:6c5e:2a00:5805:c222:580f:7592:7110]) by smtp.gmail.com with ESMTPSA id e9-20020aca2309000000b003a724566afdsm4046407oie.20.2023.08.28.19.39.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 19:39:27 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v4 8/8] bitmap: move bitmap_*_region() functions to bitmap.h Date: Mon, 28 Aug 2023 19:39:11 -0700 Message-Id: <20230829023911.64335-9-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230829023911.64335-1-yury.norov@gmail.com> References: <20230829023911.64335-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. CC: Andy Shevchenko CC: Rasmus Villemoes 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 1516ff979315..973ae5b11c70 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 int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp, int nmaskbits); @@ -594,6 +591,66 @@ static inline void bitmap_set_value8(unsigned long *ma= p, unsigned long value, map[index] |=3D value << offset; } =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, 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. + * + * Return: 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. + * + * Return: 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; +} + #endif /* __ASSEMBLY__ */ =20 #endif /* __LINUX_BITMAP_H */ diff --git a/lib/bitmap.c b/lib/bitmap.c index ab730ce52d21..65a6d5d47d81 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, 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); - unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags) { return kmalloc_array(BITS_TO_LONGS(nbits), sizeof(unsigned long), --=20 2.39.2