From patchwork Mon May 22 05:06:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 97020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1213683vqo; Sun, 21 May 2023 22:11:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7w1Xr/H2QT5vt8ZE3RE0Qilc/DS4HJs8UheKgjvDHhuYXPX0uXtEPOuumYNNVXp4iNsT4N X-Received: by 2002:a05:6a00:134c:b0:64d:2b06:5949 with SMTP id k12-20020a056a00134c00b0064d2b065949mr13259679pfu.8.1684732275614; Sun, 21 May 2023 22:11:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684732275; cv=none; d=google.com; s=arc-20160816; b=yc2WJBrhErAwnuBEbGIPf0snDj43mZC7vpM6bqwgROWJR7/+cqcDeewplE+/NWfUrd KHvK3ywDUAfKZw7jLNnPUv1vXEiSZ/qJ5PRdL5+ZtBc9cBzYAivl1goOYGLyfRZIMJmv mHZJJovqMXyh/MEnYlSikY9nGrWpc3h3tRHPl1tW1rfYFkgskA97704VIm5CNPqp1k0T yO650lXSFsDRNSKQH+4GX0j+3cc4QjsZj40v/+6NO6sKq7EZoGMSPNdSPMJwYIt5OOaJ UyHy4L01zdqvcz+P+xgPSGekO3mvNjLJLqBrcFiOHFGBRHpJILHSRqCVvZQ6EfVY2TjX Rghw== 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=ryAjJK/jvO3d1/ZbH/fm/OkRmr2azDVw5I6QoB1NED8=; b=FbMExNbP/u4Kkp3IeAlmCsc6MqCJDdhZYvY+qkvSh4nYD+/GkxE/Brrs3SLHIoPuQi Ae7Rh9k9zK1isMoeytntjivSCJBrY7FKCl8f49vxW2k0WAnZtRuFTKu7381atKI4Ci1D MtCg03DrWWt7BBg6iyW3PoFUg3Sl9pkES1fBLVotNsKGi78P5WdLfM9bxuzUMW8Wxnk3 khrjfKsQqyQFewU+IR5b2OoXz9S2FirwdVqWm/fxULX6/WbBk/rSxhHzLiZ8tsm4JlCl lmKuWnf+5AgapNSXbyTKG4gLSD0oiV+kyT+p+7LV/iTGjKObd+Bo7zzPaAlJ790hXvVl n4Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=E+sf9AoJ; 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 f9-20020aa79689000000b006452ad45992si4089157pfk.3.2023.05.21.22.11.03; Sun, 21 May 2023 22:11:15 -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=E+sf9AoJ; 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 S231716AbjEVFHZ (ORCPT + 99 others); Mon, 22 May 2023 01:07:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbjEVFHW (ORCPT ); Mon, 22 May 2023 01:07:22 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4103B92 for ; Sun, 21 May 2023 22:07:21 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-64d18d772bdso4779279b3a.3 for ; Sun, 21 May 2023 22:07:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732041; x=1687324041; 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=ryAjJK/jvO3d1/ZbH/fm/OkRmr2azDVw5I6QoB1NED8=; b=E+sf9AoJVl+JV6FsfkR4Ym5XfHy/qlWHgn7H3ghjaIqtwrmDk4FnwTgtCboieHks5a 7Xju63Rz4/hQXtTjifn3Q9wRx22XGUz+pCJWITfM6TaSYKsoLU1m7GIB/8cxEfraWRhS 8ce7qTdNdx0Rx5AX64dHcGo1GeiRMKueARhVfIFMquyHtvURi2LrwtmBx+f+ZN0H25Jn IR5e5SLGTGTpYPbpRZriNanszs4xQ2Sv8FTZCoWCx2LI56hrA+MREB3TjANB0qTaIm9G tPlFNj6QITqQQlWtPss9HM0QZsSkFNpWPI7R91rjhIRzTZw+TQz16JYxWv25eGrOJKY7 bY8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732041; x=1687324041; 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=ryAjJK/jvO3d1/ZbH/fm/OkRmr2azDVw5I6QoB1NED8=; b=RCIMWIQanMhBxLoFfdlRs8zUsn1UkmRFfDs118LbHTO3R9pLLEaI3m2ybO7gZmFzJa osF43nTUfViaV/VmIbd+BB+K9GaQM8zpRf3upgfwpZFsiZrkesD30Or0H8lZqL4ni6tp DCsLdqVaXhz06KzHDjH4syW8adAEPn1WyERmgWjs08aBQGQ2BEfnhwPpGvsuTOsFGcGI mRV+cZx+yrs6FBls0hE68PBVGR04NJuaLd2xn7j01ljtLMgAc0mbFPG3s/4ysAJdyDip DYQ2EVFg4xyrtU7wBYAjWEK6yRTW22Sqm864TPrvjXrsTZtaAvf3F67CO6AdrWed4xPD 0VWQ== X-Gm-Message-State: AC+VfDwZVtRviMV5YFnwbRC4fdc/b1T5cYoPleZE/yorgMIuH7j/qG9M Ky3AaDW68IKqpiRC3AMSiUJWog== X-Received: by 2002:a05:6a00:845:b0:634:7ba3:d140 with SMTP id q5-20020a056a00084500b006347ba3d140mr13038011pfk.15.1684732040942; Sun, 21 May 2023 22:07:20 -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.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:20 -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 01/10] maple_tree: Rework mtree_alloc_{range,rrange}() Date: Mon, 22 May 2023 13:06:47 +0800 Message-Id: <20230522050656.96215-2-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?1766569830563547605?= X-GMAIL-MSGID: =?utf-8?q?1766569830563547605?= Use mas_empty_area{_rev}() to refactor mtree_alloc_{range,rrange}() Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 57 +++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 4eb220008f72..96d102d60b4e 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -6493,31 +6493,33 @@ int mtree_alloc_range(struct maple_tree *mt, unsigned long *startp, { int ret = 0; - MA_STATE(mas, mt, min, min); + MA_STATE(mas, mt, 0, 0); if (!mt_is_alloc(mt)) return -EINVAL; if (WARN_ON_ONCE(mt_is_reserved(entry))) return -EINVAL; - if (min > max) - return -EINVAL; - - if (max < size) - return -EINVAL; - - if (!size) - return -EINVAL; - mtree_lock(mt); retry: - mas.offset = 0; - mas.index = min; - mas.last = max - size + 1; - ret = mas_alloc(&mas, entry, size, startp); + ret = mas_empty_area(&mas, min, max, size); + if (ret) + goto unlock; + + mas_insert(&mas, entry); + /* + * mas_nomem() may release the lock, causing the allocated area + * to be unavailable, so try to allocate a free area again. + */ if (mas_nomem(&mas, gfp)) goto retry; + if (mas_is_err(&mas)) + ret = xa_err(mas.node); + else + *startp = mas.index; + +unlock: mtree_unlock(mt); return ret; } @@ -6529,28 +6531,33 @@ int mtree_alloc_rrange(struct maple_tree *mt, unsigned long *startp, { int ret = 0; - MA_STATE(mas, mt, min, max - size + 1); + MA_STATE(mas, mt, 0, 0); if (!mt_is_alloc(mt)) return -EINVAL; if (WARN_ON_ONCE(mt_is_reserved(entry))) return -EINVAL; - if (min > max) - return -EINVAL; - - if (max < size - 1) - return -EINVAL; - - if (!size) - return -EINVAL; - mtree_lock(mt); retry: - ret = mas_rev_alloc(&mas, min, max, entry, size, startp); + ret = mas_empty_area_rev(&mas, min, max, size); + if (ret) + goto unlock; + + mas_insert(&mas, entry); + /* + * mas_nomem() may release the lock, causing the allocated area + * to be unavailable, so try to allocate a free area again. + */ if (mas_nomem(&mas, gfp)) goto retry; + if (mas_is_err(&mas)) + ret = xa_err(mas.node); + else + *startp = mas.index; + +unlock: mtree_unlock(mt); return ret; } From patchwork Mon May 22 05:06:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 97022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1214782vqo; Sun, 21 May 2023 22:14:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ey+D0v1A+S3FVBxzaCP0VVt3nQgX6s8PRIfyr5Tx/GIi8LUdYohbegL1rJ2jC448UzORC X-Received: by 2002:a17:902:d382:b0:19d:1bc1:ce22 with SMTP id e2-20020a170902d38200b0019d1bc1ce22mr9688114pld.5.1684732462164; Sun, 21 May 2023 22:14:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684732462; cv=none; d=google.com; s=arc-20160816; b=B4Yz/B7ASz8giaCNINdDG+d+ty+9aHogNCuH2XVAvArLcVuIMC0WsI6J0eLTFGytoB h0vAFE6GQs8NTVDvWMAKD3m+/jxzkjYau4nZJDS/cdRS9xer5QCdpdaad6XF3WII99/A 6EtabVq4V9X9GtLhFIK9t9NqQchcPlLQjsK5YhNWzUZ0mX/Tum5oYdSdOPU3FLPWukVS WmOzQoE6uqne7koKT5MVaV+xurrQxpcB66TwJm9wLBoqg8dl5coWZDzGkWMPksJMiqs8 6UJRz5garMN9Zm5B0AVj63LP/qa/9KD6OsO53030iRQhJlUpIg9jjW54fwgqmvrOvhDn tt0Q== 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=8amRkLtdnjVq9cbmGyv8etEjiXwBdz+ISKHsxqN16tA=; b=lmb3b73cxartTjpL5mjYAQJvViTjpxf0z4HC2Ld03So1lZntfqaWsrCazZ74FzKIBg 9PqwfXTpWXLN725FsIf8UAwXDrSJ1sejGNUneTxlryg9nsRRPfqXNvYh4T7ZT8VZqClT jjCIUS4K+u0Xg6NwU1PfswYk/4tPlI0i4N9vJDz4To3WjVp5cqwKsGcqWBYEhsBYP0kh s9WbZ4l7+ow2JRyaJSLNLkCMEcAc2TvijguqQi4B5fArR9EFqI04AguGHx7M+/EDd8mi BubsteIx4h+GGCz0Ev+dB27obOnPsOymgF0PaJuST5A1lLVcGxo9/FbB/QU1MYpSRt9E +tXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="GYE7/eh3"; 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 iz11-20020a170902ef8b00b001a980a2b405si3818517plb.471.2023.05.21.22.14.04; Sun, 21 May 2023 22:14:22 -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="GYE7/eh3"; 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 S231767AbjEVFHy (ORCPT + 99 others); Mon, 22 May 2023 01:07:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231734AbjEVFHr (ORCPT ); Mon, 22 May 2023 01:07:47 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A706592 for ; Sun, 21 May 2023 22:07:24 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-64d15660784so2906667b3a.0 for ; Sun, 21 May 2023 22:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732044; x=1687324044; 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=8amRkLtdnjVq9cbmGyv8etEjiXwBdz+ISKHsxqN16tA=; b=GYE7/eh3Hqti3Du8XPZUomicyjqafnfRSVXMJgGIMFX6+SBScSqdwET8DvURyQAI25 A2eaYMWJDwWyiQ/yLWt/12vUSj6bzkTk+pGFfX8gf+yVtmaOuB1FxffF70FUjmpqTzA9 lU0TUqzND5gyGUb0yKeIQJRajq4+VN2W1jz/CsH9wkCLeVYW5gqLkCAnJanNMSasF/uU O8hpWEr2WtH/xMH1UAsDv43QHtp1r+L/SgUI5S5gEN4rskUkm/mEGMOt2LBfYeUiKTBX sc9hVVsA3HUHuvjjFUGzixiTj+Q9J+BBY3yvg5bd5a9gEihrq+709FCyt5O91kotDEH2 G/6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732044; x=1687324044; 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=8amRkLtdnjVq9cbmGyv8etEjiXwBdz+ISKHsxqN16tA=; b=XbwQScZwzJwh82qLgsej/xfEWSsLpGngFOfZT4aX1vtnKdpLInjGZDn89/tPW3qz0W 3YfIyHblBoV+4Xu5YhxGbuLBoI/90tbezdxi5+I1erB+LoQ9yac3dFOPffm1exx70Xbh nF2kL0reFrUe4RYjYYEJrpYxCmTBVRbC4AnY/nZQQlPT5/JYaiFfUHbgfNTW+n8RLCw9 DV0HNkcMomZUPy8XQJ8FD+f8G3JFXyuJ7bwCsuH3y3TVBsjg0/y2cxeQIwgPrhqUB2Z/ gtukROO+il16qoEb/lhhixlxZGJQ29FlwTRgXk671KQgMYKQfE9Rs0cKMTuydeUyS0e1 rzMg== X-Gm-Message-State: AC+VfDxtg1fDDCfJlGzgft5OuyknsgtVc5LLqQTMXyWN2dKrViz+bCMj TtzZOkUSP6aReJ/4D7Ps1zn7W4xWG/SjSdZSiSo= X-Received: by 2002:a05:6a00:1882:b0:64d:42cb:42af with SMTP id x2-20020a056a00188200b0064d42cb42afmr9286193pfh.4.1684732044137; Sun, 21 May 2023 22:07:24 -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.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:23 -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 02/10] maple_tree: Drop mas_{rev_}alloc() and mas_fill_gap() Date: Mon, 22 May 2023 13:06:48 +0800 Message-Id: <20230522050656.96215-3-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?1766570026161452597?= X-GMAIL-MSGID: =?utf-8?q?1766570026161452597?= mas_{rev_}alloc() and mas_fill_gap() are useless, delete them. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 108 ----------------------------------------------- 1 file changed, 108 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 96d102d60b4e..263bd0ccc31b 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5120,46 +5120,6 @@ static inline void mas_awalk(struct ma_state *mas, unsigned long size) } } -/* - * mas_fill_gap() - Fill a located gap with @entry. - * @mas: The maple state - * @entry: The value to store - * @slot: The offset into the node to store the @entry - * @size: The size of the entry - * @index: The start location - */ -static inline void mas_fill_gap(struct ma_state *mas, void *entry, - unsigned char slot, unsigned long size, unsigned long *index) -{ - MA_WR_STATE(wr_mas, mas, entry); - unsigned char pslot = mte_parent_slot(mas->node); - struct maple_enode *mn = mas->node; - unsigned long *pivots; - enum maple_type ptype; - /* - * mas->index is the start address for the search - * which may no longer be needed. - * mas->last is the end address for the search - */ - - *index = mas->index; - mas->last = mas->index + size - 1; - - /* - * It is possible that using mas->max and mas->min to correctly - * calculate the index and last will cause an issue in the gap - * calculation, so fix the ma_state here - */ - mas_ascend(mas); - ptype = mte_node_type(mas->node); - pivots = ma_pivots(mas_mn(mas), ptype); - mas->max = mas_safe_pivot(mas, pivots, pslot, ptype); - mas->min = mas_safe_min(mas, pivots, pslot); - mas->node = mn; - mas->offset = slot; - mas_wr_store_entry(&wr_mas); -} - /* * mas_sparse_area() - Internal function. Return upper or lower limit when * searching for a gap in an empty tree. @@ -5307,74 +5267,6 @@ int mas_empty_area_rev(struct ma_state *mas, unsigned long min, } EXPORT_SYMBOL_GPL(mas_empty_area_rev); -static inline int mas_alloc(struct ma_state *mas, void *entry, - unsigned long size, unsigned long *index) -{ - unsigned long min; - - mas_start(mas); - if (mas_is_none(mas) || mas_is_ptr(mas)) { - mas_root_expand(mas, entry); - if (mas_is_err(mas)) - return xa_err(mas->node); - - if (!mas->index) - return mas_pivot(mas, 0); - return mas_pivot(mas, 1); - } - - /* Must be walking a tree. */ - mas_awalk(mas, size); - if (mas_is_err(mas)) - return xa_err(mas->node); - - if (mas->offset == MAPLE_NODE_SLOTS) - goto no_gap; - - /* - * At this point, mas->node points to the right node and we have an - * offset that has a sufficient gap. - */ - min = mas->min; - if (mas->offset) - min = mas_pivot(mas, mas->offset - 1) + 1; - - if (mas_is_err(mas)) - return xa_err(mas->node); - - if (mas->index < min) - mas->index = min; - - mas_fill_gap(mas, entry, mas->offset, size, index); - return 0; - -no_gap: - return -EBUSY; -} - -static inline int mas_rev_alloc(struct ma_state *mas, unsigned long min, - unsigned long max, void *entry, - unsigned long size, unsigned long *index) -{ - int ret = 0; - - ret = mas_empty_area_rev(mas, min, max, size); - if (ret) - return ret; - - if (mas_is_err(mas)) - return xa_err(mas->node); - - if (mas->offset == MAPLE_NODE_SLOTS) - goto no_gap; - - mas_fill_gap(mas, entry, mas->offset, size, index); - return 0; - -no_gap: - return -EBUSY; -} - /* * mte_dead_leaves() - Mark all leaves of a node as dead. * @mas: The maple state From patchwork Mon May 22 05:06:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 97052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1229480vqo; Sun, 21 May 2023 22:56:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6OA80bP4ndnQLy/FJ2mEYWaPS8Y5HXncx0Ih/LAWiGV2d1m3uoBAFRg4IN/02pd4zu5oqo X-Received: by 2002:a05:6a00:8d1:b0:642:fbed:2808 with SMTP id s17-20020a056a0008d100b00642fbed2808mr12370517pfu.25.1684734975404; Sun, 21 May 2023 22:56:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684734975; cv=none; d=google.com; s=arc-20160816; b=OofhLZ5Z6YBR+ObxoRo0hRdMgGwVUprMiiZu77D4h0nJluKRkAb+GH+ERhcjz65Sb1 NxO5y0jEu2VK6219VdeZiN8abVXgqs16cX6dxF07UbEFn+65cKmvZEc76tws5Qlffxp5 5Vt4NK3z4p+m4F9A1zSz0MXjcg/0PvKWzbPj/k9EWdZvABZEh0F2LnRN+95Bf/HkB+jS QGDqHujMj0apW1BaWlVy6XAEqnIMBOI37+VgZyj+f32NFCd64K6ev0kv8RS2JfVBNiRY gH5UY8zyB7ZfZd4yXzDAymMsojQoA9gPmBT4xOiG/PvSicBonqxIhiBPeFA3VQhIUdpG euVw== 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=yWC57VvLqW+uV6e3VSW20kWo+uFlFhqhxKDmqi/M+s4=; b=cRuIlItizCid/Ed11ugVOaZp7ap44eVOUBz6CNndHKg3ffCB3Cgs57Tj3GjyfDFscn 4B6A5OE1Zd1y7np69ggO2Per2aRkaeLWksgB2Qj1AgbXHGRZn+MsM2+wkBQSuHSGSXMo fBFNc6HKzY7py5AL+DEiiRkdAQ0v9u8STWoWSXgTsCpYVxJMbP5MiXYzs7OZenfMUwLy Wj4vixlQ2fr21QkH9FeVQiqUNx9gu+EFuOx3xTXR9jiwU4qWSsPs5vXtvDIVwvO8Aoyz M7RyGlbUtJzIFGbdaSfOJROi6HnIK7w3DDY9DkHcwGwNCRdJE59+TdwBTPsU1FjV2fxw nesA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=EzLSK3cP; 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 q17-20020aa79831000000b0064388918719si4225575pfl.85.2023.05.21.22.56.00; Sun, 21 May 2023 22:56:15 -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=EzLSK3cP; 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 S231730AbjEVFHd (ORCPT + 99 others); Mon, 22 May 2023 01:07:33 -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 S231727AbjEVFH3 (ORCPT ); Mon, 22 May 2023 01:07:29 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0691F4 for ; Sun, 21 May 2023 22:07:27 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-64d577071a6so1521509b3a.1 for ; Sun, 21 May 2023 22:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732047; x=1687324047; 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=yWC57VvLqW+uV6e3VSW20kWo+uFlFhqhxKDmqi/M+s4=; b=EzLSK3cPy7whK/cuCX7ItKG6l3duMlUzxr2DN24N10lVm+CaqC7sQkl4JBdNua/aAQ zosKFg/rfFI7osQ8eZcIBIfKeDR03YZaXjE5O8+e2qadCDIp41XDnirHuK3FWoX8l3OU YcB4YJkxwNjDyYKJfPZHybJrX1aMBiy3UgCgsQoNlOLNB2szntp7ukZGP8Q+ZzNCsuPy V8JNyEch9NnjoH7EK7OtuSW0wVEcwlYQnqPEa9kzxzg0/vxd+qY1B24BapLesnKT1O6q iZbG3O4pP7gdt6Vx0E2R3HvXJKJDMX0BbBfYhgm7SDcOeyERTF0Kb1Cj892QnkPDOShu QbmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732047; x=1687324047; 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=yWC57VvLqW+uV6e3VSW20kWo+uFlFhqhxKDmqi/M+s4=; b=bNFcxqLOyjeI4enfRTfp5mFrFx2xOz2BDL0ukRFBmkN9svZ58tKM3KE4K4GoL4utIs /hZ2GKmlyWc0tsUMeNPW041CV2AIJ4ZnX6JAueqQjX8pzkqZ5XOpLfcwZSFwNufXNVsE 85kg57qEOs2GMMCkSF7LMKt7i/TqCBT+FLb069yqNLQmrRSK26FKYdZPiHPkZqqJTcEW PW99L4OYAYoTtbJrgI+D1Blbhjjbur1k5Xd3d9vrM4qGD6l5EuVBuUirFogNu2UhVWi3 oQ9ClJQkA3bHKJGpJFIPzX74OdgLCs1tVmwtZfFVsb6MSOrNhovuPYjsX7WPRIW5uXFt 5fjg== X-Gm-Message-State: AC+VfDwT4sRgsnxWZrjFEVRucm9c2Uq0Kl87OgPii8ldLUCCdW6kcx+Y 7mjO9G4pbXdIN6b30LUJxRALvA== X-Received: by 2002:a05:6a00:3924:b0:64d:5f1d:3d77 with SMTP id fh36-20020a056a00392400b0064d5f1d3d77mr4573175pfb.34.1684732047342; Sun, 21 May 2023 22:07:27 -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.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:27 -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 03/10] maple_tree: Fix the arguments to __must_hold() Date: Mon, 22 May 2023 13:06:49 +0800 Message-Id: <20230522050656.96215-4-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?1766572661204228647?= X-GMAIL-MSGID: =?utf-8?q?1766572661204228647?= Fix the arguments to __must_hold() to make sparse work. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 263bd0ccc31b..3fe6a6685384 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1752,7 +1752,7 @@ static inline void mas_adopt_children(struct ma_state *mas, * leave the node (true) and handle the adoption and free elsewhere. */ static inline void mas_replace(struct ma_state *mas, bool advanced) - __must_hold(mas->tree->lock) + __must_hold(mas->tree->ma_lock) { struct maple_node *mn = mas_mn(mas); struct maple_enode *old_enode; @@ -1792,7 +1792,7 @@ static inline void mas_replace(struct ma_state *mas, bool advanced) * @child: the maple state to store the child. */ static inline bool mas_new_child(struct ma_state *mas, struct ma_state *child) - __must_hold(mas->tree->lock) + __must_hold(mas->tree->ma_lock) { enum maple_type mt; unsigned char offset; @@ -6204,7 +6204,7 @@ EXPORT_SYMBOL_GPL(mas_erase); * Return: true on allocation, false otherwise. */ bool mas_nomem(struct ma_state *mas, gfp_t gfp) - __must_hold(mas->tree->lock) + __must_hold(mas->tree->ma_lock) { if (likely(mas->node != MA_ERROR(-ENOMEM))) { mas_destroy(mas); 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; } From patchwork Mon May 22 05:06:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 97033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1220655vqo; Sun, 21 May 2023 22:31:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5SG3Ho32McdOX1XUYVh/8IVQl5bWJjmpfdbjL32lVktAUPORlpFzmlpTH9uQXz/A0DAjlD X-Received: by 2002:a05:6a20:8f02:b0:105:dafa:feb3 with SMTP id b2-20020a056a208f0200b00105dafafeb3mr11317283pzk.61.1684733482134; Sun, 21 May 2023 22:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684733482; cv=none; d=google.com; s=arc-20160816; b=VG3NNt1KsfRwgDU0QfHMCubBdqzE8zv9UozktGvCiJo4a1pHe2DODQtxhytCbs23JE uq6gkOxP/Urc2SUz9seG1tBx8CCwttKF6n8vribNLJHTjJDScUAauePKwreIj9iQzQro zXA83y+gkUmwVLq9AVeJYGmr3K/nTUwhFD24JQ6XrI++eo2gGbuVDFT2ttCsb76Ngf+W OOUw+MKDepkLKOee0S5WjeY8W5XY3j19Cv3FTApPLSkVxh6mFJa5XQNGHXPidmBfdNMZ xs69VqYUibz/p9OpoRi1cZT4wRaV3BZaeFhUOi/REiVpUhVZYqJkBUaI5ylSQS90/P2i ygTQ== 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=eo5rcY2cJVWJgq5aXNebmW2HhW0q7JfmSI/nM1R46gk=; b=BuhS5sGdNyNxihMDjyHWs25sVyUloQAtbw/sPkhdfw9wbbh8vdRC5n9NEPyfbVgfZ8 ngI8YV1K+MwuNJh0wAjPqKBc7J+ggrCITY8Fy4tx4y2fC3q3RXZBIf0qTi9m9I/mlQyB frRrhe/1OsnG8wAjezK6lcSt5owzKXF6zNC2MYrpV02qyemubX3P1yCB4rNS9wNg2TMj PVCxPqWuOzX2FiAToHEbYFraBvuX6hH5XMBg6aLdgu3DH4YcFw1F5/emyYPRPhcreQdn UJ55iVWYVvg8FySOrbUDTkHDYEpzPaaifVtUwq0FWDWfft26c4dICG1LshXW2ngbXSBR Nm2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ZSCKQFXL; 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 nh7-20020a17090b364700b0024df18639f4si4036512pjb.72.2023.05.21.22.31.10; Sun, 21 May 2023 22:31:22 -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=ZSCKQFXL; 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 S231745AbjEVFHh (ORCPT + 99 others); Mon, 22 May 2023 01:07:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231727AbjEVFHf (ORCPT ); Mon, 22 May 2023 01:07:35 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D29EEE9 for ; Sun, 21 May 2023 22:07:33 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-64d1a0d640cso3003221b3a.1 for ; Sun, 21 May 2023 22:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732053; x=1687324053; 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=eo5rcY2cJVWJgq5aXNebmW2HhW0q7JfmSI/nM1R46gk=; b=ZSCKQFXLVBYNVkVOOzDNCt0Mcj4KMH0eT5hciFj/maxy7uR2Fkn3XI9lMlN5I5K2mq Gkw8OaXA1zC3gwyZmCX2kCRi6LHedI7vC7pGlQ/tq/vEkC3qx84ASPAf41r2VFRD1XBm Qq35xPIr91V1EpeXuEklHJyGwYOOSZuXcKpt7zcnKzZgmUmXG7hRA8dpYUo1ZjYK6p9J f/UBHZMxPM3XmWhjiUvQ3km319KaunvQEQg7Wos7iycBYkWIlOSSwDwri3+W/KsmllFu OfpLB1SibWVW3lTR6xYe6IJvXPIhv0Nt/Z5NcrMSHbdAEZqqBED9UAwJNrLOiZY7L84J F0vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732053; x=1687324053; 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=eo5rcY2cJVWJgq5aXNebmW2HhW0q7JfmSI/nM1R46gk=; b=dvjGWBmOdx7GKN0jq+dj5REHnAtalNx19fA7D26E5/id+Ie0+94eIkAPtl6KJduJCa U8Ez2cQ8tv9vUGno3RDq1VbsINYQ6GA+eQrrp0As3+KhZdYW/c6aRezHCJ7cbqrarqoV QtRkGTG2ElyP+B8OFpo+a4MmhajI6SU9A+N193802Yh4nteYHdAv+SqNrXI5pIl/F+qU lnqHqa27+rAuIt6P5ON0THSnWdHUN6ulWJqjALenIAVRlFFidqabDAu8Xu5vsG5j6Tuo /pCE+TX3pnQGcehkQmjqz39JXwO9SNeL+DMHVFV+n01n9UAZ2c2oQLyjQB3jlDcUVJml jVeg== X-Gm-Message-State: AC+VfDxC7wJ5ofwL1Td/pJKa7kH02/3wWn8+ZN2XXeDw5sQUY/QnsmHW bFYaqHSRvKB2x79KnmSD/DaUMw== X-Received: by 2002:a05:6a00:9a4:b0:64d:2e8a:4ccb with SMTP id u36-20020a056a0009a400b0064d2e8a4ccbmr13674329pfg.14.1684732053316; Sun, 21 May 2023 22:07:33 -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.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:33 -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 05/10] maple_tree: Make the code symmetrical in mas_wr_extend_null() Date: Mon, 22 May 2023 13:06:51 +0800 Message-Id: <20230522050656.96215-6-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?1766571095724190946?= X-GMAIL-MSGID: =?utf-8?q?1766571095724190946?= Just make the code symmetrical to improve readability. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index c47af84047a4..562507979a4b 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4265,19 +4265,21 @@ static inline void mas_wr_extend_null(struct ma_wr_state *wr_mas) { struct ma_state *mas = wr_mas->mas; - if (mas->last < wr_mas->end_piv && !wr_mas->slots[wr_mas->offset_end]) + if (!wr_mas->slots[wr_mas->offset_end]) { + /* If this one is null, the next and prev are not */ mas->last = wr_mas->end_piv; - - /* Check next slot(s) if we are overwriting the end */ - if ((mas->last == wr_mas->end_piv) && - (wr_mas->node_end != wr_mas->offset_end) && - !wr_mas->slots[wr_mas->offset_end + 1]) { - wr_mas->offset_end++; - if (wr_mas->offset_end == wr_mas->node_end) - mas->last = mas->max; - else - mas->last = wr_mas->pivots[wr_mas->offset_end]; - wr_mas->end_piv = mas->last; + } else { + /* Check next slot(s) if we are overwriting the end */ + if ((mas->last == wr_mas->end_piv) && + (wr_mas->node_end != wr_mas->offset_end) && + !wr_mas->slots[wr_mas->offset_end + 1]) { + wr_mas->offset_end++; + if (wr_mas->offset_end == wr_mas->node_end) + mas->last = mas->max; + else + mas->last = wr_mas->pivots[wr_mas->offset_end]; + wr_mas->end_piv = mas->last; + } } if (!wr_mas->content) { From patchwork Mon May 22 05:06:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 97021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1214658vqo; Sun, 21 May 2023 22:14:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6iUKbL4COt6S4ZK5CJCo2jrgaTtxyfHJdRSQ9qrVOe45yTQjZYN0NjCqnCbfX/6u/dLNGd X-Received: by 2002:a05:6a20:1442:b0:105:9ca9:56aa with SMTP id a2-20020a056a20144200b001059ca956aamr11104989pzi.0.1684732439672; Sun, 21 May 2023 22:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684732439; cv=none; d=google.com; s=arc-20160816; b=Jx7Ymr0C6F6UpI6SAZTftGUG6/5s5hWIPyK9Oy3jUdDonUFjBzrZXZDa6CyMjgdG65 k0rvxv+jIaia+sCbDMyxwPkBq3XuRgfaJCiUCg1ON8UM117Ngg1qHG2rtDQYWiMKGqLH 2l9dcGl3rnQ14pGE22/nQlyz0QH+NF2+TXBzMVQ3FAheRPVuoJjYpy0HAViAIBgCtKd+ SKXnhBUsMEB6aWDIC7ekOtU5hw//TM9Jmh5KOXVK5bQtAbemw1eNePER+AcnQXeQLVoD p8iY85lqeT7UF4mQyqXKsfKAjHb3+x2g9k0eobZ2KaFLuGmmXQWc0RGN5pohNpY+LG84 1Csw== 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=gZz+uQjmpOdIMxeiaJgwUz4BoyhUknFLXJa8Z3V7HsI=; b=HnJ5xFUPlbKrx3SQ8ydsZgfhvmW6QKCn3iU5s1Yzu3D4JcZHeBqv9DdSz8jmBoZXAG lmzxCLQkq2VCa/hoCCBRLiSjriQhGXcIKWZMLxPVVBY956IUTRcDMDzlr9JAG3aycX7T xasDsakfEifoEYj7r8AcrfRrlPRYVVhuKrw3hfvukW8fvnPOyd2I+pzHYE7Urlw7uEYO WcYAUeBy3XcCa8hLUZZwEWAELjyUM/ITZJRpcJI72juVVtLT1yqKWGQAiIuQPTkzTRd+ rRXQ62mTDaycyOMIN+4+Q/zq+ct4jWb0nI1gfUathZ9oMD/aaGVevv2RU1kwTJMuraFx Cg8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=jgMP8vdB; 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 f9-20020aa79689000000b006452ad45992si4089157pfk.3.2023.05.21.22.13.47; Sun, 21 May 2023 22:13:59 -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=jgMP8vdB; 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 S231854AbjEVFIJ (ORCPT + 99 others); Mon, 22 May 2023 01:08:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231396AbjEVFIC (ORCPT ); Mon, 22 May 2023 01:08:02 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A42E9115 for ; Sun, 21 May 2023 22:07:36 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-64d18d772bdso4779421b3a.3 for ; Sun, 21 May 2023 22:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732056; x=1687324056; 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=gZz+uQjmpOdIMxeiaJgwUz4BoyhUknFLXJa8Z3V7HsI=; b=jgMP8vdBmcOPewxDkJjBZQcf60lixgiNyhCEEOeGGUIpPNqCfsdnSzzeIL2MICM/0R dmJuRkdPDnNnSfKA/dr8EkxfvxBIxP3R4j2iiulIlRGcVDmX8Lct+JSE/lMFq5EGDBJD MKnUiIMoKHSCObK01IPby8K5It8XOEKZYIVlGoZ/mgPiqAD4vHLsmTpUhZE3oIODEi3b gvn0IAyhVkAuotI9HrMW1aiOaWcC/Lor8mMrbNnXu6jNXIDwgJtEi3y5StnbZsqWkZvM nF9BxiVrMtuDUA0UL2yAdW5NJdF+KXKc+Ue8A0yBVtprddy7h6bpFr1gPiOXTD9l0MZY 9rFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732056; x=1687324056; 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=gZz+uQjmpOdIMxeiaJgwUz4BoyhUknFLXJa8Z3V7HsI=; b=iinADj8hceVEp03t2foPuDVS8n5iGfDTSgyovYln1eWWFcppkJUkM/bV95Yya965KP mV+av3+5JebbS8hUUipAxFKgXmzOl94r6Ch/3KLpXiWwmcwr3t8x/By4+nbWWUDgD0tz X6T67AewR/IZIB349wqY4st8KMk0mY+CzudU+H6xE/HeFSabj90MN2K9+UD7WwxoXyre x7hwcMZikGLBN77HFbq+8IzVqB5XopgNPYuFjrmR0cQNjkcJfoJ6pewe6zTxG1JXomSi cm5kDOg8YfgCmQy2gB07RcAm9X7DM3gjdD9/V6fueziaCBCDV1kP4FXtpQ7rupn5lgxO 915A== X-Gm-Message-State: AC+VfDzbOYj4vy2xkchV5jznkziTczNr8CBBWhqvG5+VvQAtTtEOu6X7 Sx6ayzA9AOyE0maMEt59CAvS63NIiV/lXXc1qTE= X-Received: by 2002:a05:6a20:440b:b0:10b:e88f:598f with SMTP id ce11-20020a056a20440b00b0010be88f598fmr916141pzb.51.1684732056314; Sun, 21 May 2023 22:07:36 -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.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:36 -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 06/10] maple_tree: Add mas_wr_new_end() to calculate new_end accurately Date: Mon, 22 May 2023 13:06:52 +0800 Message-Id: <20230522050656.96215-7-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?1766570002884870986?= X-GMAIL-MSGID: =?utf-8?q?1766570002884870986?= The previous new_end calculation is inaccurate, because it assumes that two new pivots must be added (this is inaccurate), and sometimes it will miss the fast path and enter the slow path. Add mas_wr_new_end() to accurately calculate new_end to make the conditions for entering the fast path more accurate. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 562507979a4b..0550a07355d7 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4297,6 +4297,21 @@ static inline void mas_wr_extend_null(struct ma_wr_state *wr_mas) } } +static inline unsigned char mas_wr_new_end(struct ma_wr_state *wr_mas) +{ + struct ma_state *mas = wr_mas->mas; + unsigned char new_end = wr_mas->node_end + 2; + + new_end -= wr_mas->offset_end - mas->offset; + if (wr_mas->r_min == mas->index) + new_end--; + + if (wr_mas->end_piv == mas->last) + new_end--; + + return new_end; +} + static inline bool mas_wr_append(struct ma_wr_state *wr_mas) { unsigned char end = wr_mas->node_end; @@ -4352,9 +4367,8 @@ static void mas_wr_bnode(struct ma_wr_state *wr_mas) static inline void mas_wr_modify(struct ma_wr_state *wr_mas) { - unsigned char node_slots; - unsigned char node_size; struct ma_state *mas = wr_mas->mas; + unsigned char new_end; /* Direct replacement */ if (wr_mas->r_min == mas->index && wr_mas->r_max == mas->last) { @@ -4364,17 +4378,15 @@ static inline void mas_wr_modify(struct ma_wr_state *wr_mas) return; } - /* Attempt to append */ - node_slots = mt_slots[wr_mas->type]; - node_size = wr_mas->node_end - wr_mas->offset_end + mas->offset + 2; - if (mas->max == ULONG_MAX) - node_size++; - - /* slot and node store will not fit, go to the slow path */ - if (unlikely(node_size >= node_slots)) + /* + * new_end exceeds the size of the maple node and cannot enter the fast + * path. + */ + new_end = mas_wr_new_end(wr_mas); + if (new_end >= mt_slots[wr_mas->type]) goto slow_path; - if (wr_mas->entry && (wr_mas->node_end < node_slots - 1) && + if (wr_mas->entry && (wr_mas->node_end < mt_slots[wr_mas->type] - 1) && (mas->offset == wr_mas->node_end) && mas_wr_append(wr_mas)) { if (!wr_mas->content || !wr_mas->entry) mas_update_gap(mas); From patchwork Mon May 22 05:06:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 97030 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1218727vqo; Sun, 21 May 2023 22:25:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ40vPDKKaapfYvGF/y1L1UT8XhDfXTvHWwVYP6bk+/NyzEGI+A4SK72O4wnNPAUyfNU4wnK X-Received: by 2002:a05:6a21:9998:b0:10b:10ae:40a with SMTP id ve24-20020a056a21999800b0010b10ae040amr5209210pzb.56.1684733149907; Sun, 21 May 2023 22:25:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684733149; cv=none; d=google.com; s=arc-20160816; b=XhR3APRhm4fdepRgBS9q+MqUySvJWL5DVayPw7ZiZlf2K2KIxoq3A5E5HJISXO7KZ7 gGlD/4Svx4IcCr3Dd1K+9y8mbgyHNeWAZBOwM6kYmwSHb1HEH6LVTEOYRIA61Jgd7LzA xFtdAgMSz78rtxpL3cQy33w19HXfJTVNq9W81JaQxR6P2mfCncSs5MPMxvYg3zoHP6hH E2vUs8xkGcz2igi24Mh5A7FEVi6NFvL788AJJeVgT0DvIh1sas4dGKt7X+FrCvQyKILD GN53nqnuP5qfd+lR+aScWVStIAweJUb7FNi7xxvU7l/ljXDH/CypodOOdHHeVFDpKWij slqw== 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=BDMhWhfLT89+67MaNw9E+3uh4JNyHlNzHsoiSP1QJPc=; b=ZljUlTyilmgmvxZlOIRXp/TTwsMizKZuDyhtTwTlQnHfYP7OZjyBb2ZuvwWhqdd3XP OWtLHXvkgUTyb4X+gXuuBew8i6kraO0Q5eyCWmWHXn7fA66JYjwsw3ezJpJx1j922U81 qo2JuJOOJY3KFJgHi0vHqXf76AuKxU9t97Au1YJXHv0+dGjKNuMCgP32+ldaknVhG6xE h0oY3U0ihLJDlwF+wp1INZUOhBQ/IWUTtoF8qt/V/+vX+Uwadd6e5r6jID9jv5NVVaSB h5wcexAxsXd+0Hbv8fkq6nuWmDrfiNe9uUHAK6BL+wv0GxDQypw04F5J6VR2I4J4AP6Q +p9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=YlZq8Qee; 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 z2-20020aa79582000000b0064d740b7459si696714pfj.102.2023.05.21.22.25.35; Sun, 21 May 2023 22:25:49 -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=YlZq8Qee; 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 S231910AbjEVFIS (ORCPT + 99 others); Mon, 22 May 2023 01:08:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231790AbjEVFID (ORCPT ); Mon, 22 May 2023 01:08:03 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDCC5106 for ; Sun, 21 May 2023 22:07:39 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-64d5f65a2f7so626681b3a.1 for ; Sun, 21 May 2023 22:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732059; x=1687324059; 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=BDMhWhfLT89+67MaNw9E+3uh4JNyHlNzHsoiSP1QJPc=; b=YlZq8QeeFnwwN2PMnEu5ygiKTeL4TXc//yTBc0oVeHrSXzMJ8uRzfTDuP/PHlcM7UW hB9faQCix3KctJUaLZtd2UmZWfZ8Mfvt+myVSFtECmxjw+131ONog441mxQnYKz6dX/G FSnXiGW4od/KD+uyoierDNkcRBeklQL4FdrVA4CEWtOQ4uiJsFFsNHRgKdBvfALKLTVg DiFw3TJH9fb+KQulmNmJ1EB91in05l8bU2ap+Q70ZEOc1OoIOwCQuPhzBfcNlI7ADW01 xedz/T1eaNokKIMlAOtxmDXSzEUaUcieUHu/oXtk7OoUM6aiztzo2QZUarBT18g6KS/c Kp5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732059; x=1687324059; 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=BDMhWhfLT89+67MaNw9E+3uh4JNyHlNzHsoiSP1QJPc=; b=OgCE1yb/wuEeJg2NbMKGX4WKxvsaGKQTNz3fQwRGcoFJF8LOj/lrBLl2Y5gmAMnklf UIAGXUojAE00ru+10iH3fwODX3xk2R67ZwjzjA2fwBs3ktBgJ6+yvBZ32tkVLA3MOiuL IVp/RvrVrtd2Ok+1Ec4w6HQSHbT950fFB1l+Csmwlt37xCQAAPkMJOenUxa9VBcwQY1o N82lIhiFvyLO3K7Qc+nQpjtk8A6oNVPZKAl1NOD8VErqivPj3e8OkIdiX0JUTgkgMYHC og490p+Ovqp82VpeJqhxD974yB9PDjjeb2inzsCLt9tFTYLoPROkbGTd5nrbr/ozBN0j KFPA== X-Gm-Message-State: AC+VfDxVLyYF1AgIqZZZSmO94Y1uEggBnnDZQC9OFowS1vL8w6bJS8yX Pq444I2XzRxyqICvFr6kpk7SL62oufNGqcnjwkk= X-Received: by 2002:a05:6a00:845:b0:64a:f730:154c with SMTP id q5-20020a056a00084500b0064af730154cmr13394825pfk.13.1684732059192; Sun, 21 May 2023 22:07:39 -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.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:39 -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 07/10] maple_tree: Add comments and some minor cleanups to mas_wr_append() Date: Mon, 22 May 2023 13:06:53 +0800 Message-Id: <20230522050656.96215-8-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?1766570747283613284?= X-GMAIL-MSGID: =?utf-8?q?1766570747283613284?= Add comment for mas_wr_append(), move mas_update_gap() into mas_wr_append(), and other cleanups to make mas_wr_modify() cleaner. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 0550a07355d7..afbfdcdde5db 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4312,6 +4312,12 @@ static inline unsigned char mas_wr_new_end(struct ma_wr_state *wr_mas) return new_end; } +/* + * mas_wr_append: Attempt to append + * @wr_mas: the maple write state + * + * Return: True if appended, false otherwise + */ static inline bool mas_wr_append(struct ma_wr_state *wr_mas) { unsigned char end = wr_mas->node_end; @@ -4319,34 +4325,30 @@ static inline bool mas_wr_append(struct ma_wr_state *wr_mas) struct ma_state *mas = wr_mas->mas; unsigned char node_pivots = mt_pivots[wr_mas->type]; - if ((mas->index != wr_mas->r_min) && (mas->last == wr_mas->r_max)) { - if (new_end < node_pivots) - wr_mas->pivots[new_end] = wr_mas->pivots[end]; + if (mas->offset != wr_mas->node_end) + return false; - if (new_end < node_pivots) - ma_set_meta(wr_mas->node, maple_leaf_64, 0, new_end); + if (new_end < node_pivots) { + wr_mas->pivots[new_end] = wr_mas->pivots[end]; + ma_set_meta(wr_mas->node, maple_leaf_64, 0, new_end); + } + if (mas->last == wr_mas->r_max) { + /* Append to end of range */ rcu_assign_pointer(wr_mas->slots[new_end], wr_mas->entry); - mas->offset = new_end; wr_mas->pivots[end] = mas->index - 1; - - return true; - } - - if ((mas->index == wr_mas->r_min) && (mas->last < wr_mas->r_max)) { - if (new_end < node_pivots) - wr_mas->pivots[new_end] = wr_mas->pivots[end]; - + mas->offset = new_end; + } else { + /* Append to start of range */ rcu_assign_pointer(wr_mas->slots[new_end], wr_mas->content); - if (new_end < node_pivots) - ma_set_meta(wr_mas->node, maple_leaf_64, 0, new_end); - wr_mas->pivots[end] = mas->last; rcu_assign_pointer(wr_mas->slots[end], wr_mas->entry); - return true; } - return false; + if (!wr_mas->content || !wr_mas->entry) + mas_update_gap(mas); + + return true; } /* @@ -4386,12 +4388,9 @@ static inline void mas_wr_modify(struct ma_wr_state *wr_mas) if (new_end >= mt_slots[wr_mas->type]) goto slow_path; - if (wr_mas->entry && (wr_mas->node_end < mt_slots[wr_mas->type] - 1) && - (mas->offset == wr_mas->node_end) && mas_wr_append(wr_mas)) { - if (!wr_mas->content || !wr_mas->entry) - mas_update_gap(mas); + /* Attempt to append */ + if (new_end == wr_mas->node_end + 1 && mas_wr_append(wr_mas)) return; - } if ((wr_mas->offset_end - mas->offset <= 1) && mas_wr_slot_store(wr_mas)) return; From patchwork Mon May 22 05:06:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 97029 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1217630vqo; Sun, 21 May 2023 22:22:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6TUc4Yr2K8VmRLWDzfkwrrpxLTGx+3sGDK2odm2XcZtNfoVt/FJX6tiVC38L7BreJur7X/ X-Received: by 2002:a17:902:f813:b0:1ae:7d3d:65c0 with SMTP id ix19-20020a170902f81300b001ae7d3d65c0mr9036609plb.16.1684732957394; Sun, 21 May 2023 22:22:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684732957; cv=none; d=google.com; s=arc-20160816; b=VnkB1Exi2ObD1iH517VNWWe7KNKCu72ALZ9qY+BbdOp0DxszQh4/6YFG4yodWc5q6i I7XTL66VeprfGtZNiS68Kamfx1x/cQg62nRKy9fX/ZnalYRM7t+M1dCmcDXJar8Vc3WR /Tqhl1sagqGeCoh136mXfaKpI/+uemU5OCUXcjEbitC6WBQGBo/5vveCE6xykv+w6F6n jYzDuTwoDnKgNyZcSsCKi5VenXFcTr+G9njfHvdri4kndP1t7NjKAATqSb4G3exAgx37 ceH4wMiMReY1XOgS/Iydvgf8vVeszjQWxUvSidKmaw/RHCP6QZyaUwuMBXkzYrYmmE2C iTZg== 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=qKVnArPifyAdGV9PIImrukiWg2xfu85fuVT0WT/x1lU=; b=YZtGiT+4x3qnepUi6+p6mbMoi4j3PRiYYzwJHRuTiQYCz4QHeMgXhFnYSlb1TV9trC CUs6axb2NPko5KqzhzELNLx2euXyJOxlT7VZynIYgKjc1tXYB/+H+wO9ts7NEq6DESbi sYigrkgjx8geTk1o1ZR+UOZV9fJUiCCH3c4dafHl7+5sLcXL60CIffYGc0R9e1MCfi15 coM6ZfTcPQkmN+JYOZH2QX9TO3MiBUMFfSgMwVLQQgoE0s9mxvH+sjyQw1Kvpw1B71BZ Q0UcDRssm0l/6NbSaamVeHHbdJ9Kp/n7E1QBdG0Pue6LEYuCPFabZmEhZ5Pq90yc2WyB tzZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=fw0PRf8Q; 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 jb1-20020a170903258100b001aaf7a9d7aasi2291465plb.126.2023.05.21.22.22.24; Sun, 21 May 2023 22:22:37 -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=fw0PRf8Q; 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 S231784AbjEVFHv (ORCPT + 99 others); Mon, 22 May 2023 01:07:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231758AbjEVFHq (ORCPT ); Mon, 22 May 2023 01:07:46 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95A9C139 for ; Sun, 21 May 2023 22:07:42 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-64d2981e3abso2786899b3a.1 for ; Sun, 21 May 2023 22:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732062; x=1687324062; 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=qKVnArPifyAdGV9PIImrukiWg2xfu85fuVT0WT/x1lU=; b=fw0PRf8Q3oQzgqHErNvDCU259xWd4Me2ceXFQD8pISEEcIEQZmk7bW7OJ3mBQ0eywD v7wNxQOQTVF4JZf9ON/6V5aCR3dkMK/NNESMj6wazF1zAw2gwqe+5A9004QgW40Jn8wf NRquXTchX9dImyrXbMIRvklOEHCfUofQg2xsBQ54kLTzcXz6ITsMt/ENw3oUKSUkw01t ZugU1Bcs0+eIsKfAO0I/jngb59O1PU0WvWi6+TwcGR4tuPzFQajmv63m1xEB1W3F+6HZ hJT0pSolSpSQKQ/rqzJP5/QiQVzYL5TvoE5uUy4y/Z8Tftr+0PeYqUwLgjtERfdeYo2D hh2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732062; x=1687324062; 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=qKVnArPifyAdGV9PIImrukiWg2xfu85fuVT0WT/x1lU=; b=YkHAQKkrIhbRchqIDv+mhrGgjazsDKT/H+VmppM25/dszObTIJWbdKaW3917ZqxFS0 OhfEEV6SHBABVKYuQwNRNPYn9PISv1kXIY3cZmMdaB4330hh2DY6nuKbeVq+mXTpyUz0 JVXNwoSEkXNlu4hAD9ekzNQV4nSQlvqXz6mQMwV85xD2Q8yrMKPoLUZN8LGWmqKjt+10 HMwh50KBALyQY3ZTHa4ptJWJfVXyJunJwVgvtjN4pFi6qW5JaiGq8jQLZqy1+yIC/kEH GkBfcRI2YnakyUExKxgAR0DOMtWbUjXc7H2VqNIdmqQDv/7kg+GSkzDMJWzKCrILU4O2 R5WA== X-Gm-Message-State: AC+VfDxLm7CHQ654RDO9xPhT/zjCGRUBK8J2g5sAZqq8ukxlhxtnhgDI UUzwdpx/cO61Pqkvg0/wus7UkQ== X-Received: by 2002:a05:6a20:3956:b0:107:17f6:940b with SMTP id r22-20020a056a20395600b0010717f6940bmr11393229pzg.41.1684732061987; Sun, 21 May 2023 22:07:41 -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.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:41 -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 08/10] maple_tree: Rework mas_wr_slot_store() to be cleaner and more efficient. Date: Mon, 22 May 2023 13:06:54 +0800 Message-Id: <20230522050656.96215-9-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?1766570545691778566?= X-GMAIL-MSGID: =?utf-8?q?1766570545691778566?= The code of mas_wr_slot_store() is messy, make it clearer and concise, and add comments. In addition, get whether the two gaps are empty to avoid calling mas_update_gap() all the time. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 53 +++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index afbfdcdde5db..1fc872f7683c 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4203,49 +4203,34 @@ static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas) static inline bool mas_wr_slot_store(struct ma_wr_state *wr_mas) { struct ma_state *mas = wr_mas->mas; - unsigned long lmax; /* Logical max. */ unsigned char offset = mas->offset; + bool gap = false; - if ((wr_mas->r_max > mas->last) && ((wr_mas->r_min != mas->index) || - (offset != wr_mas->node_end))) + if (wr_mas->offset_end - offset != 1) return false; - if (offset == wr_mas->node_end - 1) - lmax = mas->max; - else - lmax = wr_mas->pivots[offset + 1]; - - /* going to overwrite too many slots. */ - if (lmax < mas->last) - return false; - - if (wr_mas->r_min == mas->index) { - /* overwriting two or more ranges with one. */ - if (lmax == mas->last) - return false; + gap |= !mt_slot_locked(mas->tree, wr_mas->slots, offset); + gap |= !mt_slot_locked(mas->tree, wr_mas->slots, offset + 1); - /* Overwriting all of offset and a portion of offset + 1. */ + if (mas->index == wr_mas->r_min) { + /* Overwriting the range and over a part of the next range. */ rcu_assign_pointer(wr_mas->slots[offset], wr_mas->entry); wr_mas->pivots[offset] = mas->last; - goto done; + } else { + /* Overwriting a part of the range and over the next range */ + rcu_assign_pointer(wr_mas->slots[offset + 1], wr_mas->entry); + wr_mas->pivots[offset] = mas->index - 1; + mas->offset++; /* Keep mas accurate. */ } - /* Doesn't end on the next range end. */ - if (lmax != mas->last) - return false; - - /* Overwriting a portion of offset and all of offset + 1 */ - if ((offset + 1 < mt_pivots[wr_mas->type]) && - (wr_mas->entry || wr_mas->pivots[offset + 1])) - wr_mas->pivots[offset + 1] = mas->last; - - rcu_assign_pointer(wr_mas->slots[offset + 1], wr_mas->entry); - wr_mas->pivots[offset] = mas->index - 1; - mas->offset++; /* Keep mas accurate. */ - -done: trace_ma_write(__func__, mas, 0, wr_mas->entry); - mas_update_gap(mas); + /* + * Only update gap when the new entry is empty or there is an empty + * entry in the original two ranges. + */ + if (!wr_mas->entry || gap) + mas_update_gap(mas); + return true; } @@ -4392,7 +4377,7 @@ static inline void mas_wr_modify(struct ma_wr_state *wr_mas) if (new_end == wr_mas->node_end + 1 && mas_wr_append(wr_mas)) return; - if ((wr_mas->offset_end - mas->offset <= 1) && mas_wr_slot_store(wr_mas)) + if (new_end == wr_mas->node_end && mas_wr_slot_store(wr_mas)) return; else if (mas_wr_node_store(wr_mas)) return; From patchwork Mon May 22 05:06:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 97023 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1214933vqo; Sun, 21 May 2023 22:14:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6i0729jiQ+hJJVbwb9ntThnvFtbwnYgkhT5NeYv1VJJbGYEu44ddzwFl/LSqTBPhysGi17 X-Received: by 2002:a17:903:41c5:b0:1a6:abac:9cc with SMTP id u5-20020a17090341c500b001a6abac09ccmr12527072ple.66.1684732496201; Sun, 21 May 2023 22:14:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684732496; cv=none; d=google.com; s=arc-20160816; b=BflGDmpXnGWbwt+XB+UoaofVGi0wf6uFAg2U6Ytr58x3/AkAR/eVk4U0NRkdPEYF6z 7k/QOO42ChipjXyo2KiK0pkUGjfooCXtwxR1/cGkcn17qaSXTkYmWKsa6gtlG2Dx+2SR 2p6MNcbeD99B8ySMDXR9urSOqctrj+TEecPR6ZkrK3Mt+9m9uCuLIX1fiHaDss+j9dWl tZTXh8ohPPwOXZsQ2dh1Ob/qqpWqptfRaWSo4/FD1XDpi14cqsu8o/KYXkgeXs6iSupj UVjwJb6CM4iY+gqFfPQBNlrSoUsA4a0o1Z7eBhKYLzBjojfLNC18c5XFX/S8ftIZDqw6 YE2g== 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=zXcykhEsvUWhqgulB/awfwAbXbqU+zgrczKRgN6cHyY=; b=XEx533+8Ixg2CA17YA80lQ5+aNs4DLP58qUYmiFXhkPQJn9e9c7uy/JZPUE8+aR2d6 qOgWWpTQThf4iIdrUoNJOlkEcNOZ72ygdmMc1cCQJzmdWTTAohmC+SeYrXbFg3L7KLKQ 9x849WS7mGyQ6h2sYMSegxpmkRhkRzjVZRJqv5CGTnqLyZRbAyoKg5ZqXfguC2GRLQm1 4xI2Wx3nZaDfEM1V5d9NM6uH2n9tboV0ZSZj0irGdBp2tdoPfqJdHTeR0cG/64sEWY+O NO96CEecpwfIi4KPR2ge/IcOFGEpQc/66Azo0S/Df3qiouxgFU8Vnq8c1VfCpIAa28E5 07Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=BKOlFfw7; 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 iz11-20020a170902ef8b00b001a980a2b405si3818517plb.471.2023.05.21.22.14.43; Sun, 21 May 2023 22:14:56 -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=BKOlFfw7; 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 S231887AbjEVFIk (ORCPT + 99 others); Mon, 22 May 2023 01:08:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229764AbjEVFIN (ORCPT ); Mon, 22 May 2023 01:08:13 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E9D2E9 for ; Sun, 21 May 2023 22:07:45 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-64d1a0d640cso3003293b3a.1 for ; Sun, 21 May 2023 22:07:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732065; x=1687324065; 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=zXcykhEsvUWhqgulB/awfwAbXbqU+zgrczKRgN6cHyY=; b=BKOlFfw73MQsx7LKzihVb1eW2ku1Xa0uxS543oAZwXAeguF1RrGxaXVIbOQY17SQAQ kV1Uhnt0EvCzfgZCQJRhJA1pjbp8GCJmlUxZ8ozuWFSLCFY8c/MplHp2+j7uwMSrHVBa zU4r2Q45Vv1cofp/3n9tPjiEhbtoj/DxS6hNtjdbzivBv8C2Czl+xRXGAS+dhMiWKz0r /CIdRyWY17x9u18PW8dv9F5DlJFuCEK3kFjIekHWt3qgvtdh/p5TxWQX/VTgOScLeSHE 7x32o2kDITVj9QcRo0K2UK8/Mgua27wg8lQIjh01Up1//2t3VGz9t58HMSjr+JHyVx+X DncQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732065; x=1687324065; 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=zXcykhEsvUWhqgulB/awfwAbXbqU+zgrczKRgN6cHyY=; b=E2XH3r7VHRBqM2JuvuMNLaRfebwjXI9N3t/4AXX4Oph6sswGLrJkxDQe0ILtZEKU1C xunPLDl0Ovx+5NMdnhJ1JmmdgAc3cMCBwC1ONpooxiBVH69TayIXPPiaVsAOvX55CDoM zJyT+RAjcE2bVwZpSDInhcnezQA1XG/g5CmjcUFbSMPcfZzS3NtxTxDtM3MAeRErgqra TUrpnPvlH0qirJthbaJmRuDMdH6314ZbGynvRhJ+exEKJo0tF423m9Ntj4uEuoArWIHE RZKaQpTI7wYCLPIhZ1FPguOBIR2WANcm4CTTJNixEvbbVceVvPDJMftvrsdiLkvqKVSp /cnw== X-Gm-Message-State: AC+VfDwyfYjumUnoaCCzxjZOhAuvO5fb6xlLw9Zbh/TUfkxqq3tJbQfH 1bqjpgV2vle6Rb8Bc3FwUSgpmA== X-Received: by 2002:a05:6a00:1803:b0:643:6aed:3a9 with SMTP id y3-20020a056a00180300b006436aed03a9mr12429588pfa.0.1684732064880; Sun, 21 May 2023 22:07:44 -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.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:44 -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 09/10] maple_tree: Simplify and clean up mas_wr_node_store() Date: Mon, 22 May 2023 13:06:55 +0800 Message-Id: <20230522050656.96215-10-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?1766570061636199007?= X-GMAIL-MSGID: =?utf-8?q?1766570061636199007?= Simplify and clean up mas_wr_node_store(), remove unnecessary code. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 87 +++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 61 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 1fc872f7683c..aa1472c45757 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4075,52 +4075,27 @@ static inline int mas_wr_spanning_store(struct ma_wr_state *wr_mas) * * Return: True if stored, false otherwise */ -static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas) +static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas, + unsigned char new_end) { struct ma_state *mas = wr_mas->mas; void __rcu **dst_slots; unsigned long *dst_pivots; - unsigned char dst_offset; - unsigned char new_end = wr_mas->node_end; - unsigned char offset; - unsigned char node_slots = mt_slots[wr_mas->type]; + unsigned char dst_offset, offset_end = wr_mas->offset_end; struct maple_node reuse, *newnode; - unsigned char copy_size, max_piv = mt_pivots[wr_mas->type]; + unsigned char copy_size, node_pivots = mt_pivots[wr_mas->type]; bool in_rcu = mt_in_rcu(mas->tree); - offset = mas->offset; - if (mas->last == wr_mas->r_max) { - /* runs right to the end of the node */ - if (mas->last == mas->max) - new_end = offset; - /* don't copy this offset */ - wr_mas->offset_end++; - } else if (mas->last < wr_mas->r_max) { - /* new range ends in this range */ - if (unlikely(wr_mas->r_max == ULONG_MAX)) - mas_bulk_rebalance(mas, wr_mas->node_end, wr_mas->type); - - new_end++; - } else { - if (wr_mas->end_piv == mas->last) - wr_mas->offset_end++; - - new_end -= wr_mas->offset_end - offset - 1; - } - - /* new range starts within a range */ - if (wr_mas->r_min < mas->index) - new_end++; - - /* Not enough room */ - if (new_end >= node_slots) - return false; - - /* Not enough data. */ + /* Check if there is enough data. The room is enough. */ if (!mte_is_root(mas->node) && (new_end <= mt_min_slots[wr_mas->type]) && !(mas->mas_flags & MA_STATE_BULK)) return false; + if (mas->last == wr_mas->end_piv) + offset_end++; /* don't copy this offset */ + else if (unlikely(wr_mas->r_max == ULONG_MAX)) + mas_bulk_rebalance(mas, wr_mas->node_end, wr_mas->type); + /* set up node. */ if (in_rcu) { mas_node_count(mas, 1); @@ -4137,47 +4112,36 @@ static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas) dst_pivots = ma_pivots(newnode, wr_mas->type); dst_slots = ma_slots(newnode, wr_mas->type); /* Copy from start to insert point */ - memcpy(dst_pivots, wr_mas->pivots, sizeof(unsigned long) * (offset + 1)); - memcpy(dst_slots, wr_mas->slots, sizeof(void *) * (offset + 1)); - dst_offset = offset; + memcpy(dst_pivots, wr_mas->pivots, sizeof(unsigned long) * mas->offset); + memcpy(dst_slots, wr_mas->slots, sizeof(void *) * mas->offset); /* Handle insert of new range starting after old range */ if (wr_mas->r_min < mas->index) { - mas->offset++; - rcu_assign_pointer(dst_slots[dst_offset], wr_mas->content); - dst_pivots[dst_offset++] = mas->index - 1; + rcu_assign_pointer(dst_slots[mas->offset], wr_mas->content); + dst_pivots[mas->offset++] = mas->index - 1; } /* Store the new entry and range end. */ - if (dst_offset < max_piv) - dst_pivots[dst_offset] = mas->last; - mas->offset = dst_offset; - rcu_assign_pointer(dst_slots[dst_offset], wr_mas->entry); + if (mas->offset < node_pivots) + dst_pivots[mas->offset] = mas->last; + rcu_assign_pointer(dst_slots[mas->offset], wr_mas->entry); /* * this range wrote to the end of the node or it overwrote the rest of * the data */ - if (wr_mas->offset_end > wr_mas->node_end || mas->last >= mas->max) { - new_end = dst_offset; + if (offset_end > wr_mas->node_end) goto done; - } - dst_offset++; + dst_offset = mas->offset + 1; /* Copy to the end of node if necessary. */ - copy_size = wr_mas->node_end - wr_mas->offset_end + 1; - memcpy(dst_slots + dst_offset, wr_mas->slots + wr_mas->offset_end, + copy_size = wr_mas->node_end - offset_end + 1; + memcpy(dst_slots + dst_offset, wr_mas->slots + offset_end, sizeof(void *) * copy_size); - if (dst_offset < max_piv) { - if (copy_size > max_piv - dst_offset) - copy_size = max_piv - dst_offset; - - memcpy(dst_pivots + dst_offset, - wr_mas->pivots + wr_mas->offset_end, - sizeof(unsigned long) * copy_size); - } + memcpy(dst_pivots + dst_offset, wr_mas->pivots + offset_end, + sizeof(unsigned long) * (copy_size - 1)); - if ((wr_mas->node_end == node_slots - 1) && (new_end < node_slots - 1)) + if (new_end < node_pivots) dst_pivots[new_end] = mas->max; done: @@ -4379,7 +4343,8 @@ static inline void mas_wr_modify(struct ma_wr_state *wr_mas) if (new_end == wr_mas->node_end && mas_wr_slot_store(wr_mas)) return; - else if (mas_wr_node_store(wr_mas)) + + if (mas_wr_node_store(wr_mas, new_end)) return; if (mas_is_err(mas)) From patchwork Mon May 22 05:06:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 97048 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1228751vqo; Sun, 21 May 2023 22:54:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5bKB4Zmd600PyPxYT5R/fAbONYNLT6L7b8Mh+In4dBv6dS8n/rLwZbVGt+OIAM8tqXhO5a X-Received: by 2002:a05:6a20:e615:b0:102:2de7:ee1d with SMTP id my21-20020a056a20e61500b001022de7ee1dmr10023432pzb.6.1684734860729; Sun, 21 May 2023 22:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684734860; cv=none; d=google.com; s=arc-20160816; b=ZaDodUChV3d+ef6L9QWcxC3RF3Bth4bfRrQOovq9/yQnW7pXhPl1Ba3O2gXhStDull fI/dNq24R1ENOVnKRoCFjYJOpvScbjwS+v4Gtb/l4S2BcxjpfI7Mp8SFWiGuYkvbGDhm WV1YxMGds47niYzffOB03C44KT8d8mClzyw//A3dBb6l3etOGUqfXiHcM+kMp/2psXn5 QBtVs8cRS1Z2epNM9aK5+EaEvtnekY3fm8g6E5oWgfb0iLL8qqMcqvqWV+rCYVJk/Voy pWoKkdJid4mZ5lyz5HVtwXTo1kp/Yn/bb6N6BAE7N4fiJ4q327iQfx2Ycjs2WS8AHSMy 8wPw== 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=4yOLk/7tHD7/ODqSb7roZU5d9FbnbbLKf36QePLl4Fs=; b=krh2ZCdd67AlJuToJDHhuYPZXjp04A1o9NkrgaPY/bdqlDNYoXRE8Ql6OSF987wS9+ xx1MQmn/zA1FtgUM/NU0NFoBySKMicmgxZpvsc/oKFodqflM51aQaty+KC1ylUyfPI2l NfV/g7OTSIfXA0f1UkGqesQFBTy3QXYxMy6KgRSicsFTNQMrOztZ9Engs2eNQQa5sElR a3KLekmdkQcs6AkRMFFq/y8WksuuAvC2ZRbR98ZULI9EOj4Au0YshB9o5wu10lPAEeLk gqQs0+FPPF6kJVwmH8Hds3xZbrzXHA3Km6zqDF/PpMWptOa5oHMnveQI1R8Cz82evznd 9Wmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=AzHzNd0m; 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 x24-20020a63db58000000b0051b53285341si4193599pgi.277.2023.05.21.22.54.06; Sun, 21 May 2023 22:54:20 -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=AzHzNd0m; 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 S231806AbjEVFIp (ORCPT + 99 others); Mon, 22 May 2023 01:08:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231790AbjEVFIT (ORCPT ); Mon, 22 May 2023 01:08:19 -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 4E551129 for ; Sun, 21 May 2023 22:07:48 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-64d2e8a842cso2299179b3a.3 for ; Sun, 21 May 2023 22:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732068; x=1687324068; 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=4yOLk/7tHD7/ODqSb7roZU5d9FbnbbLKf36QePLl4Fs=; b=AzHzNd0mvm+jLZUdv/e7B4MQC3FEjUAXCF3VVAaoRyZSNx71MXEV51MxVvMQPGTRnL beZ/HAieLZVm6erPnazYr8lxJ/KMnHLGwVLS9rpwqD4TZwtSOLNIx2ilFdPluS8Fo5wH aulAdvKjGbORvC5pYRoimAsxCsbmmub7MiwaCjUVNgDxrPoNguk1B2QxFs2f/4u0BDxC ghdjhr9rKY4kS7OZrxzDsus7afl7TirEZO6XG2XE9PaDtCnJIS3J6uHgXmphvXYrsd64 V0VVSCQSKamOqt+7V9vZLiSj9VDqYA4y4mi6VfOkA+OqJDHu8LZDsc5yOBZRw9CnQDtp /E8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732068; x=1687324068; 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=4yOLk/7tHD7/ODqSb7roZU5d9FbnbbLKf36QePLl4Fs=; b=WnSaeAIFmoE/m2FY+BtcXD2W1LoABJuUPgL9tyw/mh0hKJ9U5noLlmHlDXVuTrFeHg 39yhXHAP6bJP7OmGyTQttoZB0fGcEDfHiBEIyzAac7JZUEuFNf6aIcSR7x5qslRW9uQp v06y/9KIVLOw4uKI3htAfVHgT7tu2TRXjYtGEwC1e3toV+yjn0nE/sGMdwRXxPSmhGmn b2JZniDDbhzg51iyEUl5HUTaLyfbqQmch8pP6OjTSfVrmjNLtJ5atlAgQKbkrUtuzZpC lJm2pKUNbC/pMggJKNL/rK23fZ0jhXE7+URypIJDLOiS98WPUZ12fQN0fyIAeWhGawXa 7OrA== X-Gm-Message-State: AC+VfDw3YGC4kcpSHg7qzsidFWJXxMaSr4j1ZztI12qNb1sdhUI5QzvI 0jNXg/TgSFciFbxm2KSNeH043A== X-Received: by 2002:a05:6a00:c8d:b0:644:c365:50d5 with SMTP id a13-20020a056a000c8d00b00644c36550d5mr11924837pfv.6.1684732067735; Sun, 21 May 2023 22:07:47 -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.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:47 -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 10/10] maple_tree: Relocate the declaration of mas_empty_area_rev(). Date: Mon, 22 May 2023 13:06:56 +0800 Message-Id: <20230522050656.96215-11-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?1766572541239954014?= X-GMAIL-MSGID: =?utf-8?q?1766572541239954014?= Relocate the declaration of mas_empty_area_rev() so that mas_empty_area() and mas_empty_area_rev() are together. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- include/linux/maple_tree.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index 85559a34a098..c4681cb8414f 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -474,6 +474,12 @@ void *mas_next_range(struct ma_state *mas, unsigned long max); int mas_empty_area(struct ma_state *mas, unsigned long min, unsigned long max, unsigned long size); +/* + * This finds an empty area from the highest address to the lowest. + * AKA "Topdown" version, + */ +int mas_empty_area_rev(struct ma_state *mas, unsigned long min, + unsigned long max, unsigned long size); static inline void mas_init(struct ma_state *mas, struct maple_tree *tree, unsigned long addr) @@ -497,12 +503,6 @@ static inline bool mas_is_paused(const struct ma_state *mas) return mas->node == MAS_PAUSE; } -/* - * This finds an empty area from the highest address to the lowest. - * AKA "Topdown" version, - */ -int mas_empty_area_rev(struct ma_state *mas, unsigned long min, - unsigned long max, unsigned long size); /** * mas_reset() - Reset a Maple Tree operation state. * @mas: Maple Tree operation state.