Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp239990rdh; Mon, 18 Dec 2023 18:34:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhPA9B4UgZk4ENeH/BaX/5zl7EKR3uZ/mxIn2VuDiPCuBPq8t5D+8GiL+0H9wr89ep+NJj X-Received: by 2002:ac8:7e88:0:b0:423:8e47:7236 with SMTP id w8-20020ac87e88000000b004238e477236mr28354641qtj.41.1702953294209; Mon, 18 Dec 2023 18:34:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702953294; cv=none; d=google.com; s=arc-20160816; b=NFmV0CPzp5vS7tBKqZFGJ680bHnFymScNN9kJ2IVRxuKlXbHTd+gPPI2Ql+YMxg0AU B4/L/YX6t98iUW1sz4oI82Wgkis8LJqadLG85hTHkEv6gs3sMzoSBepJnirbCzbP4sCB FLCN0dTu0BOcXtRUgtxyQo+yYiW5gnJXD41gk1j0F2nuE++48DBuoO/mhbWHsXyDltT0 bZJ15P91kSdzPXCZ54ZzkS/7Ez46/RckrV8YSWnTsHnYi8iSvyskQ5yCVHExwQ4X+Rnc X055MF9jqPs3T9Q+onsAIF9kzDs+MIUqbOzS12lH2Qk+Jy0WkcFsFMniCbATuVHngg1p VM+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:cc:references:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=D9QkIhhrk9atF5NzOy+uO1AzHmVd/CKbg5xM+XgezA8=; fh=OF5G+2TWKTt4uhtthiv1fKNOh/nxlxwkyvBuum6WbbQ=; b=tBh1ri/dwvx/9WECmIo+RRBl9OO+hUjw9LxnG3VlJWRaki3R9lBu1bPJCt+YnUSjRj 42h7VGhQg9TJcLjFO1Qer/t4eMLXWPzTjIMLJD4xhnH4lE97tmhwiknyT5kBxOnVMpfe qlgWkVKIp/1Vt/zAqn6B0WwEk6JM0ixsTYiTQ1k+uyQ0NZ9GZFrcHDVZgxe8qqGHYvyL pILcaO/4+vjX9vs3c+RmSVNDxCa47uy5L1I9C8BHRZMuhV4fMogN1foSco/NS14KVJoa 2D+FmEv8E0+7kBhcdta/hj3uuA6pGNBJvvSYr0JBfp93I0uzXnSCA7l4f3Tqf+MbkUob 3yuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Bq5G6vTX; spf=pass (google.com: domain of linux-kernel+bounces-4606-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4606-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id eq20-20020a05622a5e1400b0042586ba8fdbsi27676369qtb.257.2023.12.18.18.34.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 18:34:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4606-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Bq5G6vTX; spf=pass (google.com: domain of linux-kernel+bounces-4606-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4606-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DD6CE1C2156F for ; Tue, 19 Dec 2023 02:34:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C40076FAD; Tue, 19 Dec 2023 02:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="Bq5G6vTX" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A35A4C8A for ; Tue, 19 Dec 2023 02:34:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-42778277d9aso846211cf.1 for ; Mon, 18 Dec 2023 18:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1702953282; x=1703558082; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:cc:references:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=D9QkIhhrk9atF5NzOy+uO1AzHmVd/CKbg5xM+XgezA8=; b=Bq5G6vTX7AycPA46eJnEM4NUP/4HEhiaK6kq19V/+8BxJido1YAqNmCyZKiX6mli7r QOQmIINFqvmqZ3ZtnyBJd3mwQkZ1cXkUIrvepJ+ElL6N0PoQQe03PhIpSZMUH1IVJoAr LkgSGriQkYrOat2c5yhYFNCbjW6SOi2EYcR6Ke0ZMCRZQ1SU3itAoGnA5AShqi4TFo+i MfwXxhc0w5YYsKFApu9chd6c4ZhUK4I8NHhfUqlvgPWtoramXoY2eBN80WRaLi0MNS4O UJxtBK7hRatrzvTTPeItWCKT1nqnWkbb2Rkgtmq8V/V3Mn83lGq9ptutCbNDc6CMvlOb 11rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702953282; x=1703558082; h=content-transfer-encoding:in-reply-to:from:cc:references:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=D9QkIhhrk9atF5NzOy+uO1AzHmVd/CKbg5xM+XgezA8=; b=gEGz//7374XMu5AgUWnJNBYtYdwtsIxniXqU34E3MqUm4IXqvy09N0e9wJOcUzVZ6Q JgZN0jlUz5o4Z6K4nuw+uI1ixAOpTQ5R9tndN9R8ceoH5Gz0B0BmIaxiYqxfuqNj0OGx Kygz7qvt7OELnwcpkdp5y4eBfGOnF3HaYVSQn71mgS3/BtD4I+kIOiayclyYQ3r+y8UE EQCxtYY1MlglP3+QWGVh8u+9+nXMwynUaXxIj73BxJ71uG67+W4WH0xgRI4XQeA8N4V2 EX6bv5ndxh1gOx0wjQCerJTO4Bgp99VMJCnBPMMyaUOlNchnMYJVaxtOC8ZZ4Bv5G+Qm D04Q== X-Gm-Message-State: AOJu0YwHFRhobQDnXLCjdHYYDaWsQz3vCKGFznVyrIm8OBChrZq9MJ0a vFHBXGeOpOUss3fptRr8XMM1ZQ== X-Received: by 2002:ac8:5790:0:b0:425:8637:f81a with SMTP id v16-20020ac85790000000b004258637f81amr22848990qta.71.1702953282222; Mon, 18 Dec 2023 18:34:42 -0800 (PST) Received: from [10.84.146.214] ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id qc12-20020a17090b288c00b0028b6f522fedsm252431pjb.43.2023.12.18.18.34.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Dec 2023 18:34:41 -0800 (PST) Message-ID: <00ffc2e3-446b-473e-89b9-a859f36e43dd@bytedance.com> Date: Tue, 19 Dec 2023 10:34:36 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] maple_tree: Avoid checking other gaps after getting the largest gap To: "Liam R. Howlett" References: <20231215074632.82045-1-zhangpeng.00@bytedance.com> <20231218202014.mpotsekdkszasn4t@revolver> <20231218202845.buffbdq3vhpiv2py@revolver> Cc: maple-tree@lists.infradead.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peng Zhang From: Peng Zhang In-Reply-To: <20231218202845.buffbdq3vhpiv2py@revolver> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2023/12/19 04:28, Liam R. Howlett 写道: > * Liam R. Howlett [231218 15:20]: >> * Peng Zhang [231215 02:46]: >>> The last range stored in maple tree is typically quite large. By >>> checking if it exceeds the sum of the remaining ranges in that node, it >>> is possible to avoid checking all other gaps. >>> >>> Running the maple tree test suite in user mode almost always results in >>> a near 100% hit rate for this optimization. >> >> This should only be triggered for right-most nodes and root though, >> correct (mas->max == ULONG_MAX from just before this)? Yes, only for right-most nodes and root. >> >> I wonder if it's worth special case checking the first gap if the node >> min is 0 as well. Might be worth looking at, but this patch is >> certainly worth doing. > > Actually, not just when the min is 0, we have a special case close to > here for slot 0 so we could just check the same sort of thing there. I think that the first slot in a node does not have any special significance. It has a lower probability of being the largest gap, so it may not be worth considering. > >> >>> >>> Signed-off-by: Peng Zhang >> >> Reviewed-by: Liam R. Howlett >> >>> --- >>> lib/maple_tree.c | 3 +++ >>> 1 file changed, 3 insertions(+) >>> >>> diff --git a/lib/maple_tree.c b/lib/maple_tree.c >>> index c9a970ea20dd..6f241bb38799 100644 >>> --- a/lib/maple_tree.c >>> +++ b/lib/maple_tree.c >>> @@ -1518,6 +1518,9 @@ static unsigned long mas_leaf_max_gap(struct ma_state *mas) >>> gap = ULONG_MAX - pivots[max_piv]; >>> if (gap > max_gap) >>> max_gap = gap; >>> + >>> + if (max_gap > pivots[max_piv] - mas->min) >>> + return max_gap; >>> } >>> >>> for (; i <= max_piv; i++) { >>> -- >>> 2.20.1 >>> >