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 0F72BEE57EB for ; Fri, 8 Sep 2023 09:38:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 518BD6B00A8; Fri, 8 Sep 2023 05:38:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C96F6B00A9; Fri, 8 Sep 2023 05:38:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3696D6B00AA; Fri, 8 Sep 2023 05:38:16 -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 267306B00A8 for ; Fri, 8 Sep 2023 05:38:16 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DDE3CA1124 for ; Fri, 8 Sep 2023 09:38:15 +0000 (UTC) X-FDA: 81212929350.29.DED2D94 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf08.hostedemail.com (Postfix) with ESMTP id 38F6D16002A for ; Fri, 8 Sep 2023 09:38:12 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=W8R3CPVl; spf=pass (imf08.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.215.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=1694165894; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mQurMd8wafZyGpE7OFXdsS2nMZ3Ok9Nncr0Nhd/YGjQ=; b=HLmS6LUij88djSW6LzlTgv2rk2mJV7PvJXdfkLmXCuTFFHSKHbjnLMRWRhb99ohXuNeNeH XxXZ2wNkGEDkknnlPu7a50+Ctb0vDLjX2FHFbeFnyraOp9nOkzLhUwV5WSq68fRoPyRKDb macPY6q8aXzLqQ78YWSObibYumI7Ghc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694165894; a=rsa-sha256; cv=none; b=62pLq99ioxZnQJuUP7C1X5EnyPSx0wkun7DFdb14Ij/Ifl4NhiKflBMf3dJWgUD2e7diIk oXjFP+aF/7KUIKC8tLWE9cfhnRYjxVTcC8srPFo7ISESvBW86aZuQv0Jl1dMaPBJfM4HZm O6WmA3lUlCGp2+YStXZbVQZxo/O14oM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=W8R3CPVl; spf=pass (imf08.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-53fa455cd94so1441937a12.2 for ; Fri, 08 Sep 2023 02:38:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694165892; x=1694770692; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:references:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=mQurMd8wafZyGpE7OFXdsS2nMZ3Ok9Nncr0Nhd/YGjQ=; b=W8R3CPVlLjXxOWDr+iYGG96u9MBfuItrem5I4UFchzWdDA4LdG0GBa2ElEeFTLqJE6 8Ir0NqQoFl4zF82BYlaPmYJ8pH2QwGE5Z6MXNOcZJ0ICoxodBZ5NjMXO5V6EjdXKTFHt GiikZCb2K1mE+4o7oZPFg2dYXutPqFoYg9BWXnGrFs4WdRik/C9r8NSGxeYI6TLIFR6X InLJcV5zLoABbuczV+R4D5tnvTjWPU61Nw5UKIvcXnw7dFIDtAvO712dra/vXbpIWIiT XszUs09864LSXmOclu25ghprPSPE6AO7ESJ+0nQQLoJtUEDj0MGnjB8G7gzsuS3GAjBt chFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694165892; x=1694770692; h=content-transfer-encoding:in-reply-to:from:references:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=mQurMd8wafZyGpE7OFXdsS2nMZ3Ok9Nncr0Nhd/YGjQ=; b=RpuxrXcrgXYGhUbORhJ8F4gcnqfv5IAx7BvdFU1CaNSTuqz3K0EABWM7iniI0I12h9 JBVZX9oEIxRB1GBsihiWQn+CQ5FszlCcNPlRDgaep5AjjfoqGQ30wt11fXHmag/itavU RskIjk7qWk293mRxmT+6IPVDZoHLCKeebJddsmF9X29AWj8zJIZPA9qCJTODfMPdQMKc 6HiclXOKM2pFPEQY6g03nXNUzk3egcyk3nl98KyOzb7/6teSaCfVUzBSVwJL4/WH7zW7 jD8OvpgmedlP0YnM4KAuYe87WBrocH6BUy82ZCjnzmW86Jlxp7JFmi1MZBmxLnxK0M7p X5Mg== X-Gm-Message-State: AOJu0YwyInK4oERpMJR8T+A2A8h/Mh1Wa0elxg49sbcUjJySUfeiF6GY Joy0spdT9anAy1rzdcm3MTIY9A== X-Google-Smtp-Source: AGHT+IHB91jf4hnfV9rkW+86RhzzNtiPB4y2Fqq2M5G67tYchUf6VDoRL5TFEYDoIX4qASMsUn4mAw== X-Received: by 2002:a17:90a:cb93:b0:26b:36dc:2f08 with SMTP id a19-20020a17090acb9300b0026b36dc2f08mr2043363pju.46.1694165891549; Fri, 08 Sep 2023 02:38:11 -0700 (PDT) Received: from [10.254.232.87] ([139.177.225.246]) by smtp.gmail.com with ESMTPSA id k92-20020a17090a4ce500b00267d9f4d340sm2892132pjh.44.2023.09.08.02.38.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 Sep 2023 02:38:11 -0700 (PDT) Message-ID: <8f0f4338-40ec-935c-4687-e6217b7bae3e@bytedance.com> Date: Fri, 8 Sep 2023 17:38:03 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: [PATCH v2 3/6] maple_tree: Add test for mtree_dup() To: "Liam R. Howlett" , Peng Zhang , 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, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org References: <20230830125654.21257-1-zhangpeng.00@bytedance.com> <20230830125654.21257-4-zhangpeng.00@bytedance.com> <20230907201353.jv6bojekvamvdzaj@revolver> From: Peng Zhang In-Reply-To: <20230907201353.jv6bojekvamvdzaj@revolver> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Stat-Signature: n8a55x5bqy5nhjwnao78ognpoikstosw X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 38F6D16002A X-Rspam-User: X-HE-Tag: 1694165892-601467 X-HE-Meta: U2FsdGVkX19F8IeFdnPbPwJK7dNq1Y3Pzm4hKhTSRkP+dLXVuVjNWSHvl1SN8Biwva0tT2htysbDvYWR013vjpp81pQhfyAuR/utUknTwBFaI2ewPdq2YdlsiyJPNWUFUPu3sO1HXF9gQ6kWYUIE9b7CwxBuEhNswk6BaVyROXNeHeZ33WAjdrpAGVNDb4JLsNslH10HzNANsY4SfYpKKZm//ThoDTJCrNFti5rO8ZNnpcFZGEe7MTnmGON4Bmm2CJXhytpnDyYJU9YGgUnHSGGKe5A4vcBp5HD0Mbz8+dS8Ug5mDfWMQl7xukZLMPDOkCguTsuHLpUhohlmqEJQFzMQaz0cXWGRMJUesKjFMmxlJLRxhOQlheIVFH5uZt1wSREuGMAVu5O49mywR4CgYRqzerY1/YaBr6FnnZGJU66UJUikJl68XOe9WylYOVXutIgHyfj0lWb9UFgxRidcSP5mPn2h9vZlemyLRjRR5KOIcZPr49hb+SDmCftY8mDUrU+tQ3ZoV+D9hiRLUAsbX9/Zsh1rze2Qncb9d+LTAg1CHa+y4j9LzJvqehITd9uMlU71w/8q/uix7kcbujHeqayAflzdiQdImcuQYssje6uC5pVs4gAgR3d9rF3QN6X3jrLeo754RdJ29eFRs6DdMIj7+gqXHCwM0cZ/qvj7O3p+XjNY/7WFiWzrCoXZLKS3+RnaxJaf7hpetlLW3GIvFoFenDN41l+00sFa62JbRHq9AiQzk+/ndqMeGblZzDBCTjmAI1mfSbou7zBMEZ2jvPui6s1cT1A49hXuQnJldFVBPujxnYvlhhzo7kpePqOIdWdUkNX+iks4Xhan/3ZaR/PbU6xhf3wOXtS3FA/TvgvV8YMyjnK/fjly3EMlYHicJ68mU2VVnX4PtyqNlOQGl0aHdundvOMtARo6vXm9VAZdyGBraqXU7uiL2L/KVi8bVEV8T5UfI5spm/yK16Q FGZpd7hS KffdibVeP3FH21BhKyarjrifHgoiOEDNtfqEBJ26GI51eTbwzhcY4NUMwNgoCWnqtkBnUSoe6OUeakf/4aVMIYTlpzUUUn6Qs3e9Ytq63Zx1wUBioIE+W4QWd8NQKp17hC/ekl4gmWM06hf7eReJeila6lcEHVkIjc2AOiM8POK50HGv+baqLG/WDmx7r/WkChp0YtDVHaBsT3O9/AcItAQkkqX046YBWN02x5rvZxUdne4L8UlHdrR+iUox3HUHWxqV0dEHgFvyyrP9n0ZDRjtHJv7bJteJupbD+7MwcnPLMPj+zLTstF997pwkOc+Zkh3A/hI/uqJRARwE/4bsErxtSvMDtsAtvW1LQpsTlqNoBPvg8gAFbCe7TBDgCwMPE9Bq4bT0km2c+6kPY4TqRI7Z6FbL9fjVC18onuDga9dXjo4QgVDoT6hKu4C/DunP6BTCF2o/vWNyfWZY9JAZnm8MJ076ivIFyJHVvAh3tPxQ1MmOoiwjqmGaytxeperqi6aSD 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: 在 2023/9/8 04:13, Liam R. Howlett 写道: > * Peng Zhang [230830 08:57]: >> Add test for mtree_dup(). > > Please add a better description of what tests are included. > >> >> Signed-off-by: Peng Zhang >> --- >> tools/testing/radix-tree/maple.c | 344 +++++++++++++++++++++++++++++++ >> 1 file changed, 344 insertions(+) >> >> diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c >> index e5da1cad70ba..38455916331e 100644 >> --- a/tools/testing/radix-tree/maple.c >> +++ b/tools/testing/radix-tree/maple.c > > Why not lib/test_maple_tree.c? Because I used mas_dfs_preorder() in user space, which is implemented in maple.c > > If they are included there then they will be built into the test module. > I try to include any tests that I can in the test module, within reason. > > >> @@ -35857,6 +35857,346 @@ 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. > > The slots can be different, right? That seems worth mentioning here. > It's also worth mentioning this is destructive. Ok, I'll mention this. > >> + */ >> +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 __init void mas_subtree_max_range(struct ma_state *mas) >> +{ >> + unsigned long limit = mas->max; >> + MA_STATE(newmas, mas->tree, 0, 0); >> + void *entry; >> + >> + mas_for_each(mas, entry, limit) { >> + if (mas->last - mas->index >= >> + newmas.last - newmas.index) { >> + newmas = *mas; >> + } >> + } >> + >> + *mas = newmas; >> +} >> + >> +/* >> + * build_full_tree() - Build a full tree. >> + * @mt: The tree to build. >> + * @flags: Use @flags to build the tree. >> + * @height: The height of the tree to build. >> + * >> + * Build a tree with full leaf nodes and internal nodes. Note that the height >> + * should not exceed 3, otherwise it will take a long time to build. >> + * Return: zero if the build is successful, non-zero if it fails. >> + */ >> +static __init int build_full_tree(struct maple_tree *mt, unsigned int flags, >> + int height) >> +{ >> + MA_STATE(mas, mt, 0, 0); >> + unsigned long step; >> + int ret = 0, cnt = 1; >> + enum maple_type type; >> + >> + mt_init_flags(mt, flags); >> + mtree_insert_range(mt, 0, ULONG_MAX, xa_mk_value(5), GFP_KERNEL); >> + >> + mtree_lock(mt); >> + >> + while (1) { >> + mas_set(&mas, 0); >> + if (mt_height(mt) < height) { >> + mas.max = ULONG_MAX; >> + goto store; >> + } >> + >> + while (1) { >> + mas_dfs_preorder(&mas); >> + if (mas_is_none(&mas)) >> + goto unlock; >> + >> + type = mte_node_type(mas.node); >> + if (mas_data_end(&mas) + 1 < mt_slots[type]) { >> + mas_set(&mas, mas.min); >> + goto store; >> + } >> + } >> +store: >> + mas_subtree_max_range(&mas); >> + step = mas.last - mas.index; >> + if (step < 1) { >> + ret = -1; >> + goto unlock; >> + } >> + >> + step /= 2; >> + mas.last = mas.index + step; >> + mas_store_gfp(&mas, xa_mk_value(5), >> + GFP_KERNEL); >> + ++cnt; >> + } >> +unlock: >> + mtree_unlock(mt); >> + >> + MT_BUG_ON(mt, mt_height(mt) != height); >> + /* pr_info("height:%u number of elements:%d\n", mt_height(mt), cnt); */ >> + return ret; >> +} >> + >> +static noinline void __init check_mtree_dup(struct maple_tree *mt) >> +{ >> + DEFINE_MTREE(new); >> + int i, j, ret, count = 0; >> + unsigned int rand_seed = 17, rand; >> + >> + /* store a value at [0, 0] */ >> + mt_init_flags(&tree, 0); >> + mtree_store_range(&tree, 0, 0, xa_mk_value(0), GFP_KERNEL); >> + ret = mtree_dup(&tree, &new, GFP_KERNEL); >> + MT_BUG_ON(&new, ret); >> + mt_validate(&new); >> + if (compare_tree(&tree, &new)) >> + MT_BUG_ON(&new, 1); >> + >> + mtree_destroy(&tree); >> + mtree_destroy(&new); >> + >> + /* The two trees have different attributes. */ >> + mt_init_flags(&tree, 0); >> + mt_init_flags(&new, MT_FLAGS_ALLOC_RANGE); >> + ret = mtree_dup(&tree, &new, GFP_KERNEL); >> + MT_BUG_ON(&new, ret != -EINVAL); >> + mtree_destroy(&tree); >> + mtree_destroy(&new); >> + >> + /* The new tree is not empty */ >> + mt_init_flags(&tree, 0); >> + mt_init_flags(&new, 0); >> + mtree_store(&new, 5, xa_mk_value(5), GFP_KERNEL); >> + ret = mtree_dup(&tree, &new, GFP_KERNEL); >> + MT_BUG_ON(&new, ret != -EINVAL); >> + mtree_destroy(&tree); >> + mtree_destroy(&new); >> + >> + /* Test for duplicating full trees. */ >> + for (i = 1; i <= 3; i++) { >> + ret = build_full_tree(&tree, 0, i); >> + MT_BUG_ON(&tree, ret); >> + mt_init_flags(&new, 0); >> + >> + ret = mtree_dup(&tree, &new, GFP_KERNEL); >> + MT_BUG_ON(&new, ret); >> + mt_validate(&new); >> + if (compare_tree(&tree, &new)) >> + MT_BUG_ON(&new, 1); >> + >> + mtree_destroy(&tree); >> + mtree_destroy(&new); >> + } >> + >> + for (i = 1; i <= 3; i++) { >> + ret = build_full_tree(&tree, MT_FLAGS_ALLOC_RANGE, i); >> + MT_BUG_ON(&tree, ret); >> + mt_init_flags(&new, MT_FLAGS_ALLOC_RANGE); >> + >> + ret = mtree_dup(&tree, &new, GFP_KERNEL); >> + MT_BUG_ON(&new, ret); >> + mt_validate(&new); >> + if (compare_tree(&tree, &new)) >> + MT_BUG_ON(&new, 1); >> + >> + mtree_destroy(&tree); >> + mtree_destroy(&new); >> + } >> + >> + /* Test for normal duplicating. */ >> + for (i = 0; i < 1000; i += 3) { >> + if (i & 1) { >> + mt_init_flags(&tree, 0); >> + mt_init_flags(&new, 0); >> + } else { >> + mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE); >> + mt_init_flags(&new, 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 = mtree_dup(&tree, &new, GFP_KERNEL); >> + MT_BUG_ON(&new, ret); >> + mt_validate(&new); >> + if (compare_tree(&tree, &new)) >> + MT_BUG_ON(&new, 1); >> + >> + mtree_destroy(&tree); >> + mtree_destroy(&new); >> + } >> + >> + /* Test memory allocation failed. */ > > It might be worth while having specific allocations fail. At a leaf > node, intermediate nodes, first node come to mind. In fact, the random number has covered the first node. I'll write some test cases later. > >> + for (i = 0; i < 1000; i += 3) { >> + if (i & 1) { >> + mt_init_flags(&tree, 0); >> + mt_init_flags(&new, 0); >> + } else { >> + mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE); >> + mt_init_flags(&new, 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); >> + } >> + /* >> + * The rand() library function is not used, so we can generate >> + * the same random numbers on any platform. >> + */ >> + rand_seed = rand_seed * 1103515245 + 12345; >> + rand = rand_seed / 65536 % 128; >> + mt_set_non_kernel(rand); >> + >> + ret = mtree_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("mtree_dup() fail %d times\n", count); */ >> + BUG_ON(!count); >> +} >> + >> extern void test_kmem_cache_bulk(void); >> >> void farmer_tests(void) >> @@ -35904,6 +36244,10 @@ void farmer_tests(void) >> check_null_expand(&tree); >> mtree_destroy(&tree); >> >> + mt_init_flags(&tree, 0); >> + check_mtree_dup(&tree); >> + mtree_destroy(&tree); >> + >> /* RCU testing */ >> mt_init_flags(&tree, 0); >> check_erase_testset(&tree); >> -- >> 2.20.1 >>