From nobody Wed Dec 17 23:49:49 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 87898C04A94 for ; Tue, 15 Aug 2023 23:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240638AbjHOXhG (ORCPT ); Tue, 15 Aug 2023 19:37:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240620AbjHOXgi (ORCPT ); Tue, 15 Aug 2023 19:36: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 06EDF13E for ; Tue, 15 Aug 2023 16:36:37 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1bdfb11ea2aso7747105ad.2 for ; Tue, 15 Aug 2023 16:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692142596; x=1692747396; 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=bNrK9GyOkfgy8vFobQz0dvafv7zThWTFwPQDrVe2f4I=; b=p9FgoXqhPY+caeRBg5x1v9jj3nZEGLTU48KrS2KlEmkRDKV0RT/UJsjXo9nM99dSv3 6NUp2tv0eFUdFnczbZEGXkHf3xTX8B1/VhySK44OJUWb5N+euJdLicAoN8WOlCkWl9l7 U7BtG5ntxwNeHUhejA8qHhKAcOoV8srAtYpu+YhTJxefzypUwSDzxos80uXduqrdH+5y evi4f2+DricjcX5wzquzepILzt30KZkxbgEy9ASHwtXPiq7oQ5uJsCdLhgf0HfjR+3tF LqAh+nWgQxn59VOMj2IIxex69BK6Gl113KR6GUnYeYNKaEIhGNdB9gGLH9m0zlY8oPZP 4hCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692142596; x=1692747396; 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=bNrK9GyOkfgy8vFobQz0dvafv7zThWTFwPQDrVe2f4I=; b=YSL73nozXBs7TDseVQnTR9DjiBEa4uHO05p+oyDG5XzHh5RGjdbnl6wKX9s0BX5Kkr 7B6o8n/iCCVevZBSC/FjanaqVty3FKW9ioYmyyNxpce3gUnkgw4zJut/isFogEZIW1UR oahblr9cK8MkRK0LvOgwMRIdRmchT5g6RiXyUWkMKFzpquWJ6Bfp188dhZlNw80Pwx24 RmafIPzVd2AlKPQnGaYWu0QdlsUVRfnqIu4AYg5ss7kAQtZaeHbjQ++PqDismIsKg1Dq X/0g0IIo39XQrvJr5/kYV/zNI4FCg04eZFypPTz+CK+dyNHPLn7Qqxpx87c2MKmKwyaU A7tA== X-Gm-Message-State: AOJu0YzjEkzjKL7ZdMan5FZhx+28q2yz12AxOcmDA7ZYFSrAS8xWpjjQ fgH6p7PEMWbTil2LbhGjebx5e5DE+5M= X-Google-Smtp-Source: AGHT+IE7TAvabQnBsSvv+XtbuxOtnk9uAp4T3mP0sq699ScC33mKn76Zwz//MslUFnbsTz8oBlwdjQ== X-Received: by 2002:a17:902:8215:b0:1ac:63ac:10a7 with SMTP id x21-20020a170902821500b001ac63ac10a7mr252835pln.68.1692142595931; Tue, 15 Aug 2023 16:36:35 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id ju11-20020a170903428b00b001bdc3768ca5sm8178907plb.254.2023.08.15.16.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 16:36:35 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH v3 1/8] bitmap: align __reg_op() wrappers with modern coding style Date: Tue, 15 Aug 2023 16:36:21 -0700 Message-Id: <20230815233628.45016-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230815233628.45016-1-yury.norov@gmail.com> References: <20230815233628.45016-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 style in bitmap_find_free_region(). Signed-off-by: Yury Norov Reviewed-by: Andy Shevchenko Suggested-by: Andy Shevchenko Suggested-by? --- lib/bitmap.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index bf6b0eea1af8..76bf79261107 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1238,8 +1238,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 { @@ -1311,14 +1311,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); @@ -1336,8 +1336,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) { @@ -1353,7 +1351,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:49:49 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 A8919C41513 for ; Tue, 15 Aug 2023 23:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240644AbjHOXhH (ORCPT ); Tue, 15 Aug 2023 19:37:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240621AbjHOXgk (ORCPT ); Tue, 15 Aug 2023 19:36:40 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6D1313E for ; Tue, 15 Aug 2023 16:36:39 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-686daaa5f1fso4153299b3a.3 for ; Tue, 15 Aug 2023 16:36:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692142599; x=1692747399; 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=E3AlzGU/to4Xl1KzwzjbqvzpnXCRrEvWt3l9FSMWBlM=; b=Y5j3+25u5jV0XpIm0/9JU32Tq++HKy5GE0mQ486AHQDAytaUtGEMxX7V6yjBFsb5w9 FnL3vqqS7BF0hupHl2Tt4DvE2rt/E01EmVwnjnmT16rmb9naN/qAfB3wj70p0qCveK0P f0bHJ+gvbRAIR23Ow+q5hAQU7RkZBnAtSlxCcSnzdwPfiVdUtMIw3sTqA7t2dcLuR2ar I5aaXOykvFw3cCEPwVcpsHiGLw0jdX1VoeZdXjRGnfxt5wpirmgEISDbrZbDIH6XWbAk yUqVuGpTgGAls+Kd6wmzTA1aJxz5hyh0pN3Lsb5lTmuNzlj8ON8GQtfWDPT7GpGCxSzG zxcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692142599; x=1692747399; 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=E3AlzGU/to4Xl1KzwzjbqvzpnXCRrEvWt3l9FSMWBlM=; b=Vtm3bVNFPSRULCEBKZwU3lelTEM2/nyasMlSlGbtMblIF6WDnKyibimdHM5Nu11318 Yenl/KMPdqdwRvrWFjXdQedA7Hj9iOvsbfFkymtrtiIvGyNmwjacfYnNMUUsn/HmeR/d OLgxGofMoJeFaTM//XmL008cxhKa9uvaznybnOadXbZ5c6j38bBIRMar1kubUhXdW8CD kpogwGVG9LDo+LifOsWhD78Cw/ZUb2GjWwsxQ2+aG0Y8ZPiKCjyRwLHizHf/+Hqjwxw9 jq5Pkg7jSZ7pobsjorKLWUesXkIkhw8X0RTqPNeoSOaDRE7N9hEwna6jrPyBpfMKBjNT rc8w== X-Gm-Message-State: AOJu0Yy/+nFPzb6E3CEevI94HMu4dvnz2zcnIDTu09VUX/PrsSUN3TEL 2Ys3xmMrcdSA3QVy0JCR+kpilh7Ew/A= X-Google-Smtp-Source: AGHT+IEE5u2ZK0cfCsgIWsn8Vz7z1VP+m76K8MG1XeGMDBI+rX5Zl1vqL8JDuf30O2sna5EiFbi9lQ== X-Received: by 2002:a05:6a00:c92:b0:687:1604:39eb with SMTP id a18-20020a056a000c9200b00687160439ebmr250905pfv.25.1692142598978; Tue, 15 Aug 2023 16:36:38 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id i15-20020aa787cf000000b006875df4773fsm771855pfo.163.2023.08.15.16.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 16:36:38 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH v3 2/8] bitmap: add test for bitmap_*_region() functions Date: Tue, 15 Aug 2023 16:36:22 -0700 Message-Id: <20230815233628.45016-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230815233628.45016-1-yury.norov@gmail.com> References: <20230815233628.45016-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. 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..def7d2f9bd14 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, BIT(order) < 512 ? 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:49:49 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 BB1B2C001DF for ; Tue, 15 Aug 2023 23:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240649AbjHOXhI (ORCPT ); Tue, 15 Aug 2023 19:37:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240622AbjHOXgo (ORCPT ); Tue, 15 Aug 2023 19:36:44 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A08813E for ; Tue, 15 Aug 2023 16:36:43 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-686ba29ccb1so4004661b3a.1 for ; Tue, 15 Aug 2023 16:36:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692142602; x=1692747402; 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=hHD7wUMcR/IeqBhQ/f6jYRlMrAkqr7++FIIFzS8UJGc=; b=jDsPUuqhIcHgswnWxC6LBLdtjE7d0YrR76YpcxHP/GZ/oWUJbXmLTknCSiH1DFdeWt EvegoLMxlIQBMuK5PfOiHkt8draLwUGwpNn/940sGppmusDwmZIU70QBDXXYS3Ai+T3A sX4NUlaRkuqRkV6plQmDBgL/kgQTZrG5YKW+31vO0RA/YTWhLTklVyWkluZOhQMDUkfq lLbnWD2Ta827S8a0fDRZhI/35xIW7W8UDGF4vbTU5Z+SCzLg3jIUQLMmwDa6EPBHebWm IRnau8c/JFvqyUf4lPKIZ5lcsbNqxDxDUMYOTY8054i+Z9Wm3J7vCoj7gYg18TYRRneY kx2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692142602; x=1692747402; 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=hHD7wUMcR/IeqBhQ/f6jYRlMrAkqr7++FIIFzS8UJGc=; b=WpkMewCs13GyR5VcP1y5t18grSqpIM8CB73S45bg5qeSnmzOe1v0OPSdrJ+mYwSIdQ 40sSY9T+dONI5XR3ly9F02VYEfx5vQXqR1r96Md7iyyfTzJ5Teue057gEy9sVI9MHJkS lkcTC7m2yJgPDrZcnsovXwyBILgfHgP14FoNPVAP3I13suNZOuDphSSxNQuqEdiapDaX dA36MSJ1OxietYmHHqRtVnWPrPN4l8tpNjr3XVu4rsd36oBLxuvGxR7XYVxprY7QHBWZ obUyq7F1wUvD14WyLTuF9EFLXVsG9WGAMJv7f1YxZOeLmszF8wYlRrypcPHtTX2r30k2 3WBg== X-Gm-Message-State: AOJu0Yy72ote36CwTqSQK1Bv5v78OKVRcvHYBSZk1B072sgAJYSxhGJ2 PJ6qNwzwBMQ0Kdm9X1O4JR5S/4vjUh4= X-Google-Smtp-Source: AGHT+IE8ZrYkAgXGGlouo0bXXtQI7xXQfhsmnYeQ5d7aYjtQZXNfb+Xxn7fZDSNFnBIB/b9UkLX/xQ== X-Received: by 2002:a05:6a20:3952:b0:143:c453:814c with SMTP id r18-20020a056a20395200b00143c453814cmr478669pzg.18.1692142602255; Tue, 15 Aug 2023 16:36:42 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id ff10-20020a056a002f4a00b00682a8e600f0sm9884943pfb.35.2023.08.15.16.36.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 16:36:41 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH v3 3/8] bitmap: fix opencoded bitmap_allocate_region() Date: Tue, 15 Aug 2023 16:36:23 -0700 Message-Id: <20230815233628.45016-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230815233628.45016-1-yury.norov@gmail.com> References: <20230815233628.45016-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 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index 76bf79261107..4c9f119240cc 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1319,10 +1319,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:49:49 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 CC9B1C04FDF for ; Tue, 15 Aug 2023 23:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240654AbjHOXhJ (ORCPT ); Tue, 15 Aug 2023 19:37:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240623AbjHOXgr (ORCPT ); Tue, 15 Aug 2023 19:36:47 -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 D903013E for ; Tue, 15 Aug 2023 16:36:46 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bdef6f5449so17154245ad.3 for ; Tue, 15 Aug 2023 16:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692142606; x=1692747406; 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=/MXMbfduNsWvc77oRSmnPlmSNU8ovvpGLo9LCB6NzM8=; b=f4bbNFRmU22uvlvSDb+GZMtx292gUoyz2khtCihMj0eWPFC9DKPq4qUD6N8wQkhust zFKImYWZeuBEkjq/Yrbsqbl4ia1F3n5gtfyINCFU0rISryN3p7ye5nzuf/B1pNZ5WkKB /LTtdGWb6kPoY/sva0doQDTq8QyCe0lUoQY//NsWrAw1cY7Sn1QvqNpRTHxpkKejDHOJ +UYIlb3eEwlBWjqr/RE1eDs9nxSbpBcIgBad9IjWV8oKa1V6FIcL759x4nWfD6JwFkjf /LGtMOLfQzaVohrTzkvbtp3PwIGP1iHy2pbMheKVhopwlauYvtD/lnUnInmfDRVaHiJG W4sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692142606; x=1692747406; 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=/MXMbfduNsWvc77oRSmnPlmSNU8ovvpGLo9LCB6NzM8=; b=blfGHp+2/hB0D0JKb9PJOqExgWyb1EiZXDhiXQDOYUu0o6fhVpR4snNfY7vOx3QxVT 3oBqTlROky81HfFYrrr6i5c3Vlvz2BTIUPUDF1y/F5cHY28K/rKwlSlmEiSzltVvwGua afT2S0H280LAQxt2LtLdwSlkT+/grJUIHWJ/fY0EkEdyzYLWJHLj0Xed8uEbih1+Paif ehZOdu147w7zrMMJiTS45QJCDSBpMIjazcWHs/aw6swpw35ZNxTZZACAtpcrrAZZV+cB Oqkdrk3heDgM1wsLEVGvoQX3Nxk2h6DSWreHYeSbNooCZdr05qDDdSijVWFBkSxxCct/ CXJg== X-Gm-Message-State: AOJu0YyspZEU3ZoTyH9rYCFvwftt4Ao5QyAJml4ey70RAZmu89x7KaQ6 Oga6tRgyiZxN9/oVBymTRXCiDTpRX+4= X-Google-Smtp-Source: AGHT+IERQ9IKfxQP2jKRd8x7EC9qE5L8ytRPOupRf9Ktwlv7jH/SIuvsBxYTvgK3N9BND7qGB7OuNQ== X-Received: by 2002:a17:903:2796:b0:1b8:8223:8bdd with SMTP id jw22-20020a170903279600b001b882238bddmr355939plb.59.1692142605829; Tue, 15 Aug 2023 16:36:45 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id x5-20020a170902ec8500b001bde6fa0a39sm4104226plg.167.2023.08.15.16.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 16:36:45 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH v3 4/8] bitmap: replace _reg_op(REG_OP_ALLOC) with bitmap_set() Date: Tue, 15 Aug 2023 16:36:24 -0700 Message-Id: <20230815233628.45016-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230815233628.45016-1-yury.norov@gmail.com> References: <20230815233628.45016-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(). Fix 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 4c9f119240cc..b7ea47b9f09d 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1354,9 +1354,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:49:49 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 E655DC04E69 for ; Tue, 15 Aug 2023 23:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240659AbjHOXhL (ORCPT ); Tue, 15 Aug 2023 19:37:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240624AbjHOXgu (ORCPT ); Tue, 15 Aug 2023 19:36:50 -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 1B98B13E for ; Tue, 15 Aug 2023 16:36:50 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bc5acc627dso40009525ad.1 for ; Tue, 15 Aug 2023 16:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692142609; x=1692747409; 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=VO+SrF+5VgwP9Hr4BPfpf01QUQcSzSGpK+hCjWqxDDI=; b=m+YpORYKHBZRy0daTvbNKQ7OxF8whqpiLWwnJp2GH2f4C6O3WUHnm5z6MNSHaPxpdX BX7U3CmPSP3YbJuU8mzjJLR3OGCMlkrPLwOTHl74zrub0EiGo/d9K3abHMEdkxtPTZpS OZ/QxsYop9BHdgvtgaTWbd3sGlQSiTDVVCwF8C7Ok7EcFLVCrvs/AIc9mC6m9CDtjNy8 PgegimvAH/05/6QwwCc8a1djO6h15/swKMMU1aAp8VJ5sCO+D6kc+R1u/NAzLCMiTS1f TWozFokWkbjzCaxIr2GXfNQhJhcdJjjwzclUDSjTNSQffVEK7+sgJXSMar47uNN84CXz 4qSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692142609; x=1692747409; 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=VO+SrF+5VgwP9Hr4BPfpf01QUQcSzSGpK+hCjWqxDDI=; b=a8ZpjpP95HDlFZFuLAL46YAMPL7RgxtgIX4V6Sj8S7QnPZwX8YI+RObUn2ZzPQDsS5 tov+4eq7o9QybgPTrODYJP0mjlA8tjocjL/rQ8167gWQvoLI1wp37IWEWl4rwEGttPFz S7m+OvNKRrdhKVdgiyfJKSV9wtaNBlsxXrXgBzCvVdLta87JClUuoTHk+ckRIUn3WBcO 9PBo3Cps5ScNbMkS7T23yqnRXwVBoFDLTjMqTqsKGp1CuVAgZHBJRSK4J0aelQX3OzkS nioo47KJUgEBY+LeZWZCgnmt2B+XYi+Aiz5v2r+i1gOEaXDaIYBt4NjMwOtArbSVi8RN 0zvA== X-Gm-Message-State: AOJu0Yy7TQ9xOJHMt0eIrMcfAfIEWU48Vl0h8hz/wZPZOtSt5kUqiR72 OqZdIGUaoNHqoV8nWT4S3ZhT5vBYDog= X-Google-Smtp-Source: AGHT+IFYoR0BMzpCcKWs/U9BPFs89FaiscuKJLHcnTxEmj/DzeFIqKVD2MuVt7kbvtEIlAUx4aQS3A== X-Received: by 2002:a17:902:c94a:b0:1bc:6e8c:eeff with SMTP id i10-20020a170902c94a00b001bc6e8ceeffmr359942pla.43.1692142609116; Tue, 15 Aug 2023 16:36:49 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id p5-20020a170902e74500b001b9de2b905asm11582621plf.231.2023.08.15.16.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 16:36:48 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH v3 5/8] bitmap: replace _reg_op(REG_OP_RELEASE) with bitmap_clear() Date: Tue, 15 Aug 2023 16:36:25 -0700 Message-Id: <20230815233628.45016-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230815233628.45016-1-yury.norov@gmail.com> References: <20230815233628.45016-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(). Fix 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 b7ea47b9f09d..2898ec2bdef1 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1337,7 +1337,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:49:49 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 150E1C04FE2 for ; Tue, 15 Aug 2023 23:37:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240665AbjHOXhM (ORCPT ); Tue, 15 Aug 2023 19:37:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240625AbjHOXgy (ORCPT ); Tue, 15 Aug 2023 19:36:54 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8D5613E for ; Tue, 15 Aug 2023 16:36:52 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6887059f121so725774b3a.3 for ; Tue, 15 Aug 2023 16:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692142612; x=1692747412; 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=SiYOATL4Yt0CXg+oEOLFMOCykgPiyRQW/lZP421Tl8g=; b=oyAmxVZ1Vfx8ISf3Ltk9F9p2m4nKztfLvmNcmi5JJfPy3lBwel5j8bD8e8bJg7wlDm ob91Eh8fK9lcs7DPYRuDODy4O7di3Cgxj038h67hePvpRDttH9ZLtSYMaszMa00YEEM4 Yb1657fmOqvlQ4Eot9UDUZkUffLewAsXXlNKQZ7FwuCFFGZSK4aTaU2D2TkkPXG3a3GW HtSjCFWvGmradvjPXRk+JMTNHJGQdKJh46rGoV1NZPKnjcE4a37IAryZmtTj3IDCsMYH m27C7Zl2vtOiTvDc9WbGvT4U0Qm9pWfnevpG1OwTTspJZ5KSL7hXZVZ97dme0vnCE0ZF U1Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692142612; x=1692747412; 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=SiYOATL4Yt0CXg+oEOLFMOCykgPiyRQW/lZP421Tl8g=; b=dLKO7aqvcxIm0OOD7m6TtSkIxHB5MdWZsu2qya6JzFfa0K5PkI5C9uKKr+421eWIja BUWKQ1ZXqik2tiVTh9jUnv5qcLWDreiJCe3BHAvhL92EbWb33HuhJ7DYhBbOsEuN7sij IzKwVcuzfJq4709epHI+f3ypPwiqKEXGPDp0aJF8CPtXa3550gs0yIVm8no68NbwXoRK tmKefKLwTeVMLm8DsGh/6rVJLRNLzbEyugLgOWinUsVaYpuxpK4cAye23do38yU8Q42+ aewjjIGiST9tpvmhXdUK1F3RVZU6A7UsYDu/Cv3RFPVEM9C4+xPjn30rxwmFdC5zAKSL ADNQ== X-Gm-Message-State: AOJu0YzKw5b3gOONtwQTJfYL06xuI3jaHikjKe8P+LIHi+Q1B6Yfv1uv CCv23hv36+ihdLF0TUcs6weOdydmDIM= X-Google-Smtp-Source: AGHT+IGw3e3HBJ3B2RxSt5fec/v+xG1BnUI9IMBKv0mv9x9Q79spXvimRIHSZd70+JUCn0raG+6trQ== X-Received: by 2002:a05:6a00:1393:b0:668:69fa:f791 with SMTP id t19-20020a056a00139300b0066869faf791mr279325pfg.3.1692142611977; Tue, 15 Aug 2023 16:36:51 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id u18-20020aa78492000000b00673e652985bsm9823073pfn.118.2023.08.15.16.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 16:36:51 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH v3 6/8] bitmap: replace _reg_op(REG_OP_ISFREE) with find_next_bit() Date: Tue, 15 Aug 2023 16:36:26 -0700 Message-Id: <20230815233628.45016-7-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230815233628.45016-1-yury.norov@gmail.com> References: <20230815233628.45016-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 2898ec2bdef1..c29140e27d20 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1356,7 +1356,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:49:49 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 02137C04FE0 for ; Tue, 15 Aug 2023 23:37:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240669AbjHOXhS (ORCPT ); Tue, 15 Aug 2023 19:37:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240627AbjHOXg5 (ORCPT ); Tue, 15 Aug 2023 19:36:57 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F9CD13E for ; Tue, 15 Aug 2023 16:36:56 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1bdf98a6086so10087105ad.0 for ; Tue, 15 Aug 2023 16:36:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692142615; x=1692747415; 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=MsmgxI2dDLH2ymR4KmGzcaJe1p1eps4K+t7hMi45DJo=; b=MsphCzpuYX4idGa4Gi885hd0RX7AwhMSkXR2PLk4+bJxfiMg9pdrme+8Zw9XFWv6uK vPcUdkTLAjEPSHYYVOzznjhMf+bFaad2WFL9JG+tCzzUJBgJkxgNpXytYGxZPKA2Vsij CRyeDZtCGWy3Iko+bRdJ9shEtXnhTpXZf5rGXaK5BPqfNxFlTBI6/gndcQPO7vdbbdca NbMWHurgoBToBk3r4ZmZnEz8iFCinEPDhBrH491pbfSYSUa0ihwTWm5szLp0N3+XvNFQ bxm2hmbJexZZC2QGRcfiYtmWkC4Z10jrE8n2Aiogqulj2NU+3EC2ck7cJeq9V0htFQDd S7rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692142615; x=1692747415; 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=MsmgxI2dDLH2ymR4KmGzcaJe1p1eps4K+t7hMi45DJo=; b=bad6WuOwQQuUyr7BZ2Teo3Kp1fahWSPbkO+YDIsy6itXrX0pDq3X6/dCGKN6dDmjRA Af6Y0usoC0krW79XHK72cU0SLVG8WgpM7HkTbFezNbGJAfg0SMB6BOoFN85BkryLnaQQ pSjnFoi5uVL+bMKDiVppRBRSMmSji1s/OWhJZ42nxcTYbPnsGJOSk4to0sRcgSIp9w48 4RiOIZR207cgi6j/TFPTnejLmQQ+Ipzbkcjux8aTNh4QG5Dja+F4DygMBU+3PbE6v45m vb6g4bV5kSlGLwWbOIxFtLt9cIonPt29nN7GCrgC+YJ+cZ7tXj5Sd99OYOsDLZ+PoJRc PTZA== X-Gm-Message-State: AOJu0Yy9IB8TWH0hjLjjGUW8J/JS3FydIe4m1eV+OTEqowOQh+eFjs0b d9bOqxoQg9NUjHB9FCwx65Z2rxQwu7M= X-Google-Smtp-Source: AGHT+IFLlpS4ukwyWWebufIvWo7oJDgo1x/KiX17zl8SGMHl2wrSmmRAJC5D202okZpWXFkemugIMw== X-Received: by 2002:a17:902:d2cb:b0:1bd:ae9e:62ea with SMTP id n11-20020a170902d2cb00b001bdae9e62eamr492121plc.8.1692142615155; Tue, 15 Aug 2023 16:36:55 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id m11-20020a170902768b00b001bb750189desm11607799pll.255.2023.08.15.16.36.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 16:36:54 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH v3 7/8] bitmap: drop _reg_op() function Date: Tue, 15 Aug 2023 16:36:27 -0700 Message-Id: <20230815233628.45016-8-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230815233628.45016-1-yury.norov@gmail.com> References: <20230815233628.45016-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 c29140e27d20..ffbd400605ac 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1224,82 +1224,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:49:49 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 2C4C3C04FE1 for ; Tue, 15 Aug 2023 23:37:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240674AbjHOXhW (ORCPT ); Tue, 15 Aug 2023 19:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240628AbjHOXhA (ORCPT ); Tue, 15 Aug 2023 19:37:00 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D9C71BFE for ; Tue, 15 Aug 2023 16:36:59 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1bdc8081147so23696185ad.1 for ; Tue, 15 Aug 2023 16:36:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692142618; x=1692747418; 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=7HM5VWSDcFnMpZztYnuFJvyiIm9Y9FSftVouXPEbNl8=; b=fFyuH+z3KHaZ/tgX5T9xzHdJf7O0JRfkATFtFmFY81mxv3ezDEbmlEiOhdnfSoiBou FmnTugGV5Mq17m028tFIOYBbhW7J3qUhd/uwbp4j0Lzr3D2LS0rwnEpIkfvC4Ht3x+Qg ucwbAHOMYf1IrANE/GzffC7OzTNJLdSpT18NiYiIGkn5depRLOp/ejjtTKM+3IzDVwI8 3t1vOms3fIoA33smVNj1V4+qUcig3WjpJKLU3hwSK9d+VdN+HEJxanbKZ+mAGFnF75Sv +/JZS3jazc+oq4husrvTBgC04ZwD2OSGb0A+89l7UC4jVcWkZsCIaTgZs/3RqU6zxBX8 4kYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692142618; x=1692747418; 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=7HM5VWSDcFnMpZztYnuFJvyiIm9Y9FSftVouXPEbNl8=; b=S+/AhvgV9E9ahMjt9rxG92PMrdMt3A6N4XzI0I8uubi5JGVfCZsOw0EpgBl/dWOP/8 hyVLr53r2xyUJadUYu95Fp6JCriepHJ/pyYHq85FivkI2inLYc/4ZAvjl+Dd7G128ePj AAegL05Ukoe6fHasYs5OsCgplwqweszxNebaZiew1L+dnMacLGUKr+dvl5fQXJF9bV4S w5mnaOylM3ukEhVAG+dkgge9ww1bfQfZET4cu7BWuUUy9ngzYxXio3tdGdH9kVM/9bl+ JxLWKs0/cMI47CzMIH+rnyunpmnxX5i57gWrWAn2vmf/WkOYOtLE5x0v214xQbGo/SUq ULvg== X-Gm-Message-State: AOJu0YxoKOVEWYQ4TdzRZLfxBjS0tAb2H9KHBuqJiJcILgjpcNt6K81q TNnvOPhnkULDkIMtuBguZRhwXVC6+2U= X-Google-Smtp-Source: AGHT+IHFTU3pnIcFkODHXEDxL2w2vj8mMMcquPUB9dQOkDlEkGFbVBqyy20MA+y+xiJ0dAj7AJ1lOg== X-Received: by 2002:a17:902:db0e:b0:1b8:af5e:853c with SMTP id m14-20020a170902db0e00b001b8af5e853cmr531075plx.26.1692142618121; Tue, 15 Aug 2023 16:36:58 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id w20-20020a170902d71400b001b016313b1dsm8230990ply.86.2023.08.15.16.36.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 16:36:57 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Cc: Yury Norov Subject: [PATCH v3 8/8] bitmap: move bitmap_*_region functions to bitmap.h Date: Tue, 15 Aug 2023 16:36:28 -0700 Message-Id: <20230815233628.45016-9-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230815233628.45016-1-yury.norov@gmail.com> References: <20230815233628.45016-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..cadb1113ae09 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); @@ -599,6 +596,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, 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 ffbd400605ac..001bfa8a3a71 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1224,69 +1224,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