From nobody Sun Feb 8 02:55:56 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 DF0CAC0015E for ; Thu, 27 Jul 2023 02:02:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229602AbjG0CC0 (ORCPT ); Wed, 26 Jul 2023 22:02:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbjG0CCV (ORCPT ); Wed, 26 Jul 2023 22:02:21 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDD8CCE for ; Wed, 26 Jul 2023 19:02:16 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1b8b2886364so2893565ad.0 for ; Wed, 26 Jul 2023 19:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690423336; x=1691028136; 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=7JvH6fCyOwmUpJlih9kGPQ82FswQKyJELuqHpVpnDY4=; b=i7gBSpnqZQMeQLBB3IgdhZMBG7JEgU+m3wyIXdUHG3iCYDl66WvgCrSqmUpC5Njy3W dY+PJkHGbPQDbcb24H/c4beeMOYfCENgG3YPBbnTEeW4ru+hluahmqoSBW/28IsDhh4p 4e5sbagKQJDa0OmqfHfRqb2hm8iVcZAfUi6zvIsB+nIpI5wSwBzb9KZ+OP+izfp1SAaO otpMwFXFToqJa96GG006XR0IvD+ZrQv2lY7mFv4AVHUdMeVcaicJ6A5/HvNi3Qt4uUHl TCwg1x3lWUb/uJUxKqhy2EyFqe6wpkiOEbFmvCJpeDCiq4aTPYD8omlkGE4DRKAqv9Td DOZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690423336; x=1691028136; 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=7JvH6fCyOwmUpJlih9kGPQ82FswQKyJELuqHpVpnDY4=; b=OYiZnSWcNYEVhz4yexGIX5nJBg/YM3tKqG7OHU//GpBpoQxnwuPIBvhx9ohJQTQAFg IzcCmYVf+Q0sZdqlPwnBuOYOk2QWw2aqRokUhXJvb3deCabLQo8/QjYQP+dAO/9FnfaW ZZ0ns0CR2k3u4KPlcl713gz5gnKlaeXBC+Upu4i7T4IN/fFf98eVnWDWxnpirTDr6oR+ CHksjheej++gAVJuFwOeOmAB7tUN4AGAZZSt8xzLerhLXPQ9pbggCwWmgbkJ8vQPMlst rm7vzJKZezMq8WuUsiQWDVk/q9NO2/4AH9ZaO9xsr7MIf/0FLiYdQF76pYB/DGmKi0jU Fjdg== X-Gm-Message-State: ABy/qLahFDuXG3WL5WOxNVkWgm/FGLqy/wyJDlbiIdQhvFxYD7zyoaoB a9xZBSdxetKdh7P2qS4LSsO0cvHbmi9BSg== X-Google-Smtp-Source: APBJJlEYYacde0cKtvxPkhHMjKZE1q1RLQsFu6oYo+pe8taW61QdhtOFkkGW0JdkvxBqLUMdKWhGOg== X-Received: by 2002:a17:902:7616:b0:1b9:f7dc:b4f6 with SMTP id k22-20020a170902761600b001b9f7dcb4f6mr2750054pll.44.1690423335906; Wed, 26 Jul 2023 19:02:15 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id u6-20020a17090282c600b001a1b66af22fsm234921plz.62.2023.07.26.19.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 19:02:15 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH 1/6] bitmap: fix opencoded bitmap_allocate_region() Date: Wed, 26 Jul 2023 19:02:02 -0700 Message-Id: <20230727020207.36314-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230727020207.36314-1-yury.norov@gmail.com> References: <20230727020207.36314-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. Signed-off-by: Yury Norov --- lib/bitmap.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index ddb31015e38a..0bed9d943d96 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1314,12 +1314,10 @@ 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) { - if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE)) - continue; - __reg_op(bitmap, pos, order, REG_OP_ALLOC); - return pos; - } + for (pos =3D 0 ; (end =3D pos + (1U << order)) <=3D bits; pos =3D end) + if (!bitmap_allocate_region(bitmap, pos, order)) + return pos; + return -ENOMEM; } EXPORT_SYMBOL(bitmap_find_free_region); --=20 2.39.2 From nobody Sun Feb 8 02:55:56 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 EC25CC0015E for ; Thu, 27 Jul 2023 02:02:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230306AbjG0CCa (ORCPT ); Wed, 26 Jul 2023 22:02:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbjG0CCW (ORCPT ); Wed, 26 Jul 2023 22:02:22 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EAB79E for ; Wed, 26 Jul 2023 19:02:20 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bb7b8390e8so2778555ad.2 for ; Wed, 26 Jul 2023 19:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690423340; x=1691028140; 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=Y3H7tTdXzCccSotcbK0HBN3jtn5fCkiAGI0Ov9NcQqc=; b=FE8vhxxde3URV15sRKyzYC3RSBIPZnfZAbCJuIjENhkipGgFCLWNIy6Se5Tj3jTdi9 DM8XdHJlQbuweQv2ulSRoW2p/ik4/RFySbZC/GnbJz7FUmmKIvcrOkzdZwbrsOgE4Txi oSGxZnE8QNNlndoUZbMS/DQ2u3tsDRyHq5kymA+i5haL+/EQSUZI47q5FCdw/yo5XwAb fu4ShUvwjwwP05boV6WrfHQUVPbHEKwy0CYR65ujtghPXNRtpbCZnwvcfzt44UzXDOwI groPZF3G+mey2uA7xZ7WPlMLTKWTLZHhUV0XfFmIW2cGwCj1IT/mbIrZjEucrYUYi3cb 7QDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690423340; x=1691028140; 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=Y3H7tTdXzCccSotcbK0HBN3jtn5fCkiAGI0Ov9NcQqc=; b=PL5Znzf4hOiDmgtYwC72y9W67NcGQAu6GBxlGKiWQqlU2CKzt/lz3vNaxXAl1mSx4a XZ1za+9XwJDqJa+vf+dqiwMqvM9XrEiMhwNswWIXB+mpPYOfF3tK73vdMqS7/ToOh/FN QdVRltKagrDntIX55Z1sB6F2zPQjNLAbf86ak6pFijzTaxsgqwgYu5e9iUcjptHK/U5O 9dlZEFFeg7uvKLa6f86nxOkjOy7EOvk2owecg5JOt0OcGmBMgXNIHpFQYMuLsQ+JuS9U hd847UcYeXFwXxijfYp4sFFcs6yap4OXHAvRZ6v1AABixVYGGYLDAD+Xzio6YqyXO75d 3LHg== X-Gm-Message-State: ABy/qLb8nTxZlzqBZZnLkmE2V4XEuCRYf/+oF/xdnJSMzjd9CDjj0Tka lJuTINpV77N3FNE2VReskvM0L3edKSZuFw== X-Google-Smtp-Source: APBJJlF0NQyhEBYt5tlROyKdSLsCGnG72vbaMpfDMlFOiPOM5ns+egetlDvW9I2BwS2QLt19wa2XdQ== X-Received: by 2002:a17:902:d4c9:b0:1ae:626b:475f with SMTP id o9-20020a170902d4c900b001ae626b475fmr3616183plg.12.1690423339606; Wed, 26 Jul 2023 19:02:19 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id c17-20020a170903235100b001b8422f1000sm215289plh.201.2023.07.26.19.02.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 19:02:19 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH 2/6] bitmap: replace _reg_op(REG_OP_ALLOC) with bitmap_set() Date: Wed, 26 Jul 2023 19:02:03 -0700 Message-Id: <20230727020207.36314-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230727020207.36314-1-yury.norov@gmail.com> References: <20230727020207.36314-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(). Drop it. 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 0bed9d943d96..346b848170e4 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1352,9 +1352,12 @@ EXPORT_SYMBOL(bitmap_release_region); */ int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int or= der) { + unsigned int nbits =3D pos + 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, nbits); + return 0; } EXPORT_SYMBOL(bitmap_allocate_region); =20 --=20 2.39.2 From nobody Sun Feb 8 02:55:56 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 60CD2C0015E for ; Thu, 27 Jul 2023 02:02:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230355AbjG0CCe (ORCPT ); Wed, 26 Jul 2023 22:02:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbjG0CC0 (ORCPT ); Wed, 26 Jul 2023 22:02:26 -0400 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53D53F5 for ; Wed, 26 Jul 2023 19:02:24 -0700 (PDT) Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6b9ec15e014so403674a34.0 for ; Wed, 26 Jul 2023 19:02:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690423343; x=1691028143; 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=/d6DIVKFawOMMIJLnYm8D4xwWB9Dgojb3pJDV5k1BWo=; b=IKVSlvEBuLb8cq54LSOaCvpKeohRZhPCwM+ZGrqES/emJidsTD1ZfsklKwzo93ATvi ZjsByhGPaaTx2ul5l6jP/tnhBK4nZzmpBcRRpNLig0ruJubaPVDrfdS2BzvUOGsPJIF0 Ypi5z6UPfqw8t8fgpI3DIp7KtqPRgx1tuY2AhyiYSoY9xuq3fvbIA4We4w0z1WLn1vZi 2tLifF6mC3wkpDcPGmm51q+YDkNq45vdsulZcO7hNQIjuL2/ip/FSULPgC1y5f5qG0Qf gT4i7AGUs+FTXrk5XWmZx7BVJHQVC6TIdkkJwwu4V4F4Lfh6VSRvRmxyK6WDdGCSM0dq Oukg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690423343; x=1691028143; 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=/d6DIVKFawOMMIJLnYm8D4xwWB9Dgojb3pJDV5k1BWo=; b=KtL/joqJzfy+Vyig9Wj+yvTfkjHHSYxxne33xpGlT9M3ku1dBFyNkpAS31Gef4t7PM LS+3IKzele50pwDmKRr2kVMzs9r3nKoAEwouAQmiuG6+v2ENZraeBlkkTkmNqREcLM6I +DNhPYasXVuDcpO+g3Rd0+yP2NxwE7Y07vhV3wllj7eta3p8WnAHDkRSGkt4u/6xsGUR YBpocc4WBufnuko6/575P3Lj+UEmuo1ElUz9fc42qoeXoPnXsmxB41RI8+GsPrIp6VmC QS9QWSOTqqBdaW30JPtGV99ARv90yOLz5SK2hLZKJXJojXQqjd6giHemlajrNFaT3vHE Z9cg== X-Gm-Message-State: ABy/qLbgeowx3b0QqOkrSKb8+EW8boGIQ89MEG5cg1BK8NFqGEcMSS6U GHk3na+rBB2B/wcX6gXLNaFqJAiGiG55SA== X-Google-Smtp-Source: APBJJlFjpHVjAga5y8aJXK5X7B5sanIetM6OhbfApqpDPH85bGk7/kdrEqXpz0n5eJaTDQlJoDzEdg== X-Received: by 2002:a05:6830:1050:b0:6b9:53ff:7513 with SMTP id b16-20020a056830105000b006b953ff7513mr3980719otp.34.1690423343206; Wed, 26 Jul 2023 19:02:23 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id z8-20020a17090a398800b00267f1455d60sm208692pjb.20.2023.07.26.19.02.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 19:02:22 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH 3/6] bitmap: replace _reg_op(REG_OP_RELEASE) with bitmap_clear() Date: Wed, 26 Jul 2023 19:02:04 -0700 Message-Id: <20230727020207.36314-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230727020207.36314-1-yury.norov@gmail.com> References: <20230727020207.36314-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(). Drop it. 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 346b848170e4..9be083ad71bf 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1335,7 +1335,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 Sun Feb 8 02:55:56 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 D60FAC0015E for ; Thu, 27 Jul 2023 02:02:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230245AbjG0CCn (ORCPT ); Wed, 26 Jul 2023 22:02:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230356AbjG0CCi (ORCPT ); Wed, 26 Jul 2023 22:02:38 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02CEA2139 for ; Wed, 26 Jul 2023 19:02:28 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1bba48b0bd2so2755565ad.3 for ; Wed, 26 Jul 2023 19:02:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690423348; x=1691028148; 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=muQcnaFQ3olJEak0NF0aGgOvQeQ9I+wuFJc+tIo+YJ8=; b=nwe4+YEyQi6i81SK443t1/Qsn/z061kBXYrrc9wWsp2XZVh+dpDEKIvJbGfFHEWiXc GmJE8pnFxzerOhmlcQYicoLDU/VHlfdJNzUyWEIScWyRMQs/BcW00EVDRAHqio49haYu pkVKq4DouMbxV41Q7Q/0QecLESEV7VHmJbiM05GoX2JobOurogfXEWv2g2SyU74GttxT 4iq8xyBJRjjXZKOKATP2yGR+8L7IVJcncsrTSIqWD1NApmUa7M6RCo9hSnR0orjcdQ4K SkQl48rDBM3ZlwuZaxAHsHf2EMw1v5DAzH/O+edPlKQboymulN7Z3Gn0T3AXCiFQZXW5 bAGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690423348; x=1691028148; 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=muQcnaFQ3olJEak0NF0aGgOvQeQ9I+wuFJc+tIo+YJ8=; b=NTntw00u59STTNvHxzwPlvT4eVh/sBd34phAr5a7IwOzPQdeM7l2tXhzcsyVFnK546 EXK2KIFOeT3MGcXE3n1tKZ+g5ANwfzYO9AOabwwluePzGo6goX16C1WgpRrtcQzeEFbP CIb6oL8noGNI1fDtqbdqzfiTDkPfm9iN7EwvoPwQyRl+F4/GUMUToRIGhxrM4Gp1gcOn 6eNUl+6+gW2IO9xdQ4Oqygc7ylkHp6fCSYMPywhnQuOWRap3Kle4oSMa/y8IiTiFI288 mbffTaLX4/evBACwyXDyNq65NjnH2GJi7lfP3qFGmJ7i11/nNsdOz2i+H464heZmKKzC 5UvQ== X-Gm-Message-State: ABy/qLawE+4nHnTiI1lqfuVEGX9hW82uCQpb8CdFgGbaOWDvNDKPiZ1v QfKe6k6YNCgGKKnRI5wsyg0S8y4CmFX7+g== X-Google-Smtp-Source: APBJJlFU97S+aZxoKJH6Zgy5xOHnLIpAArSTuQ/RqxKIU+ltvE0/QEIcplLyfATaOYZGgXZqAhCDaQ== X-Received: by 2002:a17:902:b694:b0:1bb:25bd:d09c with SMTP id c20-20020a170902b69400b001bb25bdd09cmr2723224pls.1.1690423347650; Wed, 26 Jul 2023 19:02:27 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id e4-20020a170902b78400b001bb7a736b46sm230990pls.104.2023.07.26.19.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 19:02:27 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH 4/6] bitmap: replace _reg_op(REG_OP_ISFREE) with find_next_bit() Date: Wed, 26 Jul 2023 19:02:05 -0700 Message-Id: <20230727020207.36314-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230727020207.36314-1-yury.norov@gmail.com> References: <20230727020207.36314-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(). Drop it. 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 9be083ad71bf..e0c3bba79181 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1354,7 +1354,7 @@ int bitmap_allocate_region(unsigned long *bitmap, uns= igned int pos, int order) { unsigned int nbits =3D pos + BIT(order); =20 - if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE)) + if (find_next_bit(bitmap, pos, nbits) < nbits) return -EBUSY; bitmap_set(bitmap, pos, nbits); return 0; --=20 2.39.2 From nobody Sun Feb 8 02:55:56 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 7F689C0015E for ; Thu, 27 Jul 2023 02:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229938AbjG0CCt (ORCPT ); Wed, 26 Jul 2023 22:02:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbjG0CCm (ORCPT ); Wed, 26 Jul 2023 22:02:42 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF9052D5B for ; Wed, 26 Jul 2023 19:02:31 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1b8b2b60731so2690435ad.2 for ; Wed, 26 Jul 2023 19:02:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690423350; x=1691028150; 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=3wwm/gViyZb0bI4gStUbGLvXclrv40DnexcC/4FNgNg=; b=I4QhlzEZJlABhRD76RVW081j9KS4wZlXMNp1tfW9qOESs4AkH8mwhul7Cw2pccxsEF OsPfe+gWS86FA9QMRI/IQsmTQpF5+OVlJdIwaPW5MrJmAj2RuDmylTX5+gDWq8qIsL7G 27jO0Cj5P8VJwFXhC844c1eToOC9Oc0sRQDtxW6NR4eeFvKaZRIVMMwwDC9r4P3QVB1H eE/9V7VKNlbDUtkIidiLr6izLK+KGMBaWdbbqgYmCJ71Ds8Q+r3WW++hoWCJy+HZLlCc T4XJF3nAdZ6xKM8WtB8U0VcKyavpP0ivb9bvs/a6pTs8mO33vOAkrpaZ82/c1jnukDRi o3Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690423350; x=1691028150; 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=3wwm/gViyZb0bI4gStUbGLvXclrv40DnexcC/4FNgNg=; b=OwbA+SvffwXS6GS0BPPyM4KuwksUea7mXWNFjW2QDua12qkHC5wN6i8Up/bvzu5jtD anBSYZG9vRtfm/vwtqjtq6ms0ao8YnSQoFZCrsIRL9drA/GqFsXm2JlTnmny2IaGYr/Q DrZb7V7NYfglq+opigtSJZQKCn0G+1PuYGxqDXEm3zZWOkioORNGpAbavfNGRXm8VCNR lxlV5HfEaY8JFgDhp9Qn3ABTBencauGkgSXKS+QuRd3uQ8YGGiF4Wz116ZgWsDHFsLmI Ivh52dM1vpVBgt5MIDVBvOiLFVuBHA8B5M/E9law8T9LTwJxlNZnjtwPiDuZCR2Q4Wlo 3zEg== X-Gm-Message-State: ABy/qLaAKd1R/QhDH3oC3EYlImO2ZuAuBZbvu/Ou21bRz82LMBq9Pa2N 3hUtvK8RnTk23NiA3yEcPTjtYwPIJO7zEg== X-Google-Smtp-Source: APBJJlGrLuH2xSAYirx4M4reqqRMO2+z6djClfgPE1ZE1DGAILZmcKksxVxU+/dlGPo0nhJryMhe2g== X-Received: by 2002:a17:902:d4c1:b0:1b8:1b79:a76d with SMTP id o1-20020a170902d4c100b001b81b79a76dmr3185315plg.44.1690423350179; Wed, 26 Jul 2023 19:02:30 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id jf4-20020a170903268400b001b53953f306sm221850plb.178.2023.07.26.19.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 19:02:29 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH 5/6] bitmap: drop _reg_op() function Date: Wed, 26 Jul 2023 19:02:06 -0700 Message-Id: <20230727020207.36314-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230727020207.36314-1-yury.norov@gmail.com> References: <20230727020207.36314-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 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 e0c3bba79181..7cfe0b442c73 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. - * - * Returns 1 if REG_OP_ISFREE succeeds (region is all zero bits). - * Returns 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 Sun Feb 8 02:55:56 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 19EA8C001DF for ; Thu, 27 Jul 2023 02:03:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231195AbjG0CC5 (ORCPT ); Wed, 26 Jul 2023 22:02:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230431AbjG0CCr (ORCPT ); Wed, 26 Jul 2023 22:02:47 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C1AC30C8 for ; Wed, 26 Jul 2023 19:02:35 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-686b643df5dso384952b3a.1 for ; Wed, 26 Jul 2023 19:02:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690423354; x=1691028154; 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=SJiXy/aSAKGmCQKaY16SsuP/c/XgbaK7793lnhKddOY=; b=Q1SUTW6xJiZ/vNrA/wzX08DfryWTulhgAkq/EN/6lNbEANXOVyBy5vq8uxTeZbGFcw umbiwfirDCFVQStskPKR9+cwexZK+mEqA5iowAC6QMON4ijCV9E8hBa00diHTK53ZEsJ uovpfNZbS3KQ088QeMvLYB6LzCfa9JFryZcHNTYyw7ScN6KSZvlvHjgLDRkVwWAx3Mnq EIhJvSO4+0EzSH5cg4l1JbJG01lofbSEip+y1GElamWCDxbzkULuy/zcEgkh4sMYUSFW gEVIsbdZo//2a0uU3zvt4jOnAEoXQsZg80lK6n7os6mSlPZAsgaerbLi1EnJMZu4EqUf 8K2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690423354; x=1691028154; 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=SJiXy/aSAKGmCQKaY16SsuP/c/XgbaK7793lnhKddOY=; b=GfX/nVgrD2wTPFaTzocv6BYFQmN1XiYAklYNDoIjrawxxPKbK+4kWH+uuhP/pHz5/q 8MKZiTqf9yZgK0HLK8wKzeq3+wgYOIB40cnAMsz6DkXCO6BfWi8Eg2QLXg5cZi9JRat3 vLC+d+HkE1L8hn73GEOPn1YhstsvHqSEwE6f+URm415FZFaeBeDQTA4Jr7+d6p7dmaHM NOMN+jcRRs8m9Q44NYHOQR/oaUGJwAyJPZwSz/qy+SChDUepyUFWxhKu/WwTNnIBZgIe gRrQdOTdY733hBtWqaqUgT0QipP5Hzy9nNOM4FKASxrd0zMkMRerYCvSOYLsHK89eMyF MRuw== X-Gm-Message-State: ABy/qLadx3nul8nCsDwbHjwXIvxyzxwrazGhi2vy/YkwVQxa8Rgfb2MD I5m5a5fvHecSVZXGAGFmu+aikZ6w+ZM6iA== X-Google-Smtp-Source: APBJJlFhe/VDUbWXklEqRqVigUWiBB6Px7vr2ipeO3qdSh4B705E06Nkxu6ab79wnkqAY++3jDIklQ== X-Received: by 2002:a05:6a00:cc6:b0:666:8cbb:6e0f with SMTP id b6-20020a056a000cc600b006668cbb6e0fmr3980846pfv.3.1690423353845; Wed, 26 Jul 2023 19:02:33 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id t28-20020aa7939c000000b00682b299b6besm258735pfe.70.2023.07.26.19.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 19:02:33 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH 6/6] bitmap: move bitmap_*_region functions to bitmap.h Date: Wed, 26 Jul 2023 19:02:07 -0700 Message-Id: <20230727020207.36314-7-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230727020207.36314-1-yury.norov@gmail.com> References: <20230727020207.36314-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 | 65 ++++++++++++++++++++++++++++++++++++++++-- lib/bitmap.c | 65 ------------------------------------------ 2 files changed, 62 insertions(+), 68 deletions(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 03644237e1ef..6c8d28419616 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -216,9 +216,68 @@ void bitmap_onto(unsigned long *dst, const unsigned lo= ng *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); + +/** + * 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 + (1U << order)) <=3D bits; pos =3D end) + if (!bitmap_allocate_region(bitmap, pos, order)) + return pos; + + return -ENOMEM; +} + +/** + * 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). + * + * No return value. + */ +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 nbits =3D pos + BIT(order); + + if (find_next_bit(bitmap, pos, nbits) < nbits) + return -EBUSY; + bitmap_set(bitmap, pos, nbits); + return 0; +} =20 #ifdef __BIG_ENDIAN void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned= int nbits); diff --git a/lib/bitmap.c b/lib/bitmap.c index 7cfe0b442c73..1c5d1f5d2071 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1220,71 +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 + (1U << 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). - * - * No return value. - */ -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 nbits =3D pos + BIT(order); - - if (find_next_bit(bitmap, pos, nbits) < nbits) - return -EBUSY; - bitmap_set(bitmap, pos, nbits); - 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