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 DB9D6D68BDA for ; Sat, 16 Nov 2024 01:41:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6C346B00C4; Fri, 15 Nov 2024 20:41:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CF4006B00C5; Fri, 15 Nov 2024 20:41:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B464D6B00C6; Fri, 15 Nov 2024 20:41:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 933F66B00C4 for ; Fri, 15 Nov 2024 20:41:24 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0A8381C4962 for ; Sat, 16 Nov 2024 01:41:24 +0000 (UTC) X-FDA: 82790252454.20.283DD31 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) by imf02.hostedemail.com (Postfix) with ESMTP id 05BCC8001A for ; Sat, 16 Nov 2024 01:39:54 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UCQcgU02; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731721102; a=rsa-sha256; cv=none; b=2RZ3HkifxYMszJfz31mn5ynGgis2cLHemYLNcg+zAxEWQiAzC5O9I0OHpUlW3bflS2zuAs 1ZqXxJh8+xnkTFlS/SqQ04YYDyjcpIPs5AGfbohW4mQlK/IEbgEkpQjQl4c90/U+JaYNlV ThKQ/56Owlbapw6P8MX63I9N/Z+faDE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UCQcgU02; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731721102; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kT52XIvuMeYgn+oMzKuzUITdq0BanYWIJNtHWfhNXjg=; b=iuhpXKDu8wlDhHgb/XemTXGVn0tCB7ZjldNmp/vOjp5RmhRSJpMCFxj66NVtHv8Mp9SuM/ XnU4UW5IHReVtXroFUadhZCy5NhykBHV/zPW03re3Ql8fSc7wWpoSoFtuPmLRj0mY6hcdY 0w3ZTnK8ZDJGmrQodD3u9yIOwriPaJU= Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5cb6ca2a776so3979507a12.0 for ; Fri, 15 Nov 2024 17:41:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731721280; x=1732326080; darn=kvack.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=kT52XIvuMeYgn+oMzKuzUITdq0BanYWIJNtHWfhNXjg=; b=UCQcgU0288ki2HglTHhJ60sXlxFkSycbSTD17nnxbKI3ucIsn/B5tUQaSx2hrghlW9 3OoLGAl6yJq8PPTh+QgnADE+TnGOfXo6fdXiPhXO4Y0Xce0Z1rFgYiakhnmDs7EPwaPW K4JkgiunSVd8k+Wopv2gEpDNTOi+JytyNgkFulaiZj5JnEz0ftfKexcDyo2IGWL/zjMq yb20YCysPC+5jQXURkUYYwsvmYWueRG/knIMV5/8rMalZb9THiOgJB8cWXAiC2axh5IQ w1DjZ8gYqJ23DDWvnPWG/T7LftDcdSJKLiX/ieZHrqzMf4NkJsZ5EwaouEAuwCOjNRJc 3LVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731721280; x=1732326080; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=kT52XIvuMeYgn+oMzKuzUITdq0BanYWIJNtHWfhNXjg=; b=AxJLnQKBO7NdqKzc5QpLu8WXPd5EUoPubmZl0mPxpzl/S//YziCsAbWRLYblwCbzk2 LJO2YFVdlhqmDGZK3GW3NFvYxhGBl3lPfddCWUD9Vm08ALGRyc47p5DdTPjUtBVbb2eB 4hrA5Q4jFAAz5zRnzYRI+AlgGcwjt0IHN+A737MM61IGoCm7m7vCYaIOoHHoeQyapeIg E4wOWmvPbSoVAOMKgAMB3huhEPBG6IU7G1ss2eAeOAII2vwvbFTVXTUEd/KBBhgdn8x1 7Kn2umeqQp5YRJ09rlucvjBhXNStGOHGZ8E5K3bN3DU+oO/GxuXrkZL1Cya0KDvNP/7y wXpA== X-Forwarded-Encrypted: i=1; AJvYcCWtjVLCweDHOynXYndoMuxPUkjH+ba8ptiHcJX+U7UdkBe2W7KA9X+/3B2kNEk+n2oIBL7Zoq6R/A==@kvack.org X-Gm-Message-State: AOJu0YwBwbrQQhQ3V0caltmFGYUO9M4pMZWB6/3QpmTumYqvLdAQiwts nRA5saT6YjsTN64QK+8ARgqcmtzgyBVeXI5kXe0etceWvzlr/YYv X-Google-Smtp-Source: AGHT+IHzlLHHlYLC08RK++hR/9MtTAwXU9ob5isqHjfuY7I5J3gS2FmEQxNmTR5MMGxb+W1kaKCzjw== X-Received: by 2002:a17:907:809:b0:a99:5021:bcf0 with SMTP id a640c23a62f3a-aa483454541mr333282266b.34.1731721280067; Fri, 15 Nov 2024 17:41:20 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df26598sm237246266b.2.2024.11.15.17.41.17 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Nov 2024 17:41:18 -0800 (PST) Date: Sat, 16 Nov 2024 01:41:16 +0000 From: Wei Yang To: Sidhartha Kumar Cc: Wei Yang , linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, akpm@linux-foundation.org, liam.howlett@oracle.com Subject: Re: [PATCH 3/5] maple_tree: use vacant nodes to reduce worst case allocations Message-ID: <20241116014116.a7am7z4p7k33rkl5@master> Reply-To: Wei Yang References: <20241114170524.64391-1-sidhartha.kumar@oracle.com> <20241114170524.64391-4-sidhartha.kumar@oracle.com> <20241115075203.ojspk255cw3sr3s3@master> <2aa439f1-d33d-43ee-9945-5ac570506c7e@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2aa439f1-d33d-43ee-9945-5ac570506c7e@oracle.com> User-Agent: NeoMutt/20170113 (1.7.2) X-Stat-Signature: fjtw8qw8zm7cuwakqhonid5h8thpweax X-Rspamd-Queue-Id: 05BCC8001A X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1731721194-332195 X-HE-Meta: U2FsdGVkX18W6STiJRZjU4PlAdD71qobsPpYBrmPIf0v3Xu3mnBiIi0YPfEstLafcFnOMGfIKfOHiSS9Jgfwlk9p7bOJ4wkc0DK3MdtBaEEW9KqMEu3OzMPBwzLVPKR0faTbBOhtE7Xtst8UE/+y9MoXJtNmy0JfWYZ2LbNQQwyhUZSdBhkr+qNjdrPRwLoEYojZoKcRgtg7EzjOj2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ekHzy0OHEqFCGSn+MPzaA8JHCBqfhZH9AhSmRzVfVzPyc8N8sDRRAbS2BBsMr/Nt7fmlx1TuKwWFSSDrwPj8BfiqulfM6BJRRzWLWacvKjvvDYDSi+vyGOk+RERxZagUYN2uSAaC6heL94WY6FHAW1SMDkgyl6U3KLI+Gg3rKfz0kxWv8KL8991ba+TrJ6CZ1b9RkibHIdDywjBM9bjT3+wdhMjQ7VCDJ8bYBA7Tm0YAzDcLo5gFToC2LOlxBbduPvXRpCUDs5WvACv9ig3uaKxHnel183OJz1oduDFU7tLmqKc3QmPn9fnOFv2R9R81SNhHIRFQY1+QYvJohzHXIAJCpVChvv7lFOnG3Ua8zmb1G9mVEgHOy9KyJwxnw+KHpMVrDR5UIIw6RFPYwuDnib8N X-Bogosity: Ham, tests=bogofilter, spamicity=0.000482, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Nov 15, 2024 at 03:34:55PM -0500, Sidhartha Kumar wrote: >On 11/15/24 2:52 AM, Wei Yang wrote: >> On Thu, Nov 14, 2024 at 12:05:22PM -0500, Sidhartha Kumar wrote: >> > In order to determine the store type for a maple tree operation, a walk >> > of the tree is done through mas_wr_walk(). This function descends the >> > tree until a spanning write is detected or we reach a leaf node. While >> > descending, keep track of the height at which we encounter a node with >> > available space. This is done by checking if mas->end is less than the >> > number of slots a given node type can fit. >> > >> > Now that the height of the vacant node is tracked, we can use the >> > difference between the height of the tree and the height of the vacant >> > node to know how many levels we will have to propagate creating new >> > nodes. Update mas_prealloc_calc() to consider the vacant height and >> > reduce the number of worst allocations. >> > >> > Rebalancing stores are not supported and fall back to using the full >> > height of the tree for allocations. >> > >> > Update preallocation testing assertions to take into account vacant >> > height. >> > >> > Signed-off-by: Sidhartha >> > --- >> > include/linux/maple_tree.h | 2 + >> > lib/maple_tree.c | 13 +++-- >> > tools/testing/radix-tree/maple.c | 97 +++++++++++++++++++++++++++++--- >> > 3 files changed, 100 insertions(+), 12 deletions(-) >> > >> > diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h >> > index cbbcd18d4186..7d777aa2d9ed 100644 >> > --- a/include/linux/maple_tree.h >> > +++ b/include/linux/maple_tree.h >> > @@ -463,6 +463,7 @@ struct ma_wr_state { >> > void __rcu **slots; /* mas->node->slots pointer */ >> > void *entry; /* The entry to write */ >> > void *content; /* The existing entry that is being overwritten */ >> > + unsigned char vacant_height; /* Depth of lowest node with free space */ >> ^^^ ^^^ >> >> Would this be a little misleading? >> > >Could you elaborate on how its misleading? > As you mentioned in previous patch, depth and height has different meaning. Root node has depth of 0 and height of 1. So I may wandering whether this is depth or height. >> > }; >> > >> > #define mas_lock(mas) spin_lock(&((mas)->tree->ma_lock)) >> > @@ -498,6 +499,7 @@ struct ma_wr_state { >> > .mas = ma_state, \ >> > .content = NULL, \ >> > .entry = wr_entry, \ >> > + .vacant_height = 0 \ >> > } >> > >> > #define MA_TOPIARY(name, tree) \ >> > diff --git a/lib/maple_tree.c b/lib/maple_tree.c >> > index 21289e350382..f14d70c171c2 100644 >> > --- a/lib/maple_tree.c >> > +++ b/lib/maple_tree.c >> > @@ -3545,6 +3545,9 @@ static bool mas_wr_walk(struct ma_wr_state *wr_mas) >> > if (ma_is_leaf(wr_mas->type)) >> > return true; >> > >> > + if (mas->end < mt_slots[wr_mas->type] - 1) >> > + wr_mas->vacant_height = mas->depth + 1; >> >> For some cases in rebalance, we may split data into three parts, which means >> we need 2 extra vacant slot. >> >> Maybe this check is not accurate? >> > >The triple split scenario which you are describing comes from the spanning >store case not on the wr_rebalance case. There is a check before we set >vacant height to return if is_span_wr() so I believe this is correct still. > Hmm... I come up with a case in which vacant_height may not high enough. Here is the subtree where spanning write locates. The first level is the parent node of the second level nodes. vacant node +--------+-+-+-------+ | |l|r| | +--------+-+-+-------+ l r +------+ +----+-------+ +---------+--+ +------+ | | | | | | | | | | +------+ +----+-------+ +---------+--+ +------+ ^ ^ | | index last When mas_wr_walk_descend() to node l, mas_is_span_wr() return true since last is in the right sibling, node r. Let's say the parent is vacant and l/r is leaf. So the request number is (1 * 3) + 1. Let's assume: * vacant node is just sufficient * l's left part + r's right part is sufficient but not overflow Then the "new vacant node" would be deficient and needs another round rebalance. For this case, I am afraid it doesn't allocate enough nodes. Or I misunderstand this? -- Wei Yang Help you, Help me