From patchwork Mon May 22 05:06:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 97025 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1216087vqo; Sun, 21 May 2023 22:18:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5gK5BuIgZfaXPTORBz6MfqWum7bpEfrPkfhpJLpohkDwPMb8AxIPgxLbrEFWEn2h8L6Hf9 X-Received: by 2002:a17:903:11cd:b0:1a6:84be:a08f with SMTP id q13-20020a17090311cd00b001a684bea08fmr10318876plh.64.1684732686119; Sun, 21 May 2023 22:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684732686; cv=none; d=google.com; s=arc-20160816; b=kwAJOY+CQmQdiQGMJ0SJ3yDCYtp98lhA5A7neplQVZ1wRiXi+RSD/MmR69YL5b8sdn mniZTkhKkW8vWo4XiMQ18yQOwDjLdShFowpJH+pDSExZzjvGNWeVwr+e+YiJNVlOMOf2 C0Qhx5l+qnzys4XJjG4Gl1jvSk8WO1jW2quOLNVISwYAFTfVbG5rQ07e7gXvs+Ng+YQY sNuG1aPZO9w55j6Uqg8KWiBZ6SE+P9ypPlYaC0gFV7r0YFLnVVIaawavHsloqDOChMvN k8ffOtwcpjtC0cwWFavXnQKyniTeoTobIKNkHSTH4QS3CnbFnNDHwAv0ehbjIxAm4oxh CRYQ== 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=BT/SFNbyjqRQKVOJvWMUTBqOO8oBgaqMrnpmlnOChNs=; b=yWc6ADRkwHaiMXPR+HPsrNXVYT/tHvCIXtGhSGZBdgZkGhlwVy30LCObhOyUJc1FeH qAy8SSAd0KkPRWgxFZIrYhem88cT8a+Z8MqlVArxzsKalf5EzdOI9t5XK3yc6HzQVOay s1VWJKs+XS2vrDr/Q6TBrpuNNC3ekSmP/beEm0G1JxLgZmpGaKrZB7j8Dbe8/E3C5UdV E+ksW3W0AY8PAl8Yjrnqi2AatN52BHSm5YZOuru+RPBt+9qoEEzxYAQWgciLB5qpD3/a 86tLCGhm1bumXHWnypXmPhwBhJBCxLVFIBedEbnaTtg+LmgpYLm6u1WvwmAGe4xCLbLV aL4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=EKjJchlG; 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 17-20020a170902ee5100b001a1a0db7f61si3995984plo.336.2023.05.21.22.17.53; Sun, 21 May 2023 22:18:06 -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=EKjJchlG; 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 S231840AbjEVFID (ORCPT + 99 others); Mon, 22 May 2023 01:08:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231783AbjEVFHv (ORCPT ); Mon, 22 May 2023 01:07:51 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF050A1 for ; Sun, 21 May 2023 22:07:30 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-64d2da69fdfso3786458b3a.0 for ; Sun, 21 May 2023 22:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732050; x=1687324050; 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=BT/SFNbyjqRQKVOJvWMUTBqOO8oBgaqMrnpmlnOChNs=; b=EKjJchlGDXRmxJY8egKTtCPHJW2FBKY8xN7qIIKeMpGB4j4yfs4iePqfPdOGDGS203 IQjvd34wUy4iqm1NNQJMsANpzDUtvuiVQo71ID6Ql5b/ZD31hFk8zHJpgjT9hmu5H5CG W8AKwWnNxPTTL+axxU+uEI/qffJlMjhfvrBTBD4nxKkPe9Lqh0j9uCLHAV37edea/+S6 c/7Hxz7fmZF9O9S2PREteryTTvvviwB/5gf/KOkvxJ/j1jRMaiNomC+EdpaWZVIcIXEF ezrPNKmy3LltEsCoP28TpF/5IGnfNZZB7VItCs35pXc12CfQgdA9uAdfhOYdExojYMPD ahkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732050; x=1687324050; 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=BT/SFNbyjqRQKVOJvWMUTBqOO8oBgaqMrnpmlnOChNs=; b=H/rKLtyDMzHw0jhZcjOKlOWWxbZreU4oOKccakFV6jjmrJx86J/EFNmFl7dMnri2YA jDGicxy2R1wmD0ATZT0rX+ChC5xwkg24of1PtWtBI6F7aT351lkfVi0Tc+OQyyMf3w4e TJZ9DUkJhCUKjUUoAF7awpacK1dWbDQtNkUlKxCoXhKwptePZCvM/hVVKErQFLDkPtTC wjNQBk2o8W88WUuCtgVIzJwUY8a6JpCIrKNEADP22e2fiv3NMs2mjcJMwBz8gLHtcbsa +GQ6WAm4t25A4xy69YVqvhO7VeKoG5J+9yGrmVeKqIjGX3J7ddK+fY3oLLTuE2XhiT3B aRRg== X-Gm-Message-State: AC+VfDzUO4n/on0GCu6ZroYNaJW8r3uc/uBepCKlaIUPXP2iaumOpfNt NAEblzfKwF0jX2DVAiWtJcl9RQ== X-Received: by 2002:a05:6a00:2185:b0:64d:46b2:9a58 with SMTP id h5-20020a056a00218500b0064d46b29a58mr7924134pfi.26.1684732050365; Sun, 21 May 2023 22:07:30 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id t10-20020a62ea0a000000b0063b5776b073sm3247519pfh.117.2023.05.21.22.07.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:30 -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 v3 04/10] maple_tree: Simplify mas_is_span_wr() Date: Mon, 22 May 2023 13:06:50 +0800 Message-Id: <20230522050656.96215-5-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230522050656.96215-1-zhangpeng.00@bytedance.com> References: <20230522050656.96215-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_PASS,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?1766570260875036272?= X-GMAIL-MSGID: =?utf-8?q?1766570260875036272?= Make the code for detecting spanning writes more concise. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 3fe6a6685384..c47af84047a4 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3728,43 +3728,32 @@ 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 this is not leaf node, detect spanning store wr walk. */ - 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; }