From nobody Sun Feb 8 17:46:34 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 DB169C7EE29 for ; Mon, 22 May 2023 05:07:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231726AbjEVFH0 (ORCPT ); Mon, 22 May 2023 01:07:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbjEVFHW (ORCPT ); Mon, 22 May 2023 01:07:22 -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 4103B92 for ; Sun, 21 May 2023 22:07:21 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-64d18d772bdso4779279b3a.3 for ; Sun, 21 May 2023 22:07:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732041; x=1687324041; 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=ryAjJK/jvO3d1/ZbH/fm/OkRmr2azDVw5I6QoB1NED8=; b=E+sf9AoJVl+JV6FsfkR4Ym5XfHy/qlWHgn7H3ghjaIqtwrmDk4FnwTgtCboieHks5a 7Xju63Rz4/hQXtTjifn3Q9wRx22XGUz+pCJWITfM6TaSYKsoLU1m7GIB/8cxEfraWRhS 8ce7qTdNdx0Rx5AX64dHcGo1GeiRMKueARhVfIFMquyHtvURi2LrwtmBx+f+ZN0H25Jn IR5e5SLGTGTpYPbpRZriNanszs4xQ2Sv8FTZCoWCx2LI56hrA+MREB3TjANB0qTaIm9G tPlFNj6QITqQQlWtPss9HM0QZsSkFNpWPI7R91rjhIRzTZw+TQz16JYxWv25eGrOJKY7 bY8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732041; x=1687324041; 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=ryAjJK/jvO3d1/ZbH/fm/OkRmr2azDVw5I6QoB1NED8=; b=RCIMWIQanMhBxLoFfdlRs8zUsn1UkmRFfDs118LbHTO3R9pLLEaI3m2ybO7gZmFzJa osF43nTUfViaV/VmIbd+BB+K9GaQM8zpRf3upgfwpZFsiZrkesD30Or0H8lZqL4ni6tp DCsLdqVaXhz06KzHDjH4syW8adAEPn1WyERmgWjs08aBQGQ2BEfnhwPpGvsuTOsFGcGI mRV+cZx+yrs6FBls0hE68PBVGR04NJuaLd2xn7j01ljtLMgAc0mbFPG3s/4ysAJdyDip DYQ2EVFg4xyrtU7wBYAjWEK6yRTW22Sqm864TPrvjXrsTZtaAvf3F67CO6AdrWed4xPD 0VWQ== X-Gm-Message-State: AC+VfDwZVtRviMV5YFnwbRC4fdc/b1T5cYoPleZE/yorgMIuH7j/qG9M Ky3AaDW68IKqpiRC3AMSiUJWog== X-Google-Smtp-Source: ACHHUZ6Xjaki5a0wpYv6HPrx9PPhoRm0BZ5h3RO2p2wQiWSIZBHDnR5shbpMqf2VKAtyiIKtmnXE3Q== X-Received: by 2002:a05:6a00:845:b0:634:7ba3:d140 with SMTP id q5-20020a056a00084500b006347ba3d140mr13038011pfk.15.1684732040942; Sun, 21 May 2023 22:07:20 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id t10-20020a62ea0a000000b0063b5776b073sm3247519pfh.117.2023.05.21.22.07.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:20 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v3 01/10] maple_tree: Rework mtree_alloc_{range,rrange}() Date: Mon, 22 May 2023 13:06:47 +0800 Message-Id: <20230522050656.96215-2-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230522050656.96215-1-zhangpeng.00@bytedance.com> References: <20230522050656.96215-1-zhangpeng.00@bytedance.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" Use mas_empty_area{_rev}() to refactor mtree_alloc_{range,rrange}() Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 57 +++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 4eb220008f72..96d102d60b4e 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -6493,31 +6493,33 @@ int mtree_alloc_range(struct maple_tree *mt, unsign= ed long *startp, { int ret =3D 0; =20 - MA_STATE(mas, mt, min, min); + MA_STATE(mas, mt, 0, 0); if (!mt_is_alloc(mt)) return -EINVAL; =20 if (WARN_ON_ONCE(mt_is_reserved(entry))) return -EINVAL; =20 - if (min > max) - return -EINVAL; - - if (max < size) - return -EINVAL; - - if (!size) - return -EINVAL; - mtree_lock(mt); retry: - mas.offset =3D 0; - mas.index =3D min; - mas.last =3D max - size + 1; - ret =3D mas_alloc(&mas, entry, size, startp); + ret =3D mas_empty_area(&mas, min, max, size); + if (ret) + goto unlock; + + mas_insert(&mas, entry); + /* + * mas_nomem() may release the lock, causing the allocated area + * to be unavailable, so try to allocate a free area again. + */ if (mas_nomem(&mas, gfp)) goto retry; =20 + if (mas_is_err(&mas)) + ret =3D xa_err(mas.node); + else + *startp =3D mas.index; + +unlock: mtree_unlock(mt); return ret; } @@ -6529,28 +6531,33 @@ int mtree_alloc_rrange(struct maple_tree *mt, unsig= ned long *startp, { int ret =3D 0; =20 - MA_STATE(mas, mt, min, max - size + 1); + MA_STATE(mas, mt, 0, 0); if (!mt_is_alloc(mt)) return -EINVAL; =20 if (WARN_ON_ONCE(mt_is_reserved(entry))) return -EINVAL; =20 - if (min > max) - return -EINVAL; - - if (max < size - 1) - return -EINVAL; - - if (!size) - return -EINVAL; - mtree_lock(mt); retry: - ret =3D mas_rev_alloc(&mas, min, max, entry, size, startp); + ret =3D mas_empty_area_rev(&mas, min, max, size); + if (ret) + goto unlock; + + mas_insert(&mas, entry); + /* + * mas_nomem() may release the lock, causing the allocated area + * to be unavailable, so try to allocate a free area again. + */ if (mas_nomem(&mas, gfp)) goto retry; =20 + if (mas_is_err(&mas)) + ret =3D xa_err(mas.node); + else + *startp =3D mas.index; + +unlock: mtree_unlock(mt); return ret; } --=20 2.20.1 From nobody Sun Feb 8 17:46:34 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 8FA53C7EE23 for ; Mon, 22 May 2023 05:07:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231768AbjEVFHz (ORCPT ); Mon, 22 May 2023 01:07:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231734AbjEVFHr (ORCPT ); Mon, 22 May 2023 01:07:47 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A706592 for ; Sun, 21 May 2023 22:07:24 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-64d15660784so2906667b3a.0 for ; Sun, 21 May 2023 22:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732044; x=1687324044; 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=8amRkLtdnjVq9cbmGyv8etEjiXwBdz+ISKHsxqN16tA=; b=GYE7/eh3Hqti3Du8XPZUomicyjqafnfRSVXMJgGIMFX6+SBScSqdwET8DvURyQAI25 A2eaYMWJDwWyiQ/yLWt/12vUSj6bzkTk+pGFfX8gf+yVtmaOuB1FxffF70FUjmpqTzA9 lU0TUqzND5gyGUb0yKeIQJRajq4+VN2W1jz/CsH9wkCLeVYW5gqLkCAnJanNMSasF/uU O8hpWEr2WtH/xMH1UAsDv43QHtp1r+L/SgUI5S5gEN4rskUkm/mEGMOt2LBfYeUiKTBX sc9hVVsA3HUHuvjjFUGzixiTj+Q9J+BBY3yvg5bd5a9gEihrq+709FCyt5O91kotDEH2 G/6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732044; x=1687324044; 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=8amRkLtdnjVq9cbmGyv8etEjiXwBdz+ISKHsxqN16tA=; b=XbwQScZwzJwh82qLgsej/xfEWSsLpGngFOfZT4aX1vtnKdpLInjGZDn89/tPW3qz0W 3YfIyHblBoV+4Xu5YhxGbuLBoI/90tbezdxi5+I1erB+LoQ9yac3dFOPffm1exx70Xbh nF2kL0reFrUe4RYjYYEJrpYxCmTBVRbC4AnY/nZQQlPT5/JYaiFfUHbgfNTW+n8RLCw9 DV0HNkcMomZUPy8XQJ8FD+f8G3JFXyuJ7bwCsuH3y3TVBsjg0/y2cxeQIwgPrhqUB2Z/ gtukROO+il16qoEb/lhhixlxZGJQ29FlwTRgXk671KQgMYKQfE9Rs0cKMTuydeUyS0e1 rzMg== X-Gm-Message-State: AC+VfDxtg1fDDCfJlGzgft5OuyknsgtVc5LLqQTMXyWN2dKrViz+bCMj TtzZOkUSP6aReJ/4D7Ps1zn7W4xWG/SjSdZSiSo= X-Google-Smtp-Source: ACHHUZ7HimVTIQoub3tu0mdIJwmiVfKwyk3rieE8LPbYzYmpwti5Dz/8eFWiSuI3fjzaDlWesoLrBg== X-Received: by 2002:a05:6a00:1882:b0:64d:42cb:42af with SMTP id x2-20020a056a00188200b0064d42cb42afmr9286193pfh.4.1684732044137; Sun, 21 May 2023 22:07:24 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id t10-20020a62ea0a000000b0063b5776b073sm3247519pfh.117.2023.05.21.22.07.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:23 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v3 02/10] maple_tree: Drop mas_{rev_}alloc() and mas_fill_gap() Date: Mon, 22 May 2023 13:06:48 +0800 Message-Id: <20230522050656.96215-3-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230522050656.96215-1-zhangpeng.00@bytedance.com> References: <20230522050656.96215-1-zhangpeng.00@bytedance.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" mas_{rev_}alloc() and mas_fill_gap() are useless, delete them. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 108 ----------------------------------------------- 1 file changed, 108 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 96d102d60b4e..263bd0ccc31b 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5120,46 +5120,6 @@ static inline void mas_awalk(struct ma_state *mas, u= nsigned long size) } } =20 -/* - * mas_fill_gap() - Fill a located gap with @entry. - * @mas: The maple state - * @entry: The value to store - * @slot: The offset into the node to store the @entry - * @size: The size of the entry - * @index: The start location - */ -static inline void mas_fill_gap(struct ma_state *mas, void *entry, - unsigned char slot, unsigned long size, unsigned long *index) -{ - MA_WR_STATE(wr_mas, mas, entry); - unsigned char pslot =3D mte_parent_slot(mas->node); - struct maple_enode *mn =3D mas->node; - unsigned long *pivots; - enum maple_type ptype; - /* - * mas->index is the start address for the search - * which may no longer be needed. - * mas->last is the end address for the search - */ - - *index =3D mas->index; - mas->last =3D mas->index + size - 1; - - /* - * It is possible that using mas->max and mas->min to correctly - * calculate the index and last will cause an issue in the gap - * calculation, so fix the ma_state here - */ - mas_ascend(mas); - ptype =3D mte_node_type(mas->node); - pivots =3D ma_pivots(mas_mn(mas), ptype); - mas->max =3D mas_safe_pivot(mas, pivots, pslot, ptype); - mas->min =3D mas_safe_min(mas, pivots, pslot); - mas->node =3D mn; - mas->offset =3D slot; - mas_wr_store_entry(&wr_mas); -} - /* * mas_sparse_area() - Internal function. Return upper or lower limit when * searching for a gap in an empty tree. @@ -5307,74 +5267,6 @@ int mas_empty_area_rev(struct ma_state *mas, unsigne= d long min, } EXPORT_SYMBOL_GPL(mas_empty_area_rev); =20 -static inline int mas_alloc(struct ma_state *mas, void *entry, - unsigned long size, unsigned long *index) -{ - unsigned long min; - - mas_start(mas); - if (mas_is_none(mas) || mas_is_ptr(mas)) { - mas_root_expand(mas, entry); - if (mas_is_err(mas)) - return xa_err(mas->node); - - if (!mas->index) - return mas_pivot(mas, 0); - return mas_pivot(mas, 1); - } - - /* Must be walking a tree. */ - mas_awalk(mas, size); - if (mas_is_err(mas)) - return xa_err(mas->node); - - if (mas->offset =3D=3D MAPLE_NODE_SLOTS) - goto no_gap; - - /* - * At this point, mas->node points to the right node and we have an - * offset that has a sufficient gap. - */ - min =3D mas->min; - if (mas->offset) - min =3D mas_pivot(mas, mas->offset - 1) + 1; - - if (mas_is_err(mas)) - return xa_err(mas->node); - - if (mas->index < min) - mas->index =3D min; - - mas_fill_gap(mas, entry, mas->offset, size, index); - return 0; - -no_gap: - return -EBUSY; -} - -static inline int mas_rev_alloc(struct ma_state *mas, unsigned long min, - unsigned long max, void *entry, - unsigned long size, unsigned long *index) -{ - int ret =3D 0; - - ret =3D mas_empty_area_rev(mas, min, max, size); - if (ret) - return ret; - - if (mas_is_err(mas)) - return xa_err(mas->node); - - if (mas->offset =3D=3D MAPLE_NODE_SLOTS) - goto no_gap; - - mas_fill_gap(mas, entry, mas->offset, size, index); - return 0; - -no_gap: - return -EBUSY; -} - /* * mte_dead_leaves() - Mark all leaves of a node as dead. * @mas: The maple state --=20 2.20.1 From nobody Sun Feb 8 17:46:34 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 47213C7EE23 for ; Mon, 22 May 2023 05:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231738AbjEVFHe (ORCPT ); Mon, 22 May 2023 01:07:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231727AbjEVFH3 (ORCPT ); Mon, 22 May 2023 01:07:29 -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 E0691F4 for ; Sun, 21 May 2023 22:07:27 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-64d577071a6so1521509b3a.1 for ; Sun, 21 May 2023 22:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732047; x=1687324047; 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=yWC57VvLqW+uV6e3VSW20kWo+uFlFhqhxKDmqi/M+s4=; b=EzLSK3cPy7whK/cuCX7ItKG6l3duMlUzxr2DN24N10lVm+CaqC7sQkl4JBdNua/aAQ zosKFg/rfFI7osQ8eZcIBIfKeDR03YZaXjE5O8+e2qadCDIp41XDnirHuK3FWoX8l3OU YcB4YJkxwNjDyYKJfPZHybJrX1aMBiy3UgCgsQoNlOLNB2szntp7ukZGP8Q+ZzNCsuPy V8JNyEch9NnjoH7EK7OtuSW0wVEcwlYQnqPEa9kzxzg0/vxd+qY1B24BapLesnKT1O6q iZbG3O4pP7gdt6Vx0E2R3HvXJKJDMX0BbBfYhgm7SDcOeyERTF0Kb1Cj892QnkPDOShu QbmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732047; x=1687324047; 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=yWC57VvLqW+uV6e3VSW20kWo+uFlFhqhxKDmqi/M+s4=; b=bNFcxqLOyjeI4enfRTfp5mFrFx2xOz2BDL0ukRFBmkN9svZ58tKM3KE4K4GoL4utIs /hZ2GKmlyWc0tsUMeNPW041CV2AIJ4ZnX6JAueqQjX8pzkqZ5XOpLfcwZSFwNufXNVsE 85kg57qEOs2GMMCkSF7LMKt7i/TqCBT+FLb069yqNLQmrRSK26FKYdZPiHPkZqqJTcEW PW99L4OYAYoTtbJrgI+D1Blbhjjbur1k5Xd3d9vrM4qGD6l5EuVBuUirFogNu2UhVWi3 oQ9ClJQkA3bHKJGpJFIPzX74OdgLCs1tVmwtZfFVsb6MSOrNhovuPYjsX7WPRIW5uXFt 5fjg== X-Gm-Message-State: AC+VfDwT4sRgsnxWZrjFEVRucm9c2Uq0Kl87OgPii8ldLUCCdW6kcx+Y 7mjO9G4pbXdIN6b30LUJxRALvA== X-Google-Smtp-Source: ACHHUZ78HzvmR367cMVPT2DzYVrIahGxjmoDH/aFdaP1ySwjC4sDSZwePIHcLNsfO8g2Nn/oaa1aBw== X-Received: by 2002:a05:6a00:3924:b0:64d:5f1d:3d77 with SMTP id fh36-20020a056a00392400b0064d5f1d3d77mr4573175pfb.34.1684732047342; Sun, 21 May 2023 22:07:27 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id t10-20020a62ea0a000000b0063b5776b073sm3247519pfh.117.2023.05.21.22.07.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:27 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v3 03/10] maple_tree: Fix the arguments to __must_hold() Date: Mon, 22 May 2023 13:06:49 +0800 Message-Id: <20230522050656.96215-4-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230522050656.96215-1-zhangpeng.00@bytedance.com> References: <20230522050656.96215-1-zhangpeng.00@bytedance.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 the arguments to __must_hold() to make sparse work. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 263bd0ccc31b..3fe6a6685384 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1752,7 +1752,7 @@ static inline void mas_adopt_children(struct ma_state= *mas, * leave the node (true) and handle the adoption and free elsewhere. */ static inline void mas_replace(struct ma_state *mas, bool advanced) - __must_hold(mas->tree->lock) + __must_hold(mas->tree->ma_lock) { struct maple_node *mn =3D mas_mn(mas); struct maple_enode *old_enode; @@ -1792,7 +1792,7 @@ static inline void mas_replace(struct ma_state *mas, = bool advanced) * @child: the maple state to store the child. */ static inline bool mas_new_child(struct ma_state *mas, struct ma_state *ch= ild) - __must_hold(mas->tree->lock) + __must_hold(mas->tree->ma_lock) { enum maple_type mt; unsigned char offset; @@ -6204,7 +6204,7 @@ EXPORT_SYMBOL_GPL(mas_erase); * Return: true on allocation, false otherwise. */ bool mas_nomem(struct ma_state *mas, gfp_t gfp) - __must_hold(mas->tree->lock) + __must_hold(mas->tree->ma_lock) { if (likely(mas->node !=3D MA_ERROR(-ENOMEM))) { mas_destroy(mas); --=20 2.20.1 From nobody Sun Feb 8 17:46:34 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 CA185C7EE23 for ; Mon, 22 May 2023 05:08:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229801AbjEVFIE (ORCPT ); Mon, 22 May 2023 01:08:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231783AbjEVFHv (ORCPT ); Mon, 22 May 2023 01:07:51 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF050A1 for ; Sun, 21 May 2023 22:07:30 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-64d2da69fdfso3786458b3a.0 for ; Sun, 21 May 2023 22:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732050; x=1687324050; 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=BT/SFNbyjqRQKVOJvWMUTBqOO8oBgaqMrnpmlnOChNs=; b=EKjJchlGDXRmxJY8egKTtCPHJW2FBKY8xN7qIIKeMpGB4j4yfs4iePqfPdOGDGS203 IQjvd34wUy4iqm1NNQJMsANpzDUtvuiVQo71ID6Ql5b/ZD31hFk8zHJpgjT9hmu5H5CG W8AKwWnNxPTTL+axxU+uEI/qffJlMjhfvrBTBD4nxKkPe9Lqh0j9uCLHAV37edea/+S6 c/7Hxz7fmZF9O9S2PREteryTTvvviwB/5gf/KOkvxJ/j1jRMaiNomC+EdpaWZVIcIXEF ezrPNKmy3LltEsCoP28TpF/5IGnfNZZB7VItCs35pXc12CfQgdA9uAdfhOYdExojYMPD ahkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732050; x=1687324050; 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=BT/SFNbyjqRQKVOJvWMUTBqOO8oBgaqMrnpmlnOChNs=; b=H/rKLtyDMzHw0jhZcjOKlOWWxbZreU4oOKccakFV6jjmrJx86J/EFNmFl7dMnri2YA jDGicxy2R1wmD0ATZT0rX+ChC5xwkg24of1PtWtBI6F7aT351lkfVi0Tc+OQyyMf3w4e TJZ9DUkJhCUKjUUoAF7awpacK1dWbDQtNkUlKxCoXhKwptePZCvM/hVVKErQFLDkPtTC wjNQBk2o8W88WUuCtgVIzJwUY8a6JpCIrKNEADP22e2fiv3NMs2mjcJMwBz8gLHtcbsa +GQ6WAm4t25A4xy69YVqvhO7VeKoG5J+9yGrmVeKqIjGX3J7ddK+fY3oLLTuE2XhiT3B aRRg== X-Gm-Message-State: AC+VfDzUO4n/on0GCu6ZroYNaJW8r3uc/uBepCKlaIUPXP2iaumOpfNt NAEblzfKwF0jX2DVAiWtJcl9RQ== X-Google-Smtp-Source: ACHHUZ48HsI5YZd3LN1vDcUYC1K6qWTTr5aUygORmW+ZGTHv31Rrj+0oY+hVYu/YmeCBOpKh0r58EA== X-Received: by 2002:a05:6a00:2185:b0:64d:46b2:9a58 with SMTP id h5-20020a056a00218500b0064d46b29a58mr7924134pfi.26.1684732050365; Sun, 21 May 2023 22:07:30 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id t10-20020a62ea0a000000b0063b5776b073sm3247519pfh.117.2023.05.21.22.07.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:30 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v3 04/10] maple_tree: Simplify mas_is_span_wr() Date: Mon, 22 May 2023 13:06:50 +0800 Message-Id: <20230522050656.96215-5-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230522050656.96215-1-zhangpeng.00@bytedance.com> References: <20230522050656.96215-1-zhangpeng.00@bytedance.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" Make the code for detecting spanning writes more concise. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 3fe6a6685384..c47af84047a4 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3728,43 +3728,32 @@ static inline void mas_store_root(struct ma_state *= mas, void *entry) */ static bool mas_is_span_wr(struct ma_wr_state *wr_mas) { - unsigned long max; + unsigned long max =3D wr_mas->r_max; unsigned long last =3D wr_mas->mas->last; - unsigned long piv =3D wr_mas->r_max; enum maple_type type =3D wr_mas->type; void *entry =3D wr_mas->entry; =20 - /* Contained in this pivot */ - if (piv > last) + /* Contained in this pivot, fast path */ + if (last < max) return false; =20 - max =3D wr_mas->mas->max; - if (unlikely(ma_is_leaf(type))) { - /* Fits in the node, but may span slots. */ + if (ma_is_leaf(type)) { + max =3D wr_mas->mas->max; if (last < max) return false; + } =20 - /* Writes to the end of the node but not null. */ - if ((last =3D=3D max) && entry) - return false; - + if (last =3D=3D max) { /* - * Writing ULONG_MAX is not a spanning write regardless of the - * value being written as long as the range fits in the node. + * The last entry of leaf node cannot be NULL unless it is the + * rightmost node (writing ULONG_MAX), otherwise it spans slots. + * If this is not leaf node, detect spanning store wr walk. */ - if ((last =3D=3D ULONG_MAX) && (last =3D=3D max)) - return false; - } else if (piv =3D=3D last) { - if (entry) - return false; - - /* Detect spanning store wr walk */ - if (last =3D=3D ULONG_MAX) + if (entry || last =3D=3D ULONG_MAX) return false; } =20 - trace_ma_write(__func__, wr_mas->mas, piv, entry); - + trace_ma_write(__func__, wr_mas->mas, wr_mas->r_max, entry); return true; } =20 --=20 2.20.1 From nobody Sun Feb 8 17:46:34 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 2A2EAC7EE23 for ; Mon, 22 May 2023 05:07:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231750AbjEVFHi (ORCPT ); Mon, 22 May 2023 01:07:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231727AbjEVFHf (ORCPT ); Mon, 22 May 2023 01:07:35 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D29EEE9 for ; Sun, 21 May 2023 22:07:33 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-64d1a0d640cso3003221b3a.1 for ; Sun, 21 May 2023 22:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732053; x=1687324053; 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=eo5rcY2cJVWJgq5aXNebmW2HhW0q7JfmSI/nM1R46gk=; b=ZSCKQFXLVBYNVkVOOzDNCt0Mcj4KMH0eT5hciFj/maxy7uR2Fkn3XI9lMlN5I5K2mq Gkw8OaXA1zC3gwyZmCX2kCRi6LHedI7vC7pGlQ/tq/vEkC3qx84ASPAf41r2VFRD1XBm Qq35xPIr91V1EpeXuEklHJyGwYOOSZuXcKpt7zcnKzZgmUmXG7hRA8dpYUo1ZjYK6p9J f/UBHZMxPM3XmWhjiUvQ3km319KaunvQEQg7Wos7iycBYkWIlOSSwDwri3+W/KsmllFu OfpLB1SibWVW3lTR6xYe6IJvXPIhv0Nt/Z5NcrMSHbdAEZqqBED9UAwJNrLOiZY7L84J F0vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732053; x=1687324053; 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=eo5rcY2cJVWJgq5aXNebmW2HhW0q7JfmSI/nM1R46gk=; b=dvjGWBmOdx7GKN0jq+dj5REHnAtalNx19fA7D26E5/id+Ie0+94eIkAPtl6KJduJCa U8Ez2cQ8tv9vUGno3RDq1VbsINYQ6GA+eQrrp0As3+KhZdYW/c6aRezHCJ7cbqrarqoV QtRkGTG2ElyP+B8OFpo+a4MmhajI6SU9A+N193802Yh4nteYHdAv+SqNrXI5pIl/F+qU lnqHqa27+rAuIt6P5ON0THSnWdHUN6ulWJqjALenIAVRlFFidqabDAu8Xu5vsG5j6Tuo /pCE+TX3pnQGcehkQmjqz39JXwO9SNeL+DMHVFV+n01n9UAZ2c2oQLyjQB3jlDcUVJml jVeg== X-Gm-Message-State: AC+VfDxC7wJ5ofwL1Td/pJKa7kH02/3wWn8+ZN2XXeDw5sQUY/QnsmHW bFYaqHSRvKB2x79KnmSD/DaUMw== X-Google-Smtp-Source: ACHHUZ4MzY2LZNzu/pNjw410E/5PK7X/ZtRiKyw0Xmd7JdlNmnRSaFHeU1cNLXN3WvcR/RrqWRLy2A== X-Received: by 2002:a05:6a00:9a4:b0:64d:2e8a:4ccb with SMTP id u36-20020a056a0009a400b0064d2e8a4ccbmr13674329pfg.14.1684732053316; Sun, 21 May 2023 22:07:33 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id t10-20020a62ea0a000000b0063b5776b073sm3247519pfh.117.2023.05.21.22.07.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:33 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v3 05/10] maple_tree: Make the code symmetrical in mas_wr_extend_null() Date: Mon, 22 May 2023 13:06:51 +0800 Message-Id: <20230522050656.96215-6-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230522050656.96215-1-zhangpeng.00@bytedance.com> References: <20230522050656.96215-1-zhangpeng.00@bytedance.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" Just make the code symmetrical to improve readability. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index c47af84047a4..562507979a4b 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4265,19 +4265,21 @@ static inline void mas_wr_extend_null(struct ma_wr_= state *wr_mas) { struct ma_state *mas =3D wr_mas->mas; =20 - if (mas->last < wr_mas->end_piv && !wr_mas->slots[wr_mas->offset_end]) + if (!wr_mas->slots[wr_mas->offset_end]) { + /* If this one is null, the next and prev are not */ mas->last =3D wr_mas->end_piv; - - /* Check next slot(s) if we are overwriting the end */ - if ((mas->last =3D=3D wr_mas->end_piv) && - (wr_mas->node_end !=3D wr_mas->offset_end) && - !wr_mas->slots[wr_mas->offset_end + 1]) { - wr_mas->offset_end++; - if (wr_mas->offset_end =3D=3D wr_mas->node_end) - mas->last =3D mas->max; - else - mas->last =3D wr_mas->pivots[wr_mas->offset_end]; - wr_mas->end_piv =3D mas->last; + } else { + /* Check next slot(s) if we are overwriting the end */ + if ((mas->last =3D=3D wr_mas->end_piv) && + (wr_mas->node_end !=3D wr_mas->offset_end) && + !wr_mas->slots[wr_mas->offset_end + 1]) { + wr_mas->offset_end++; + if (wr_mas->offset_end =3D=3D wr_mas->node_end) + mas->last =3D mas->max; + else + mas->last =3D wr_mas->pivots[wr_mas->offset_end]; + wr_mas->end_piv =3D mas->last; + } } =20 if (!wr_mas->content) { --=20 2.20.1 From nobody Sun Feb 8 17:46:34 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 683ACC7EE23 for ; Mon, 22 May 2023 05:08:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231859AbjEVFIK (ORCPT ); Mon, 22 May 2023 01:08:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231396AbjEVFIC (ORCPT ); Mon, 22 May 2023 01:08:02 -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 A42E9115 for ; Sun, 21 May 2023 22:07:36 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-64d18d772bdso4779421b3a.3 for ; Sun, 21 May 2023 22:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732056; x=1687324056; 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=gZz+uQjmpOdIMxeiaJgwUz4BoyhUknFLXJa8Z3V7HsI=; b=jgMP8vdBmcOPewxDkJjBZQcf60lixgiNyhCEEOeGGUIpPNqCfsdnSzzeIL2MICM/0R dmJuRkdPDnNnSfKA/dr8EkxfvxBIxP3R4j2iiulIlRGcVDmX8Lct+JSE/lMFq5EGDBJD MKnUiIMoKHSCObK01IPby8K5It8XOEKZYIVlGoZ/mgPiqAD4vHLsmTpUhZE3oIODEi3b gvn0IAyhVkAuotI9HrMW1aiOaWcC/Lor8mMrbNnXu6jNXIDwgJtEi3y5StnbZsqWkZvM nF9BxiVrMtuDUA0UL2yAdW5NJdF+KXKc+Ue8A0yBVtprddy7h6bpFr1gPiOXTD9l0MZY 9rFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732056; x=1687324056; 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=gZz+uQjmpOdIMxeiaJgwUz4BoyhUknFLXJa8Z3V7HsI=; b=iinADj8hceVEp03t2foPuDVS8n5iGfDTSgyovYln1eWWFcppkJUkM/bV95Yya965KP mV+av3+5JebbS8hUUipAxFKgXmzOl94r6Ch/3KLpXiWwmcwr3t8x/By4+nbWWUDgD0tz X6T67AewR/IZIB349wqY4st8KMk0mY+CzudU+H6xE/HeFSabj90MN2K9+UD7WwxoXyre x7hwcMZikGLBN77HFbq+8IzVqB5XopgNPYuFjrmR0cQNjkcJfoJ6pewe6zTxG1JXomSi cm5kDOg8YfgCmQy2gB07RcAm9X7DM3gjdD9/V6fueziaCBCDV1kP4FXtpQ7rupn5lgxO 915A== X-Gm-Message-State: AC+VfDzbOYj4vy2xkchV5jznkziTczNr8CBBWhqvG5+VvQAtTtEOu6X7 Sx6ayzA9AOyE0maMEt59CAvS63NIiV/lXXc1qTE= X-Google-Smtp-Source: ACHHUZ7kqirc8A3D4h9wAwED0RDK5kYc00X56oQezZL6FCZscI345O1qs97um4cy07jU4YV8E3R45A== X-Received: by 2002:a05:6a20:440b:b0:10b:e88f:598f with SMTP id ce11-20020a056a20440b00b0010be88f598fmr916141pzb.51.1684732056314; Sun, 21 May 2023 22:07:36 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id t10-20020a62ea0a000000b0063b5776b073sm3247519pfh.117.2023.05.21.22.07.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:36 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v3 06/10] maple_tree: Add mas_wr_new_end() to calculate new_end accurately Date: Mon, 22 May 2023 13:06:52 +0800 Message-Id: <20230522050656.96215-7-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230522050656.96215-1-zhangpeng.00@bytedance.com> References: <20230522050656.96215-1-zhangpeng.00@bytedance.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" The previous new_end calculation is inaccurate, because it assumes that two new pivots must be added (this is inaccurate), and sometimes it will miss the fast path and enter the slow path. Add mas_wr_new_end() to accurately calculate new_end to make the conditions for entering the fast path more accurate. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 562507979a4b..0550a07355d7 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4297,6 +4297,21 @@ static inline void mas_wr_extend_null(struct ma_wr_s= tate *wr_mas) } } =20 +static inline unsigned char mas_wr_new_end(struct ma_wr_state *wr_mas) +{ + struct ma_state *mas =3D wr_mas->mas; + unsigned char new_end =3D wr_mas->node_end + 2; + + new_end -=3D wr_mas->offset_end - mas->offset; + if (wr_mas->r_min =3D=3D mas->index) + new_end--; + + if (wr_mas->end_piv =3D=3D mas->last) + new_end--; + + return new_end; +} + static inline bool mas_wr_append(struct ma_wr_state *wr_mas) { unsigned char end =3D wr_mas->node_end; @@ -4352,9 +4367,8 @@ static void mas_wr_bnode(struct ma_wr_state *wr_mas) =20 static inline void mas_wr_modify(struct ma_wr_state *wr_mas) { - unsigned char node_slots; - unsigned char node_size; struct ma_state *mas =3D wr_mas->mas; + unsigned char new_end; =20 /* Direct replacement */ if (wr_mas->r_min =3D=3D mas->index && wr_mas->r_max =3D=3D mas->last) { @@ -4364,17 +4378,15 @@ static inline void mas_wr_modify(struct ma_wr_state= *wr_mas) return; } =20 - /* Attempt to append */ - node_slots =3D mt_slots[wr_mas->type]; - node_size =3D wr_mas->node_end - wr_mas->offset_end + mas->offset + 2; - if (mas->max =3D=3D ULONG_MAX) - node_size++; - - /* slot and node store will not fit, go to the slow path */ - if (unlikely(node_size >=3D node_slots)) + /* + * new_end exceeds the size of the maple node and cannot enter the fast + * path. + */ + new_end =3D mas_wr_new_end(wr_mas); + if (new_end >=3D mt_slots[wr_mas->type]) goto slow_path; =20 - if (wr_mas->entry && (wr_mas->node_end < node_slots - 1) && + if (wr_mas->entry && (wr_mas->node_end < mt_slots[wr_mas->type] - 1) && (mas->offset =3D=3D wr_mas->node_end) && mas_wr_append(wr_mas)) { if (!wr_mas->content || !wr_mas->entry) mas_update_gap(mas); --=20 2.20.1 From nobody Sun Feb 8 17:46:34 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 EC34FC77B75 for ; Mon, 22 May 2023 05:08:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231845AbjEVFIT (ORCPT ); Mon, 22 May 2023 01:08:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231790AbjEVFID (ORCPT ); Mon, 22 May 2023 01:08:03 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDCC5106 for ; Sun, 21 May 2023 22:07:39 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-64d5f65a2f7so626681b3a.1 for ; Sun, 21 May 2023 22:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732059; x=1687324059; 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=BDMhWhfLT89+67MaNw9E+3uh4JNyHlNzHsoiSP1QJPc=; b=YlZq8QeeFnwwN2PMnEu5ygiKTeL4TXc//yTBc0oVeHrSXzMJ8uRzfTDuP/PHlcM7UW hB9faQCix3KctJUaLZtd2UmZWfZ8Mfvt+myVSFtECmxjw+131ONog441mxQnYKz6dX/G FSnXiGW4od/KD+uyoierDNkcRBeklQL4FdrVA4CEWtOQ4uiJsFFsNHRgKdBvfALKLTVg DiFw3TJH9fb+KQulmNmJ1EB91in05l8bU2ap+Q70ZEOc1OoIOwCQuPhzBfcNlI7ADW01 xedz/T1eaNokKIMlAOtxmDXSzEUaUcieUHu/oXtk7OoUM6aiztzo2QZUarBT18g6KS/c Kp5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732059; x=1687324059; 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=BDMhWhfLT89+67MaNw9E+3uh4JNyHlNzHsoiSP1QJPc=; b=OgCE1yb/wuEeJg2NbMKGX4WKxvsaGKQTNz3fQwRGcoFJF8LOj/lrBLl2Y5gmAMnklf UIAGXUojAE00ru+10iH3fwODX3xk2R67ZwjzjA2fwBs3ktBgJ6+yvBZ32tkVLA3MOiuL IVp/RvrVrtd2Ok+1Ec4w6HQSHbT950fFB1l+Csmwlt37xCQAAPkMJOenUxa9VBcwQY1o N82lIhiFvyLO3K7Qc+nQpjtk8A6oNVPZKAl1NOD8VErqivPj3e8OkIdiX0JUTgkgMYHC og490p+Ovqp82VpeJqhxD974yB9PDjjeb2inzsCLt9tFTYLoPROkbGTd5nrbr/ozBN0j KFPA== X-Gm-Message-State: AC+VfDxVLyYF1AgIqZZZSmO94Y1uEggBnnDZQC9OFowS1vL8w6bJS8yX Pq444I2XzRxyqICvFr6kpk7SL62oufNGqcnjwkk= X-Google-Smtp-Source: ACHHUZ4G3ndXt0xInsw23oUAUWy0+eARJcOZ0g5BmWYjBmghjVZs6D0v9IRLXKJFPEcYPqYrYeIEyA== X-Received: by 2002:a05:6a00:845:b0:64a:f730:154c with SMTP id q5-20020a056a00084500b0064af730154cmr13394825pfk.13.1684732059192; Sun, 21 May 2023 22:07:39 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id t10-20020a62ea0a000000b0063b5776b073sm3247519pfh.117.2023.05.21.22.07.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:39 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v3 07/10] maple_tree: Add comments and some minor cleanups to mas_wr_append() Date: Mon, 22 May 2023 13:06:53 +0800 Message-Id: <20230522050656.96215-8-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230522050656.96215-1-zhangpeng.00@bytedance.com> References: <20230522050656.96215-1-zhangpeng.00@bytedance.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" Add comment for mas_wr_append(), move mas_update_gap() into mas_wr_append(), and other cleanups to make mas_wr_modify() cleaner. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 0550a07355d7..afbfdcdde5db 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4312,6 +4312,12 @@ static inline unsigned char mas_wr_new_end(struct ma= _wr_state *wr_mas) return new_end; } =20 +/* + * mas_wr_append: Attempt to append + * @wr_mas: the maple write state + * + * Return: True if appended, false otherwise + */ static inline bool mas_wr_append(struct ma_wr_state *wr_mas) { unsigned char end =3D wr_mas->node_end; @@ -4319,34 +4325,30 @@ static inline bool mas_wr_append(struct ma_wr_state= *wr_mas) struct ma_state *mas =3D wr_mas->mas; unsigned char node_pivots =3D mt_pivots[wr_mas->type]; =20 - if ((mas->index !=3D wr_mas->r_min) && (mas->last =3D=3D wr_mas->r_max)) { - if (new_end < node_pivots) - wr_mas->pivots[new_end] =3D wr_mas->pivots[end]; + if (mas->offset !=3D wr_mas->node_end) + return false; =20 - if (new_end < node_pivots) - ma_set_meta(wr_mas->node, maple_leaf_64, 0, new_end); + if (new_end < node_pivots) { + wr_mas->pivots[new_end] =3D wr_mas->pivots[end]; + ma_set_meta(wr_mas->node, maple_leaf_64, 0, new_end); + } =20 + if (mas->last =3D=3D wr_mas->r_max) { + /* Append to end of range */ rcu_assign_pointer(wr_mas->slots[new_end], wr_mas->entry); - mas->offset =3D new_end; wr_mas->pivots[end] =3D mas->index - 1; - - return true; - } - - if ((mas->index =3D=3D wr_mas->r_min) && (mas->last < wr_mas->r_max)) { - if (new_end < node_pivots) - wr_mas->pivots[new_end] =3D wr_mas->pivots[end]; - + mas->offset =3D new_end; + } else { + /* Append to start of range */ rcu_assign_pointer(wr_mas->slots[new_end], wr_mas->content); - if (new_end < node_pivots) - ma_set_meta(wr_mas->node, maple_leaf_64, 0, new_end); - wr_mas->pivots[end] =3D mas->last; rcu_assign_pointer(wr_mas->slots[end], wr_mas->entry); - return true; } =20 - return false; + if (!wr_mas->content || !wr_mas->entry) + mas_update_gap(mas); + + return true; } =20 /* @@ -4386,12 +4388,9 @@ static inline void mas_wr_modify(struct ma_wr_state = *wr_mas) if (new_end >=3D mt_slots[wr_mas->type]) goto slow_path; =20 - if (wr_mas->entry && (wr_mas->node_end < mt_slots[wr_mas->type] - 1) && - (mas->offset =3D=3D wr_mas->node_end) && mas_wr_append(wr_mas)) { - if (!wr_mas->content || !wr_mas->entry) - mas_update_gap(mas); + /* Attempt to append */ + if (new_end =3D=3D wr_mas->node_end + 1 && mas_wr_append(wr_mas)) return; - } =20 if ((wr_mas->offset_end - mas->offset <=3D 1) && mas_wr_slot_store(wr_mas= )) return; --=20 2.20.1 From nobody Sun Feb 8 17:46:34 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 201A7C7EE23 for ; Mon, 22 May 2023 05:07:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231792AbjEVFHw (ORCPT ); Mon, 22 May 2023 01:07:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231758AbjEVFHq (ORCPT ); Mon, 22 May 2023 01:07:46 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95A9C139 for ; Sun, 21 May 2023 22:07:42 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-64d2981e3abso2786899b3a.1 for ; Sun, 21 May 2023 22:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732062; x=1687324062; 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=qKVnArPifyAdGV9PIImrukiWg2xfu85fuVT0WT/x1lU=; b=fw0PRf8Q3oQzgqHErNvDCU259xWd4Me2ceXFQD8pISEEcIEQZmk7bW7OJ3mBQ0eywD v7wNxQOQTVF4JZf9ON/6V5aCR3dkMK/NNESMj6wazF1zAw2gwqe+5A9004QgW40Jn8wf NRquXTchX9dImyrXbMIRvklOEHCfUofQg2xsBQ54kLTzcXz6ITsMt/ENw3oUKSUkw01t ZugU1Bcs0+eIsKfAO0I/jngb59O1PU0WvWi6+TwcGR4tuPzFQajmv63m1xEB1W3F+6HZ hJT0pSolSpSQKQ/rqzJP5/QiQVzYL5TvoE5uUy4y/Z8Tftr+0PeYqUwLgjtERfdeYo2D hh2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732062; x=1687324062; 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=qKVnArPifyAdGV9PIImrukiWg2xfu85fuVT0WT/x1lU=; b=YkHAQKkrIhbRchqIDv+mhrGgjazsDKT/H+VmppM25/dszObTIJWbdKaW3917ZqxFS0 OhfEEV6SHBABVKYuQwNRNPYn9PISv1kXIY3cZmMdaB4330hh2DY6nuKbeVq+mXTpyUz0 JVXNwoSEkXNlu4hAD9ekzNQV4nSQlvqXz6mQMwV85xD2Q8yrMKPoLUZN8LGWmqKjt+10 HMwh50KBALyQY3ZTHa4ptJWJfVXyJunJwVgvtjN4pFi6qW5JaiGq8jQLZqy1+yIC/kEH GkBfcRI2YnakyUExKxgAR0DOMtWbUjXc7H2VqNIdmqQDv/7kg+GSkzDMJWzKCrILU4O2 R5WA== X-Gm-Message-State: AC+VfDxLm7CHQ654RDO9xPhT/zjCGRUBK8J2g5sAZqq8ukxlhxtnhgDI UUzwdpx/cO61Pqkvg0/wus7UkQ== X-Google-Smtp-Source: ACHHUZ4ZdOhjPoifK2FNOzw1Dpvr4gjGQyxiMVErjYNnHLBNabOF7Yl4YngE2n94wMJZLny9Vh53Og== X-Received: by 2002:a05:6a20:3956:b0:107:17f6:940b with SMTP id r22-20020a056a20395600b0010717f6940bmr11393229pzg.41.1684732061987; Sun, 21 May 2023 22:07:41 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id t10-20020a62ea0a000000b0063b5776b073sm3247519pfh.117.2023.05.21.22.07.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:41 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v3 08/10] maple_tree: Rework mas_wr_slot_store() to be cleaner and more efficient. Date: Mon, 22 May 2023 13:06:54 +0800 Message-Id: <20230522050656.96215-9-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230522050656.96215-1-zhangpeng.00@bytedance.com> References: <20230522050656.96215-1-zhangpeng.00@bytedance.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" The code of mas_wr_slot_store() is messy, make it clearer and concise, and add comments. In addition, get whether the two gaps are empty to avoid calling mas_update_gap() all the time. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 53 +++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index afbfdcdde5db..1fc872f7683c 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4203,49 +4203,34 @@ static inline bool mas_wr_node_store(struct ma_wr_s= tate *wr_mas) static inline bool mas_wr_slot_store(struct ma_wr_state *wr_mas) { struct ma_state *mas =3D wr_mas->mas; - unsigned long lmax; /* Logical max. */ unsigned char offset =3D mas->offset; + bool gap =3D false; =20 - if ((wr_mas->r_max > mas->last) && ((wr_mas->r_min !=3D mas->index) || - (offset !=3D wr_mas->node_end))) + if (wr_mas->offset_end - offset !=3D 1) return false; =20 - if (offset =3D=3D wr_mas->node_end - 1) - lmax =3D mas->max; - else - lmax =3D wr_mas->pivots[offset + 1]; - - /* going to overwrite too many slots. */ - if (lmax < mas->last) - return false; - - if (wr_mas->r_min =3D=3D mas->index) { - /* overwriting two or more ranges with one. */ - if (lmax =3D=3D mas->last) - return false; + gap |=3D !mt_slot_locked(mas->tree, wr_mas->slots, offset); + gap |=3D !mt_slot_locked(mas->tree, wr_mas->slots, offset + 1); =20 - /* Overwriting all of offset and a portion of offset + 1. */ + if (mas->index =3D=3D wr_mas->r_min) { + /* Overwriting the range and over a part of the next range. */ rcu_assign_pointer(wr_mas->slots[offset], wr_mas->entry); wr_mas->pivots[offset] =3D mas->last; - goto done; + } else { + /* Overwriting a part of the range and over the next range */ + rcu_assign_pointer(wr_mas->slots[offset + 1], wr_mas->entry); + wr_mas->pivots[offset] =3D mas->index - 1; + mas->offset++; /* Keep mas accurate. */ } =20 - /* Doesn't end on the next range end. */ - if (lmax !=3D mas->last) - return false; - - /* Overwriting a portion of offset and all of offset + 1 */ - if ((offset + 1 < mt_pivots[wr_mas->type]) && - (wr_mas->entry || wr_mas->pivots[offset + 1])) - wr_mas->pivots[offset + 1] =3D mas->last; - - rcu_assign_pointer(wr_mas->slots[offset + 1], wr_mas->entry); - wr_mas->pivots[offset] =3D mas->index - 1; - mas->offset++; /* Keep mas accurate. */ - -done: trace_ma_write(__func__, mas, 0, wr_mas->entry); - mas_update_gap(mas); + /* + * Only update gap when the new entry is empty or there is an empty + * entry in the original two ranges. + */ + if (!wr_mas->entry || gap) + mas_update_gap(mas); + return true; } =20 @@ -4392,7 +4377,7 @@ static inline void mas_wr_modify(struct ma_wr_state *= wr_mas) if (new_end =3D=3D wr_mas->node_end + 1 && mas_wr_append(wr_mas)) return; =20 - if ((wr_mas->offset_end - mas->offset <=3D 1) && mas_wr_slot_store(wr_mas= )) + if (new_end =3D=3D wr_mas->node_end && mas_wr_slot_store(wr_mas)) return; else if (mas_wr_node_store(wr_mas)) return; --=20 2.20.1 From nobody Sun Feb 8 17:46:34 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 EAE5CC77B75 for ; Mon, 22 May 2023 05:08:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231828AbjEVFIm (ORCPT ); Mon, 22 May 2023 01:08:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229764AbjEVFIN (ORCPT ); Mon, 22 May 2023 01:08:13 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E9D2E9 for ; Sun, 21 May 2023 22:07:45 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-64d1a0d640cso3003293b3a.1 for ; Sun, 21 May 2023 22:07:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732065; x=1687324065; 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=zXcykhEsvUWhqgulB/awfwAbXbqU+zgrczKRgN6cHyY=; b=BKOlFfw73MQsx7LKzihVb1eW2ku1Xa0uxS543oAZwXAeguF1RrGxaXVIbOQY17SQAQ kV1Uhnt0EvCzfgZCQJRhJA1pjbp8GCJmlUxZ8ozuWFSLCFY8c/MplHp2+j7uwMSrHVBa zU4r2Q45Vv1cofp/3n9tPjiEhbtoj/DxS6hNtjdbzivBv8C2Czl+xRXGAS+dhMiWKz0r /CIdRyWY17x9u18PW8dv9F5DlJFuCEK3kFjIekHWt3qgvtdh/p5TxWQX/VTgOScLeSHE 7x32o2kDITVj9QcRo0K2UK8/Mgua27wg8lQIjh01Up1//2t3VGz9t58HMSjr+JHyVx+X DncQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732065; x=1687324065; 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=zXcykhEsvUWhqgulB/awfwAbXbqU+zgrczKRgN6cHyY=; b=E2XH3r7VHRBqM2JuvuMNLaRfebwjXI9N3t/4AXX4Oph6sswGLrJkxDQe0ILtZEKU1C xunPLDl0Ovx+5NMdnhJ1JmmdgAc3cMCBwC1ONpooxiBVH69TayIXPPiaVsAOvX55CDoM zJyT+RAjcE2bVwZpSDInhcnezQA1XG/g5CmjcUFbSMPcfZzS3NtxTxDtM3MAeRErgqra TUrpnPvlH0qirJthbaJmRuDMdH6314ZbGynvRhJ+exEKJo0tF423m9Ntj4uEuoArWIHE RZKaQpTI7wYCLPIhZ1FPguOBIR2WANcm4CTTJNixEvbbVceVvPDJMftvrsdiLkvqKVSp /cnw== X-Gm-Message-State: AC+VfDwyfYjumUnoaCCzxjZOhAuvO5fb6xlLw9Zbh/TUfkxqq3tJbQfH 1bqjpgV2vle6Rb8Bc3FwUSgpmA== X-Google-Smtp-Source: ACHHUZ4GwWTWE5gkEqNoMIf2XcDiWGmxfbFx8zj08GpTeiP2eOnG/1Io/VG9zQ4q7LRUwyQxcVeeSA== X-Received: by 2002:a05:6a00:1803:b0:643:6aed:3a9 with SMTP id y3-20020a056a00180300b006436aed03a9mr12429588pfa.0.1684732064880; Sun, 21 May 2023 22:07:44 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id t10-20020a62ea0a000000b0063b5776b073sm3247519pfh.117.2023.05.21.22.07.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:44 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v3 09/10] maple_tree: Simplify and clean up mas_wr_node_store() Date: Mon, 22 May 2023 13:06:55 +0800 Message-Id: <20230522050656.96215-10-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230522050656.96215-1-zhangpeng.00@bytedance.com> References: <20230522050656.96215-1-zhangpeng.00@bytedance.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" Simplify and clean up mas_wr_node_store(), remove unnecessary code. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 87 +++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 61 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 1fc872f7683c..aa1472c45757 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4075,52 +4075,27 @@ static inline int mas_wr_spanning_store(struct ma_w= r_state *wr_mas) * * Return: True if stored, false otherwise */ -static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas) +static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas, + unsigned char new_end) { struct ma_state *mas =3D wr_mas->mas; void __rcu **dst_slots; unsigned long *dst_pivots; - unsigned char dst_offset; - unsigned char new_end =3D wr_mas->node_end; - unsigned char offset; - unsigned char node_slots =3D mt_slots[wr_mas->type]; + unsigned char dst_offset, offset_end =3D wr_mas->offset_end; struct maple_node reuse, *newnode; - unsigned char copy_size, max_piv =3D mt_pivots[wr_mas->type]; + unsigned char copy_size, node_pivots =3D mt_pivots[wr_mas->type]; bool in_rcu =3D mt_in_rcu(mas->tree); =20 - offset =3D mas->offset; - if (mas->last =3D=3D wr_mas->r_max) { - /* runs right to the end of the node */ - if (mas->last =3D=3D mas->max) - new_end =3D offset; - /* don't copy this offset */ - wr_mas->offset_end++; - } else if (mas->last < wr_mas->r_max) { - /* new range ends in this range */ - if (unlikely(wr_mas->r_max =3D=3D ULONG_MAX)) - mas_bulk_rebalance(mas, wr_mas->node_end, wr_mas->type); - - new_end++; - } else { - if (wr_mas->end_piv =3D=3D mas->last) - wr_mas->offset_end++; - - new_end -=3D wr_mas->offset_end - offset - 1; - } - - /* new range starts within a range */ - if (wr_mas->r_min < mas->index) - new_end++; - - /* Not enough room */ - if (new_end >=3D node_slots) - return false; - - /* Not enough data. */ + /* Check if there is enough data. The room is enough. */ if (!mte_is_root(mas->node) && (new_end <=3D mt_min_slots[wr_mas->type]) = && !(mas->mas_flags & MA_STATE_BULK)) return false; =20 + if (mas->last =3D=3D wr_mas->end_piv) + offset_end++; /* don't copy this offset */ + else if (unlikely(wr_mas->r_max =3D=3D ULONG_MAX)) + mas_bulk_rebalance(mas, wr_mas->node_end, wr_mas->type); + /* set up node. */ if (in_rcu) { mas_node_count(mas, 1); @@ -4137,47 +4112,36 @@ static inline bool mas_wr_node_store(struct ma_wr_s= tate *wr_mas) dst_pivots =3D ma_pivots(newnode, wr_mas->type); dst_slots =3D ma_slots(newnode, wr_mas->type); /* Copy from start to insert point */ - memcpy(dst_pivots, wr_mas->pivots, sizeof(unsigned long) * (offset + 1)); - memcpy(dst_slots, wr_mas->slots, sizeof(void *) * (offset + 1)); - dst_offset =3D offset; + memcpy(dst_pivots, wr_mas->pivots, sizeof(unsigned long) * mas->offset); + memcpy(dst_slots, wr_mas->slots, sizeof(void *) * mas->offset); =20 /* Handle insert of new range starting after old range */ if (wr_mas->r_min < mas->index) { - mas->offset++; - rcu_assign_pointer(dst_slots[dst_offset], wr_mas->content); - dst_pivots[dst_offset++] =3D mas->index - 1; + rcu_assign_pointer(dst_slots[mas->offset], wr_mas->content); + dst_pivots[mas->offset++] =3D mas->index - 1; } =20 /* Store the new entry and range end. */ - if (dst_offset < max_piv) - dst_pivots[dst_offset] =3D mas->last; - mas->offset =3D dst_offset; - rcu_assign_pointer(dst_slots[dst_offset], wr_mas->entry); + if (mas->offset < node_pivots) + dst_pivots[mas->offset] =3D mas->last; + rcu_assign_pointer(dst_slots[mas->offset], wr_mas->entry); =20 /* * this range wrote to the end of the node or it overwrote the rest of * the data */ - if (wr_mas->offset_end > wr_mas->node_end || mas->last >=3D mas->max) { - new_end =3D dst_offset; + if (offset_end > wr_mas->node_end) goto done; - } =20 - dst_offset++; + dst_offset =3D mas->offset + 1; /* Copy to the end of node if necessary. */ - copy_size =3D wr_mas->node_end - wr_mas->offset_end + 1; - memcpy(dst_slots + dst_offset, wr_mas->slots + wr_mas->offset_end, + copy_size =3D wr_mas->node_end - offset_end + 1; + memcpy(dst_slots + dst_offset, wr_mas->slots + offset_end, sizeof(void *) * copy_size); - if (dst_offset < max_piv) { - if (copy_size > max_piv - dst_offset) - copy_size =3D max_piv - dst_offset; - - memcpy(dst_pivots + dst_offset, - wr_mas->pivots + wr_mas->offset_end, - sizeof(unsigned long) * copy_size); - } + memcpy(dst_pivots + dst_offset, wr_mas->pivots + offset_end, + sizeof(unsigned long) * (copy_size - 1)); =20 - if ((wr_mas->node_end =3D=3D node_slots - 1) && (new_end < node_slots - 1= )) + if (new_end < node_pivots) dst_pivots[new_end] =3D mas->max; =20 done: @@ -4379,7 +4343,8 @@ static inline void mas_wr_modify(struct ma_wr_state *= wr_mas) =20 if (new_end =3D=3D wr_mas->node_end && mas_wr_slot_store(wr_mas)) return; - else if (mas_wr_node_store(wr_mas)) + + if (mas_wr_node_store(wr_mas, new_end)) return; =20 if (mas_is_err(mas)) --=20 2.20.1 From nobody Sun Feb 8 17:46:34 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 24B5EC7EE23 for ; Mon, 22 May 2023 05:08:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231901AbjEVFIq (ORCPT ); Mon, 22 May 2023 01:08:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231790AbjEVFIT (ORCPT ); Mon, 22 May 2023 01:08:19 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E551129 for ; Sun, 21 May 2023 22:07:48 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-64d2e8a842cso2299179b3a.3 for ; Sun, 21 May 2023 22:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732068; x=1687324068; 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=4yOLk/7tHD7/ODqSb7roZU5d9FbnbbLKf36QePLl4Fs=; b=AzHzNd0mvm+jLZUdv/e7B4MQC3FEjUAXCF3VVAaoRyZSNx71MXEV51MxVvMQPGTRnL beZ/HAieLZVm6erPnazYr8lxJ/KMnHLGwVLS9rpwqD4TZwtSOLNIx2ilFdPluS8Fo5wH aulAdvKjGbORvC5pYRoimAsxCsbmmub7MiwaCjUVNgDxrPoNguk1B2QxFs2f/4u0BDxC ghdjhr9rKY4kS7OZrxzDsus7afl7TirEZO6XG2XE9PaDtCnJIS3J6uHgXmphvXYrsd64 V0VVSCQSKamOqt+7V9vZLiSj9VDqYA4y4mi6VfOkA+OqJDHu8LZDsc5yOBZRw9CnQDtp /E8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732068; x=1687324068; 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=4yOLk/7tHD7/ODqSb7roZU5d9FbnbbLKf36QePLl4Fs=; b=WnSaeAIFmoE/m2FY+BtcXD2W1LoABJuUPgL9tyw/mh0hKJ9U5noLlmHlDXVuTrFeHg 39yhXHAP6bJP7OmGyTQttoZB0fGcEDfHiBEIyzAac7JZUEuFNf6aIcSR7x5qslRW9uQp v06y/9KIVLOw4uKI3htAfVHgT7tu2TRXjYtGEwC1e3toV+yjn0nE/sGMdwRXxPSmhGmn b2JZniDDbhzg51iyEUl5HUTaLyfbqQmch8pP6OjTSfVrmjNLtJ5atlAgQKbkrUtuzZpC lJm2pKUNbC/pMggJKNL/rK23fZ0jhXE7+URypIJDLOiS98WPUZ12fQN0fyIAeWhGawXa 7OrA== X-Gm-Message-State: AC+VfDw3YGC4kcpSHg7qzsidFWJXxMaSr4j1ZztI12qNb1sdhUI5QzvI 0jNXg/TgSFciFbxm2KSNeH043A== X-Google-Smtp-Source: ACHHUZ4VTPblQwvMklYDFzU1McTkdLu8cOzHgLuHXQ1smW7pdssNegVfLfyh8uucTfzZ0+l2hFIQ4w== X-Received: by 2002:a05:6a00:c8d:b0:644:c365:50d5 with SMTP id a13-20020a056a000c8d00b00644c36550d5mr11924837pfv.6.1684732067735; Sun, 21 May 2023 22:07:47 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id t10-20020a62ea0a000000b0063b5776b073sm3247519pfh.117.2023.05.21.22.07.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:47 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v3 10/10] maple_tree: Relocate the declaration of mas_empty_area_rev(). Date: Mon, 22 May 2023 13:06:56 +0800 Message-Id: <20230522050656.96215-11-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230522050656.96215-1-zhangpeng.00@bytedance.com> References: <20230522050656.96215-1-zhangpeng.00@bytedance.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" Relocate the declaration of mas_empty_area_rev() so that mas_empty_area() and mas_empty_area_rev() are together. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- include/linux/maple_tree.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index 85559a34a098..c4681cb8414f 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -474,6 +474,12 @@ void *mas_next_range(struct ma_state *mas, unsigned lo= ng max); =20 int mas_empty_area(struct ma_state *mas, unsigned long min, unsigned long = max, unsigned long size); +/* + * This finds an empty area from the highest address to the lowest. + * AKA "Topdown" version, + */ +int mas_empty_area_rev(struct ma_state *mas, unsigned long min, + unsigned long max, unsigned long size); =20 static inline void mas_init(struct ma_state *mas, struct maple_tree *tree, unsigned long addr) @@ -497,12 +503,6 @@ static inline bool mas_is_paused(const struct ma_state= *mas) return mas->node =3D=3D MAS_PAUSE; } =20 -/* - * This finds an empty area from the highest address to the lowest. - * AKA "Topdown" version, - */ -int mas_empty_area_rev(struct ma_state *mas, unsigned long min, - unsigned long max, unsigned long size); /** * mas_reset() - Reset a Maple Tree operation state. * @mas: Maple Tree operation state. --=20 2.20.1