From patchwork Wed May 24 03:12:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 98262 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2567891vqo; Tue, 23 May 2023 20:26:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4nPTEFuIP2RQLvUWmQ/BWuyyjITioNIR7FCYNmuTPM005T1oGH6AlItsdX/aI6v8o8kgk0 X-Received: by 2002:a17:90a:1548:b0:24b:52cb:9a31 with SMTP id y8-20020a17090a154800b0024b52cb9a31mr20868815pja.22.1684898765047; Tue, 23 May 2023 20:26:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684898765; cv=none; d=google.com; s=arc-20160816; b=r8ipghVeutHISIf7tJwzpeYORN8mZ2SSZqGzP9WlIsAuSBGI3yHQiyAPWe1+jYCA6U cVf2PEz2g/MGES7wb8TflmG4/mnCCJF/JXwEroej0J72fO4K+6dX7BN8Fvktw+FI8UzQ LZYthtX7YR/FfCRp5rwS8lnTQ8MKFZXF/6Jh2WbLre7VOiUM5N8t5mdXmIn5ZyGk3wqR 82cFCbhHTABeyrQ+STxPs37MAaqiXqrKlekfWoLmeKkd697NvF8JJtr1ZWMFcHkDfnQ3 vFwxPhqdg0PjJ199YwQvFjT8FtZC51JlFP3k09Mzyfyp2Y4F6VDkzuMK1EZRppOAfkbe UMmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=E5ruzeEGnj5CNT1/L3jtI3wslKiej4m4uvmLFSF+fv0=; b=FfpwFehF9SHgxli0SPeajuBtJ9eyt9PrHhsxSSTthBAqXVwCp3uaLjqxFMPIoA1Dzq ol8pHtBflTco0PVkt6kPBDbHhuRWEuPZ2HJPuEIIdBwoSQYgPXW0Oi9kjE3pdtxZq2eR Z8rGCwsprWcSnO+J1gtB7/g41F8IPjd4VJTha4E9mZ7Dfpd68RyQmf/SnNBqXLZdfD/N JP9kqCB8huoa/o+9EjsNCDhKQtOsokW4dek8ax6LzwTm41K8WugCfw3sBpLiBU0GGWln 8fL0peY5kyTNxpsbfBXlhVHuNLP7WSMko09xqKXEHCQpAZGak8iqn6yX4AsodVOsa+hJ 2tUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="MAXMrwd/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bo24-20020a17090b091800b0023fb875a929si489060pjb.106.2023.05.23.20.25.51; Tue, 23 May 2023 20:26:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="MAXMrwd/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239359AbjEXDOZ (ORCPT + 99 others); Tue, 23 May 2023 23:14:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239092AbjEXDNx (ORCPT ); Tue, 23 May 2023 23:13:53 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28F241A8 for ; Tue, 23 May 2023 20:13:25 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1ae507af2e5so5242605ad.1 for ; Tue, 23 May 2023 20:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684898004; x=1687490004; 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=E5ruzeEGnj5CNT1/L3jtI3wslKiej4m4uvmLFSF+fv0=; b=MAXMrwd/Xszur0x1fVAw7betXZi6Nv6iEeLRVE5rWFKAKqojhanpmq36+yY3jJQzsO M9EaO7RCl07OPXG4T0XWZ9VSsKYxu0A23zt5ExwuJrHR4zwdz4j0AmGa1VSOUMO6wVYw qbhvNZyU6dI9n7coOrUlXhim1BD85Jo0/sUOOUpXURBnyIkhz77RCwKkEwgBBXh8yi4h lupqDHDCc8iRhYj0YQ6830133yOLFDVOMIx7nBBQEQIABrD38VhOK6s7jpcSWBsQBTYP IV1HaE09ZjaHvHuTj90fgQdS2QStLY/pP/3jhoEO7eVxczLOyNTW1OWsR4ZkoGp1yHNJ r9VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684898004; x=1687490004; 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=E5ruzeEGnj5CNT1/L3jtI3wslKiej4m4uvmLFSF+fv0=; b=YeVJfpPONlXVggjy3g/CYnrqSQb+3CSAVWNzRfrInqiGhzURPaPXoEvVqF0PVsEEzE yz2EYT1ycmvd/i+sYpDfdBAgXRt4UBw6AHDo69/2Df3ohrmuA8jtXiuztrzICdMaYg6u BSI7/Fq+h1/QQleGdLaxjxLRoPRYtEDH30kTvBaKRn9BN5KeIIWuXNE7orbRDo3zuqBf ole5ekEAMWu+iwaARNEWwNTap4klz53/kWLqFxEZ8hK5yKeP7X3du4itoGLNW0P1k+Gw UUtGfGUNqG6vW5VjNEnXfz3Gskot8KH6OmJl7ZaqLFjxjlxddPYllvNryTqlTKIA7lfX FbAA== X-Gm-Message-State: AC+VfDxdAK16IVcw7d32HVSBYEmNtn3GGvQI0RFwDjdhLN1lxNEy1/Rz pAMUonppNFm6GWRPyMtuhaXscWZGIlsxmYl52aY= X-Received: by 2002:a17:903:8c4:b0:1ac:b03c:a58e with SMTP id lk4-20020a17090308c400b001acb03ca58emr20956735plb.25.1684898004536; Tue, 23 May 2023 20:13:24 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id i4-20020a17090332c400b001ab061e352bsm7480769plr.195.2023.05.23.20.13.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 23 May 2023 20:13:24 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v4 04/10] maple_tree: Simplify mas_is_span_wr() Date: Wed, 24 May 2023 11:12:41 +0800 Message-Id: <20230524031247.65949-5-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230524031247.65949-1-zhangpeng.00@bytedance.com> References: <20230524031247.65949-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766744407225390054?= X-GMAIL-MSGID: =?utf-8?q?1766744407225390054?= Make the code for detecting spanning writes more concise. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 3fe6a6685384..41a105e76e22 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3728,43 +3728,31 @@ static inline void mas_store_root(struct ma_state *mas, void *entry) */ static bool mas_is_span_wr(struct ma_wr_state *wr_mas) { - unsigned long max; + unsigned long max = wr_mas->r_max; unsigned long last = wr_mas->mas->last; - unsigned long piv = wr_mas->r_max; enum maple_type type = wr_mas->type; void *entry = wr_mas->entry; - /* Contained in this pivot */ - if (piv > last) + /* Contained in this pivot, fast path */ + if (last < max) return false; - max = wr_mas->mas->max; - if (unlikely(ma_is_leaf(type))) { - /* Fits in the node, but may span slots. */ + if (ma_is_leaf(type)) { + max = wr_mas->mas->max; if (last < max) return false; + } - /* Writes to the end of the node but not null. */ - if ((last == max) && entry) - return false; - + if (last == max) { /* - * Writing ULONG_MAX is not a spanning write regardless of the - * value being written as long as the range fits in the node. + * The last entry of leaf node cannot be NULL unless it is the + * rightmost node (writing ULONG_MAX), otherwise it spans slots. */ - if ((last == ULONG_MAX) && (last == max)) - return false; - } else if (piv == last) { - if (entry) - return false; - - /* Detect spanning store wr walk */ - if (last == ULONG_MAX) + if (entry || last == ULONG_MAX) return false; } - trace_ma_write(__func__, wr_mas->mas, piv, entry); - + trace_ma_write(__func__, wr_mas->mas, wr_mas->r_max, entry); return true; }