From patchwork Wed Jul 26 08:09:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 126179 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp257013vqo; Wed, 26 Jul 2023 01:34:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlHTT5BLf/maVKB2INjhf0f4iV6YFRgilWj00taqym5drPsv1BUyFCSBiFCyYR7R29AVWHRs X-Received: by 2002:a17:902:830a:b0:1b8:adea:76d0 with SMTP id bd10-20020a170902830a00b001b8adea76d0mr1072891plb.31.1690360495301; Wed, 26 Jul 2023 01:34:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690360495; cv=none; d=google.com; s=arc-20160816; b=lTNThPxG1GoEbEACkUxUQszRSArPr/I/NmV3/oKXjl4ngN6DcxCGpCyqyPOswzJKhM lIKKp+G3KKCvQPNnSJzK9CAavDZbNNnbWZD3LBhvbxQBoeBlnjZJO9VZL2utKryyBBfo XLazP4JNhhQSomNsF7GiCnylsmdoI/ZveBcfLelwyWKQdR0K+B4tfyFWNyOfDCgGPWuv H1zm4onKcGT/+KH02+3FMJ+/wqy6l8nLcuXW6oQRcSM/1Dw13r1xJFY4djZOA0G12AEJ XxLi4JmfGY7taSl31yhRzy2JVx6r4c1+AX0XJox3U7U1CKmSt4zw6iXwS8nRvgy5W2T3 +v2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v8uNs+P31bvWCjQDHXfNwA0J1eeKVpGhA2UwqZlpI48=; fh=83ed9mee+o5Uq0I46ZSfSA+aUr2+chEOwR4qsJ7tckA=; b=VXk6ReznKtAHaPaydJLwhp0on6MR4wF8b6ECmy2xGUeNzXxn/x5C4BfBP9C2NnY4lc ZboG5j2zqVjlZAW8imq8pvinLqu2TzPhekBWreRarelGGjcEGNFXFdLyFoiFYU7MAvL6 srZofdrxwxAJPtQJQTNhSQIebRgGuO3/GwvNhAeqZw2d2h4LLKhNV7EQjLU14qhxD9Qo pqbo3KJRoVK71jYFlKKCE/ji8UtDv/UpbzQiAGo4R+SgwEYOih3dyoWJd8p0hzZanXw1 7Md0ftuphATd63RnMoaBJIpj5iZz/WlQ2CpBnkw1uMj8nx35ttVU7KLo85OiMUDkESxI wEyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=CrBUyHbK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n18-20020a170902d2d200b001bb993ef74dsi5314229plc.461.2023.07.26.01.34.41; Wed, 26 Jul 2023 01:34:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=CrBUyHbK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233166AbjGZIYO (ORCPT + 99 others); Wed, 26 Jul 2023 04:24:14 -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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772471446825027627 X-GMAIL-MSGID: 1772471446825027627 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. You can search for an entry from an index upwards by using mt_find(). +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() 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() will 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. +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 efficient +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