From patchwork Wed May 17 08:58:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 95118 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp992481vqo; Wed, 17 May 2023 02:21:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7VMLasVFJcfBU/kWnNkgMza38F9+vt1Pjk+dsNTeSQWKEG++GnuDS7FHyB8y3fZytsIeJk X-Received: by 2002:a05:6a00:2313:b0:640:f313:efba with SMTP id h19-20020a056a00231300b00640f313efbamr116258pfh.19.1684315281341; Wed, 17 May 2023 02:21:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684315281; cv=none; d=google.com; s=arc-20160816; b=WnaDeceXEEt8T9U3pmwbtOj7MqE+Iz8NjpmlZgXx9Rv3MOx5yIyjRnbEbLSlds0j/8 zzdVDPYMCx/HAxStYKPtmzRanniph4ZTF7y8/vQXMi7irZhp4FSZqZ5CzvdbCplOrrYF Y0vUeg70BT/f4T4o+iYWS58FOL4ZckTMjydRTYSmMFaRdn0k1nZ5eejaorczHCyw7KAa lkMhYpTdG3IhojXmIETKrp6YcfjSMaQcjq5cswh4GpbbWaAoQ7Sz7fsHh5JW2X+GkMzq AKOjTOKBiJGUKJpppXSQYJzszCHZ5qYQiJUkqGudQDcD/WZ4+PNn5dhV9RxFozDzbjxU EHkw== 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=PgePm/CbmI9b6FDUeL4Fm0Rwlug6tP8O/eeOWJHUuog=; b=wbwa9shBNPcalt6WmwhqHNO4oeU2Vmyk6U2GwrdNRdxm1G1u6cuxZqj37j9PGF5AQY 2SRPFKUZnsui0T31yDF6tc3IMxZtnwm6J4x0jYU71FK6tJDEUvYsik1bEE79X+K8NCo2 ssPYHEM7+qDihANEYBYiji8FM+xNojOYVqowTLgw9dPJNuMKz3VVFwbJH4uKBXDtA7kE e9FH32voVt5mGWYB7eBR5JV/oqGTIMFjlsqWUeH2k4zLqB5JUdbvJBxrQwHlf1LO0rfE bg4cvKMSsQOxMuq/xIQBOpQJlybxG+8iVxQBWxPE/KB0p4YDKCO7QxtLyl/Zy1KSW6iR uStw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=CweT36Vd; 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 z25-20020aa79599000000b00643bb2643f5si21554702pfj.124.2023.05.17.02.21.07; Wed, 17 May 2023 02:21:21 -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=CweT36Vd; 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 S231244AbjEQI7h (ORCPT + 99 others); Wed, 17 May 2023 04:59:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231169AbjEQI7Z (ORCPT ); Wed, 17 May 2023 04:59:25 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41DB730DE for ; Wed, 17 May 2023 01:58:58 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-5304913530fso446405a12.0 for ; Wed, 17 May 2023 01:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684313937; x=1686905937; 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=PgePm/CbmI9b6FDUeL4Fm0Rwlug6tP8O/eeOWJHUuog=; b=CweT36VdUJkzd7EgyQjEpA/g6MONV8fPH2+11DoRZ4gl9z4pn4gx0f5yRC38Oo0kxK /hOZIMttxfmQcLJcRE12mcyOso3iB19zL2YRd6wnP2BIrfQ9RGYC/EvLPmu6VhcdRlST sb8J/NRQg37aubTJbQd4RYW/oGlOyZowBikpiRraOyZTAleG3Aei4bfYFIuWCbcYacJi n3z9EzW4KLf5MngHWtxR8texHVwmwCRUn05aw/7+E6mi4DaBv41SUTLcNOJDhAdcS5Ff rxYgtd5EXyH9Q96Fede6UlmrE+iWdPMfwBb+zROOYYpAeztuNSrfs/mZl23iOCt9k+oc YO0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684313937; x=1686905937; 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=PgePm/CbmI9b6FDUeL4Fm0Rwlug6tP8O/eeOWJHUuog=; b=aupssNgSnE5HI5440PGZ+pVTBtjHaw9KFNlkURjYAv4WooeoCVxvTkmYb30AST6ouQ YT37GMhfZrgXSAqOZp5VvEKHgfaQP/nMGQILGLbyvdNrlMPuOkvVQuTHmPtijWKBxMDp jSXgbgyfocIjU/dX6PTW6KheGqyeV7UDhV9cGGGJj8B67ySCJSHiqj45Rok3Kx9bDJs4 ihGgkpgif49G/Y067GybgwxcWxk2zfUuElHyMOwf5vDs6POez7o/J14sk4ljgMrWJBrt l6mk5GaPtTe9VUqyP6QVNnKVMc/lvXKy+fgdmGRUJwrBvzwLcxBlGa71a5Di2q84lveI +/WA== X-Gm-Message-State: AC+VfDyzXgMTBiz0NPRpaJsI62PqRTnRLhZCzuhCtmu1//OLCNWjLbBm xpSgV3LdRdQQtl2IdsEgIBsLTw== X-Received: by 2002:a05:6a20:a10d:b0:101:4d10:e40a with SMTP id q13-20020a056a20a10d00b001014d10e40amr37103525pzk.12.1684313937698; Wed, 17 May 2023 01:58:57 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id m18-20020a63ed52000000b0052c9d1533b6sm15056765pgk.56.2023.05.17.01.58.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 May 2023 01:58:57 -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 v2 04/10] maple_tree: Simplify mas_is_span_wr() Date: Wed, 17 May 2023 16:58:03 +0800 Message-Id: <20230517085809.86522-5-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230517085809.86522-1-zhangpeng.00@bytedance.com> References: <20230517085809.86522-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,URIBL_BLOCKED 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?1766132580501085193?= X-GMAIL-MSGID: =?utf-8?q?1766132580501085193?= Make the code for detecting spanning writes more concise. Signed-off-by: Peng Zhang --- lib/maple_tree.c | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index bec9906b0c8c..82dccc660889 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3728,43 +3728,29 @@ 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 (last < max) - return false; - - /* Writes to the end of the node but not null. */ - if ((last == max) && entry) - return false; - + if (ma_is_leaf(type)) + max = wr_mas->mas->max; + if (last < max) { + /* Contained in this pivot or this leaf node */ + return false; + } else 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; }