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 94741C77B78 for ; Thu, 20 Apr 2023 04:21:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86DDB6B0071; Thu, 20 Apr 2023 00:21:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 81E746B0072; Thu, 20 Apr 2023 00:21:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E5BA6B0074; Thu, 20 Apr 2023 00:21:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5BCB26B0071 for ; Thu, 20 Apr 2023 00:21:12 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1721440498 for ; Thu, 20 Apr 2023 04:21:12 +0000 (UTC) X-FDA: 80700469584.10.2E64199 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf29.hostedemail.com (Postfix) with ESMTP id CC4E212001C for ; Thu, 20 Apr 2023 04:21:08 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=TtlvBqWo; spf=pass (imf29.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.215.176 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=1681964469; 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=Ifhg/4wKiyjaXBSAZD8UD8hDN/wBg/sQQRUVu3etZ9U=; b=ZTPZKVLdEW1rmzb/Yd2C7bqvj1yI58lKeFHb5+vDgYR+I3NQto7VkzRGtcP6Uy2S0w4ePi 3siLS+xnm74RiZUvi4l2wMcFwAsjLnKByHfOQ+TtbO7OFDL6HfQNhPJ4k5AhFZ3Z4Ri44A 00JqNqG0dT6od8m6DnwHPu8+Y35BlVI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681964469; a=rsa-sha256; cv=none; b=tVVXfAM5M2Agbw4Lnakt/ma0hgJKnWVZ0c8aDRTiZUtNmlyP7n88F8R3AsXR0+jGt3NNDq ffbjaiLD18wuKs3quStX+gPUBdl7JjAg98ZAIgW2PSQ1MNxHKFcKCI3QbSmJl9080wu2p2 pHLAA9tWzBxgRVOfMXiizyUjVG3gtcw= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=TtlvBqWo; spf=pass (imf29.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-51b661097bfso415282a12.0 for ; Wed, 19 Apr 2023 21:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681964467; x=1684556467; 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=Ifhg/4wKiyjaXBSAZD8UD8hDN/wBg/sQQRUVu3etZ9U=; b=TtlvBqWoc2jm36vCVOCH5P/7+aPiHvKY5fUkMmMVZLDOlb1oKJVyLbeL4Kk06vyQGI r9wkAZRY0NiIkgMBhnPvYCiQQlzGt5E2zyAENCjvb5hTHTWF/iXVz5F+nzDEcn7xGegP Zqaw7LFr+jKjChSXdom3OHQYKoHeUXGQWtR+qzkI1+QAHknV5IptncMaD9O+w2lximD9 QzPxFZqYK4plIElw/F5urQX4n3yPZ0xQsBsSHHtPwR3sJMLX/yZORSYsSl3lgTwrDLNa QDW3/pFdH0VKYjKF3mhaMpdiFaPpssp0KTV7pZjPXVZUE3eS3gEgk5MbnQbeaK5Nc2w4 XBhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681964467; x=1684556467; 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=Ifhg/4wKiyjaXBSAZD8UD8hDN/wBg/sQQRUVu3etZ9U=; b=NKMWTSLS75eS0PYFEeKoU+iK7l8F5OJqkvcxUgIm2m4Dfpn1FVq2Pyp1OGeVoP1tdi Epad6AT5Ve9K/Z83rMtsMtuax4Ydb9jOk7B8DyKkU0aM3JrgDJwIPSbu6qwY2oMrDJD6 Bsqnoss1k23GkcvYqXu/KKlIPSVVwDhLAIKrFCXJphhAZL29qwxMqshfbO+/kL1trBkR k5sr2OtuTF9zRXjE9SwrHI7njmcb0MKSrx1OJXbfvC9Ax1ABK8QgDUBudPOHCQoP48nr +VAkSMBIN3HYHFzj78CsJEmPF04U5VLxKoH9a8YQ7CUK8/XSs0Dcnfp1DTZaJJWO0yb0 xcFA== X-Gm-Message-State: AAQBX9eEqGseJQbUa331o2xgt4Po1pgpw9WneHh3LwSBbc+IoIaK6Yw6 pv4ZcR4CW6lnh7bzEJkAAXBscw== X-Google-Smtp-Source: AKy350YyORwot+Rvti/LnKfw18XvtNb12HK6l4jBCdFe36mk9B5f8g4bF230dGemqsCnHpYFsQQmNQ== X-Received: by 2002:a05:6a20:729a:b0:ef:ead5:6fdf with SMTP id o26-20020a056a20729a00b000efead56fdfmr386294pzk.33.1681964467173; Wed, 19 Apr 2023 21:21:07 -0700 (PDT) Received: from [10.200.10.217] ([139.177.225.248]) by smtp.gmail.com with ESMTPSA id r78-20020a632b51000000b00520f316ebe3sm181883pgr.62.2023.04.19.21.21.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 Apr 2023 21:21:06 -0700 (PDT) Message-ID: <2c4f6226-7ae1-a60b-e468-2142db64ea97@bytedance.com> Date: Thu, 20 Apr 2023 12:21:01 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH 1/3] maple_tree: Make maple state reusable after mas_empty_area_rev() To: "Liam R. Howlett" , Peng Zhang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Rick Edgecombe , Andrew Morton References: <20230414145728.4067069-1-Liam.Howlett@oracle.com> <90fd5cfa-5ed9-495f-fdef-0130adaf591b@bytedance.com> <20230419225419.czzwbdgys367fax2@revolver> From: Peng Zhang In-Reply-To: <20230419225419.czzwbdgys367fax2@revolver> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Queue-Id: CC4E212001C X-Rspamd-Server: rspam09 X-Stat-Signature: itzdsj39s4r6yg6wkpogw9wdtg9wh4e4 X-HE-Tag: 1681964468-351976 X-HE-Meta: U2FsdGVkX18DPwWauUzfxEpTqhT87GtiWfsiXk371GeoWmExPSDcAIcmNqdM8cAoAnXhDNGNnI5LfYePhyrrb8fk/hJdQrPayz2quqoebj/CI3Wed2i5y5oolI5Kok+/WoQv5ans7gAZdF1wA8fI+NFYe/V0xM0mBxUlmweOYQYUd1qGvQWexSN9WTpyn3vcfbaiouUzDdIzRe5zPtnIsWahl+D5THAefTluNJmtilQ1TDi1KZesUoKDZbO+l9srNe8yuHtzuegx9hu/TSnG+2l4ZeOfqkAJ6IF0OwT2TGh/Bu6LJF1FK6KY5bi0H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HPIxPP4dXIpXNKn3XhYSb+Tu1BIS2EfwcCH7tzz6GmKZndqBDAJTRycxJK0CdIiWGWYr4xtoZQXQgKdFilIXRVeOQPoprTApy0lMI3MjznXv4H 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/4/20 06:54, Liam R. Howlett 写道: > * Peng Zhang [230419 05:02]: >> 在 2023/4/14 22:57, Liam R. Howlett 写道: >>> Stop using maple state min/max for the range by passing through pointers >>> for those values. This will allow the maple state to be reused without >>> resetting. >>> >>> Also add some logic to fail out early on searching with invalid >>> arguments. >>> >>> Fixes: 54a611b60590 ("Maple Tree: add new data structure") >>> Signed-off-by: Liam R. Howlett >>> --- >>> lib/maple_tree.c | 27 +++++++++++++-------------- >>> 1 file changed, 13 insertions(+), 14 deletions(-) >>> >>> diff --git a/lib/maple_tree.c b/lib/maple_tree.c >>> index 4df6a0ce1c1b..ed350aa293b2 100644 >>> --- a/lib/maple_tree.c >>> +++ b/lib/maple_tree.c >>> @@ -4938,7 +4938,8 @@ static inline void *mas_prev_entry(struct ma_state *mas, unsigned long min) >>> * Return: True if found in a leaf, false otherwise. >>> * >>> */ >>> -static bool mas_rev_awalk(struct ma_state *mas, unsigned long size) >>> +static bool mas_rev_awalk(struct ma_state *mas, unsigned long size, >>> + unsigned long *gap_min, unsigned long *gap_max) >>> { >>> enum maple_type type = mte_node_type(mas->node); >>> struct maple_node *node = mas_mn(mas); >>> @@ -5003,8 +5004,8 @@ static bool mas_rev_awalk(struct ma_state *mas, unsigned long size) >>> if (unlikely(ma_is_leaf(type))) { >>> mas->offset = offset; >>> - mas->min = min; >>> - mas->max = min + gap - 1; >>> + *gap_min = min; >>> + *gap_max = min + gap - 1; >>> return true; >>> } >>> @@ -5280,6 +5281,9 @@ int mas_empty_area(struct ma_state *mas, unsigned long min, >>> unsigned long *pivots; >>> enum maple_type mt; >>> + if (min >= max) >> This can lead to errors, min == max is valid. >> I think it's better to change it to this: >> if (min > max || size == 0 || max - min < size - 1) > I am not sure what it means to search within a range of one. I guess > you would expect it to just return that value if it's empty? Yes, if min==max, and the value pointed to by this index is empty, we should return it. > > In any case, since we are dealing with pages of data for the VMAs, > having min == max really makes no sense, even with the subtraction of > one in the caller to reduce the max, the min and max should be at least > PAGE_SIZE - 1 apart here. > > I think you are right, and I think this needs to be looked at for the > tree on its own, but I don't think it's a problem for the VMA user. I'll > write a testcase and ensure a search for a single entry in a single > entry window works separately. Thanks for pointing this out. Yes, it's a problem with the tree itself. > >>> + return -EINVAL; >>> + >>> if (mas_is_start(mas)) >>> mas_start(mas); >>> else if (mas->offset >= 2) >>> @@ -5334,6 +5338,9 @@ int mas_empty_area_rev(struct ma_state *mas, unsigned long min, >>> { >>> struct maple_enode *last = mas->node; >>> + if (min >= max) >> ditto. > I'll do the search in both directions. Here is also the same problem with the tree itself as above. Maybe I didn't understand what you mean. I think the case of min==max should still be considered in mas_empty_area_rev(), because mas_empty_area_rev() is a separate interface. > >>> + return -EINVAL; >>> + >>> if (mas_is_start(mas)) { >>> mas_start(mas); >>> mas->offset = mas_data_end(mas); >>> @@ -5353,7 +5360,7 @@ int mas_empty_area_rev(struct ma_state *mas, unsigned long min, >>> mas->index = min; >>> mas->last = max; >>> - while (!mas_rev_awalk(mas, size)) { >>> + while (!mas_rev_awalk(mas, size, &min, &max)) { >>> if (last == mas->node) { >>> if (!mas_rewind_node(mas)) >>> return -EBUSY; >>> @@ -5368,17 +5375,9 @@ int mas_empty_area_rev(struct ma_state *mas, unsigned long min, >>> if (unlikely(mas->offset == MAPLE_NODE_SLOTS)) >>> return -EBUSY; >>> - /* >>> - * mas_rev_awalk() has set mas->min and mas->max to the gap values. If >>> - * the maximum is outside the window we are searching, then use the last >>> - * location in the search. >>> - * mas->max and mas->min is the range of the gap. >>> - * mas->index and mas->last are currently set to the search range. >>> - */ >>> - >>> /* Trim the upper limit to the max. */ >>> - if (mas->max <= mas->last) >>> - mas->last = mas->max; >>> + if (max <= mas->last) >>> + mas->last = max; >> We can get max as follows, without using pointers to track min, max in >> mas_rev_awalk(). >> >> mt = mte_node_type(mas->node); pivots = ma_pivots(mas_mn(mas), mt); max = >> mas_logical_pivot(mas, pivots, mas->offset, mt); > Yes, but why would we do this? We have done all this work already in > mas_rev_awalk(), and we have to do it there to get the offset in the > first place. Yes, both methods will work. > >> if (max < mas->last) /* The equal sign here can be removed */ > Thanks. I'll keep this in mind when I revisit the function. I don't > want to re-spin the patch for this alone. > >> mas->last = max; >> >>> mas->index = mas->last - size + 1; >>> return 0;