From nobody Tue Sep 9 18:11:28 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 642F7C41513 for ; Wed, 26 Jul 2023 08:24:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233172AbjGZIYP (ORCPT ); Wed, 26 Jul 2023 04:24:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233197AbjGZIXC (ORCPT ); Wed, 26 Jul 2023 04:23:02 -0400 Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCF8E6EB5 for ; Wed, 26 Jul 2023 01:10:30 -0700 (PDT) Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-3a43cbb432aso4468802b6e.3 for ; Wed, 26 Jul 2023 01:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690359029; x=1690963829; 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=v8uNs+P31bvWCjQDHXfNwA0J1eeKVpGhA2UwqZlpI48=; b=CrBUyHbKlHgI9bJ+PDdaaetEcpHr3E/W2ZfSeQBeKeVprTl52WIKA+JT3TW5+Ml/Vt ddWID0Zgv01crS6rbjypqKita+JfgnUG4tKAb+l2OFoy32E4s/A8cPZuepcKPkIfxCqK 2Ve0brfKitPbiuM5fkRL7lSTRVdwqr/fwvAm0+bDvcAYv7+oX/fJ7rugbAx694yPbS8C y79T2h1uzsi7M/59p+ojtXI3BlaoZ2svHDneAsizA7/Q0qzjd2Tay0M7mOc+/5KMlRpf Wyv+4A63YfHdc49RtDmJ13nR93qde273z4c2bCDXtCk6qfm/zbcgPqnD0ZeDszcCz3JY T0dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690359029; x=1690963829; 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=v8uNs+P31bvWCjQDHXfNwA0J1eeKVpGhA2UwqZlpI48=; b=GhND8y0QX/1y/JqADFWzvfY59Y4c2/pbLuJeOdjBZ19Z6VUpKmHoM18guKIg6eZ5ZB k1jMrt4Kr6xv2ZOzrHWbA91NinLaTUme/Ba5v3nwosyMbm0yxpXC3IZWwSlBbgoA3zU0 rXhAcPsGXtLxeRV7zl6aHIhVtbYJVb0n+T+7gzVrcNt/QpJEvfVSwrjm/cX5H5KV9dMA kKp8RjgnFLdqkZm3gAcopxinuEcaaPOm3WH7Ppx5++zGHpdmAvyIev8g1pGnLtoEoG62 7Eqnzb6eIhUS8fQ4mPF/LpJu9mGSt/QQB86V89dwOuryyukntZ6y49vi91hPqb8aU+MF d2MA== X-Gm-Message-State: ABy/qLblFcU3Y5VREasqwwAc9PLV+vMDub3cXjprnj+Hy1oBUr6mBoM9 BaXPqqy0IHRNW/TWHBXJsxZsrQ== X-Google-Smtp-Source: APBJJlGhAux4gsHuRlskWB+2hAoyUd2LMLZZMtlCIKrNxAMe0PgykyqeVppW19z8AHH0EfD4FyyaJQ== X-Received: by 2002:a05:6808:1599:b0:3a1:e3ee:742a with SMTP id t25-20020a056808159900b003a1e3ee742amr1872990oiw.8.1690359029699; Wed, 26 Jul 2023 01:10:29 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id gc17-20020a17090b311100b002680b2d2ab6sm756540pjb.19.2023.07.26.01.10.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 26 Jul 2023 01:10:29 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com, corbet@lwn.net, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org, surenb@google.com, michael.christie@oracle.com, peterz@infradead.org, mathieu.desnoyers@efficios.com, npiggin@gmail.com, avagin@gmail.com Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Peng Zhang Subject: [PATCH 07/11] maple_tree: Update the documentation of maple tree Date: Wed, 26 Jul 2023 16:09:12 +0800 Message-Id: <20230726080916.17454-8-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230726080916.17454-1-zhangpeng.00@bytedance.com> References: <20230726080916.17454-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" Introduces the newly introduced mt_dup() and mas_replace_entry(). Signed-off-by: Peng Zhang --- Documentation/core-api/maple_tree.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/core-api/maple_tree.rst b/Documentation/core-api= /maple_tree.rst index 45defcf15da7..a4fa991277c7 100644 --- a/Documentation/core-api/maple_tree.rst +++ b/Documentation/core-api/maple_tree.rst @@ -71,6 +71,11 @@ return -EEXIST if the range is not empty. =20 You can search for an entry from an index upwards by using mt_find(). =20 +If you want to duplicate a tree, you can use mt_dup(). It will build a new= tree +that is exactly the same as the source tree, and it uses an efficient +implementation, so it is much faster than traversing the source tree and +inserting into the new tree one by one. + You can walk each entry within a range by calling mt_for_each(). You must provide a temporary variable to store a cursor. If you want to walk each element of the tree then ``0`` and ``ULONG_MAX`` may be used as the range.= If @@ -115,6 +120,7 @@ Takes ma_lock internally: * mtree_destroy() * mt_set_in_rcu() * mt_clear_in_rcu() + * mt_dup() =20 If you want to take advantage of the internal lock to protect the data structures that you are storing in the Maple Tree, you can call mtree_lock= () @@ -155,6 +161,10 @@ You can set entries using mas_store(). mas_store() wi= ll overwrite any entry with the new entry and return the first existing entry that is overwritten. The range is passed in as members of the maple state: index and last. =20 +If you have located an entry using something like mas_find(), and want to +replace this entry, you can use mas_replace_entry(), which is more efficie= nt +than mas_store*(). + You can use mas_erase() to erase an entire range by setting index and last of the maple state to the desired range to erase. This will erase the first range that is found in that range, set the maple state index --=20 2.20.1