From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C22EC001DC for ; Wed, 26 Jul 2023 08:10:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88E876B0074; Wed, 26 Jul 2023 04:10:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 817416B007B; Wed, 26 Jul 2023 04:10:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66A1E6B007D; Wed, 26 Jul 2023 04:10:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 54EA86B0074 for ; Wed, 26 Jul 2023 04:10:21 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1E1DFC0D9A for ; Wed, 26 Jul 2023 08:10:21 +0000 (UTC) X-FDA: 81053040642.27.D847B6F Received: from mail-il1-f174.google.com (mail-il1-f174.google.com [209.85.166.174]) by imf25.hostedemail.com (Postfix) with ESMTP id 3C1EEA0002 for ; Wed, 26 Jul 2023 08:10:19 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=edqfz4k4; spf=pass (imf25.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.166.174 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690359019; a=rsa-sha256; cv=none; b=1qI8iQ75/GORMdluAla9cQaIdqJSAUhH+XNrKhVZGR1hUluUbsmHcABxwqGluFfyaqQjKt SUYv7pYnbSLSBjzo/d67IPsIVpsmkYQgmO3zislC6lchThxEKNm8HB7IA/OD6SsQf3bI6b xN3alY5xWN9PsfLUH+yrIsxn07737Ws= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=edqfz4k4; spf=pass (imf25.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.166.174 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690359019; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zLmPRatqLaPjNdFSIOQqmfdfgzRaFIKbs75zNZxQM3k=; b=axklaMtUQv3ty4XgcMMcxrGOzqrqTpTWYr5eqAxhFoEpX+VV0ESzlV6P121+Bq62PGSpWA QUeRv9Y1Kfr1e9T+VDZtLLS9GoRRS1+0GbBDAbn3q+Qmo4ZpUkAxRKodiZeAAosjLvrf92 fmJqh2vrZEimSzpgyRbftZJLMJCZKnk= Received: by mail-il1-f174.google.com with SMTP id e9e14a558f8ab-348c03de0e7so16509295ab.1 for ; Wed, 26 Jul 2023 01:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690359018; x=1690963818; 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=zLmPRatqLaPjNdFSIOQqmfdfgzRaFIKbs75zNZxQM3k=; b=edqfz4k42nCM4mbt3rgbm433jEQgkgjdf50ULvk8j2xYHjezVeSFt1oZ907tUkLq6H ow/CoVkmA5DqlFbF8xELCu7XeAPlG3bTVmgL6D3d33T+UtZlMVWJMJvrYHZ4nrda3KuW Pp+6+h0GCAVyTF84xW6NaL1Yy0kreE4NvfODNzLeX1FkzSpYfE4EDIGnEfkgGSLFIcf/ JNvbkrZvHx4x5rq0B03sAvUSxcYYjCKmiCcAjvYEtA5Y4uzZBxgt5r99KZvcg2AJ4Ce2 mlpfpAvootB9ZFpXGuoGEyHBwrOZDmHKQMbdKy+9I1mars1V4N4rHoRVXeHhHak5dgDV uiPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690359018; x=1690963818; 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=zLmPRatqLaPjNdFSIOQqmfdfgzRaFIKbs75zNZxQM3k=; b=k/+O1d1ChqvrAbFPbZDJ+NyiWkVCQgIC1Gy+/ezWMBJUTVK96Rkzuid4twni3UQMA9 8O2Ff3eBWwpd6YaRkqgOY/9eaigDPGpIUM2shjxv/FvhEFyO6rB095nsm3Mmh7qZAzfJ LQOkZ+UOSh0HPujg526TVFSA6copP0wgrHg5SA023f47W74HoabQczAo0VILutXDUuQm lsWBhDSgD4CJPIX9zJMtY5fdGXdAXbw2o458C303NKsaQPZNL4S02gTVe8L9LuIy+kOz 0g9vUoOvOWbSwmG/z5hiKrRD+rNiL89G8/paXEij4uxK5ZaipFB0FbZ5XK4kdJUF7N7N 5jpw== X-Gm-Message-State: ABy/qLabk+2CwASK6czl1R/4EMt3Kzot8QCuNqSpTSbB79RemvehFIXX K15BEhXx5T4BjUF52I3Gij0NVQ== X-Google-Smtp-Source: APBJJlGa1sI8Ot6wDuAGAIzbtMGaPwlxOu08ayCD0nVOoODHEZRjd9Ytl9786BZoeyT8Q0+YuiMnMQ== X-Received: by 2002:a05:6e02:92d:b0:348:c57f:b016 with SMTP id o13-20020a056e02092d00b00348c57fb016mr1153348ilt.3.1690359018367; Wed, 26 Jul 2023 01:10:18 -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.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 26 Jul 2023 01:10:18 -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 05/11] maple_tree: Add test for mt_dup() Date: Wed, 26 Jul 2023 16:09:10 +0800 Message-Id: <20230726080916.17454-6-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: 8bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 3C1EEA0002 X-Stat-Signature: icywgkfxa4zarjjhw69im5thzj8mppo6 X-Rspam-User: X-HE-Tag: 1690359019-348473 X-HE-Meta: U2FsdGVkX19kCtx6r9fALkM+SeKkJ1r9EYp9K1b9O4MbdAOT1ZJ60kjKUK+6mTCwJXk8Wf4Cn+vHs18U1vNyM9Zlrcb02S+rU1baBdZ1l9PI6AgFFW17/8v2H841OhyXLriGIjfh7zOeD8Vh/MfSeJVhiEnKP9KeW4MqxQ0DuDlIhapQ6DTG38C5JYTEa3I72VENn19oPOYJxksYMou51i7NmzcixFIB9oeGuWuZB3QkGriXCiFs7FCvExzNyQU/GLNFSLQ+5X6hLjdTrQ+kubohhP+3gyk8sngV4LneT5IGqU1Fo1WNdO180qmfRcWPuZJV8mvJaJINfQ5d3/OGShrB2CXhb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894lXV1HQpKm19k6y5zMc6LUJcbasMw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add test for mt_dup(). Signed-off-by: Peng Zhang --- tools/testing/radix-tree/maple.c | 202 +++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c index e5da1cad70ba..3052e899e5df 100644 --- a/tools/testing/radix-tree/maple.c +++ b/tools/testing/radix-tree/maple.c @@ -35857,6 +35857,204 @@ static noinline void __init check_locky(struct maple_tree *mt) mt_clear_in_rcu(mt); } +/* + * Compare two nodes and return 0 if they are the same, non-zero otherwise. + */ +static int __init compare_node(struct maple_enode *enode_a, + struct maple_enode *enode_b) +{ + struct maple_node *node_a, *node_b; + struct maple_node a, b; + void **slots_a, **slots_b; /* Do not use the rcu tag. */ + enum maple_type type; + int i; + + if (((unsigned long)enode_a & MAPLE_NODE_MASK) != + ((unsigned long)enode_b & MAPLE_NODE_MASK)) { + pr_err("The lower 8 bits of enode are different.\n"); + return -1; + } + + type = mte_node_type(enode_a); + node_a = mte_to_node(enode_a); + node_b = mte_to_node(enode_b); + a = *node_a; + b = *node_b; + + /* Do not compare addresses. */ + if (ma_is_root(node_a) || ma_is_root(node_b)) { + a.parent = (struct maple_pnode *)((unsigned long)a.parent & + MA_ROOT_PARENT); + b.parent = (struct maple_pnode *)((unsigned long)b.parent & + MA_ROOT_PARENT); + } else { + a.parent = (struct maple_pnode *)((unsigned long)a.parent & + MAPLE_NODE_MASK); + b.parent = (struct maple_pnode *)((unsigned long)b.parent & + MAPLE_NODE_MASK); + } + + if (a.parent != b.parent) { + pr_err("The lower 8 bits of parents are different. %p %p\n", + a.parent, b.parent); + return -1; + } + + /* + * If it is a leaf node, the slots do not contain the node address, and + * no special processing of slots is required. + */ + if (ma_is_leaf(type)) + goto cmp; + + slots_a = ma_slots(&a, type); + slots_b = ma_slots(&b, type); + + for (i = 0; i < mt_slots[type]; i++) { + if (!slots_a[i] && !slots_b[i]) + break; + + if (!slots_a[i] || !slots_b[i]) { + pr_err("The number of slots is different.\n"); + return -1; + } + + /* Do not compare addresses in slots. */ + ((unsigned long *)slots_a)[i] &= MAPLE_NODE_MASK; + ((unsigned long *)slots_b)[i] &= MAPLE_NODE_MASK; + } + +cmp: + /* + * Compare all contents of two nodes, including parent (except address), + * slots (except address), pivots, gaps and metadata. + */ + return memcmp(&a, &b, sizeof(struct maple_node)); +} + +/* + * Compare two trees and return 0 if they are the same, non-zero otherwise. + */ +static int __init compare_tree(struct maple_tree *mt_a, struct maple_tree *mt_b) +{ + MA_STATE(mas_a, mt_a, 0, 0); + MA_STATE(mas_b, mt_b, 0, 0); + + if (mt_a->ma_flags != mt_b->ma_flags) { + pr_err("The flags of the two trees are different.\n"); + return -1; + } + + mas_dfs_preorder(&mas_a); + mas_dfs_preorder(&mas_b); + + if (mas_is_ptr(&mas_a) || mas_is_ptr(&mas_b)) { + if (!(mas_is_ptr(&mas_a) && mas_is_ptr(&mas_b))) { + pr_err("One is MAS_ROOT and the other is not.\n"); + return -1; + } + return 0; + } + + while (!mas_is_none(&mas_a) || !mas_is_none(&mas_b)) { + + if (mas_is_none(&mas_a) || mas_is_none(&mas_b)) { + pr_err("One is MAS_NONE and the other is not.\n"); + return -1; + } + + if (mas_a.min != mas_b.min || + mas_a.max != mas_b.max) { + pr_err("mas->min, mas->max do not match.\n"); + return -1; + } + + if (compare_node(mas_a.node, mas_b.node)) { + pr_err("The contents of nodes %p and %p are different.\n", + mas_a.node, mas_b.node); + mt_dump(mt_a, mt_dump_dec); + mt_dump(mt_b, mt_dump_dec); + return -1; + } + + mas_dfs_preorder(&mas_a); + mas_dfs_preorder(&mas_b); + } + + return 0; +} + +static noinline void __init check_mt_dup(struct maple_tree *mt) +{ + DEFINE_MTREE(new); + int i, j, ret, count = 0; + + /* stored in the root pointer*/ + mt_init_flags(&tree, 0); + mtree_store_range(&tree, 0, 0, xa_mk_value(0), GFP_KERNEL); + mt_dup(&tree, &new, GFP_KERNEL); + mt_validate(&new); + if (compare_tree(&tree, &new)) + MT_BUG_ON(&new, 1); + + mtree_destroy(&tree); + mtree_destroy(&new); + + for (i = 0; i < 1000; i += 3) { + if (i & 1) + mt_init_flags(&tree, 0); + else + mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE); + + for (j = 0; j < i; j++) { + mtree_store_range(&tree, j * 10, j * 10 + 5, + xa_mk_value(j), GFP_KERNEL); + } + + ret = mt_dup(&tree, &new, GFP_KERNEL); + MT_BUG_ON(&new, ret != 0); + mt_validate(&new); + if (compare_tree(&tree, &new)) + MT_BUG_ON(&new, 1); + + mtree_destroy(&tree); + mtree_destroy(&new); + } + + /* Test memory allocation failed. */ + for (i = 0; i < 1000; i += 3) { + if (i & 1) + mt_init_flags(&tree, 0); + else + mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE); + + for (j = 0; j < i; j++) { + mtree_store_range(&tree, j * 10, j * 10 + 5, + xa_mk_value(j), GFP_KERNEL); + } + + mt_set_non_kernel(50); + ret = mt_dup(&tree, &new, GFP_NOWAIT); + mt_set_non_kernel(0); + if (ret != 0) { + MT_BUG_ON(&new, ret != -ENOMEM); + count++; + mtree_destroy(&tree); + continue; + } + + mt_validate(&new); + if (compare_tree(&tree, &new)) + MT_BUG_ON(&new, 1); + + mtree_destroy(&tree); + mtree_destroy(&new); + } + + /* pr_info("mt_dup() fail %d times\n", count); */ + BUG_ON(!count); +} + extern void test_kmem_cache_bulk(void); void farmer_tests(void) @@ -35904,6 +36102,10 @@ void farmer_tests(void) check_null_expand(&tree); mtree_destroy(&tree); + mt_init_flags(&tree, 0); + check_mt_dup(&tree); + mtree_destroy(&tree); + /* RCU testing */ mt_init_flags(&tree, 0); check_erase_testset(&tree); -- 2.20.1