From patchwork Wed May 17 08:58:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 95123 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp994327vqo; Wed, 17 May 2023 02:25:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Cf7ov9Y6XxDM35LUZr/3E9IZ5wv4/Nr1XovcIKA5tF7z3OZz5OEq9VQZOZjVA0wUKXBU8 X-Received: by 2002:a17:902:d4ca:b0:1ac:8384:a7fb with SMTP id o10-20020a170902d4ca00b001ac8384a7fbmr36803491plg.66.1684315545257; Wed, 17 May 2023 02:25:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684315545; cv=none; d=google.com; s=arc-20160816; b=KEa2g6OJ89S4c392gSht1II02I9iTE/xsWTuR+je36ExHZ8etIZHJqRBdeGUzcRDwT uTfN5V7GQfZmc+RM18s3IvBvJ3mbTLF87FfkVrkv/SZM/MLQN1ctdBio7LoxMVP0l5oI NEbtqJFGwHWg601Gb978AyOQXJe/t5kR302uqs09rLnE05IOCJFqYy7U9fWvidBwYelj gGrH+qNH1dDfia+PfWi+J70xPMnFe2OZ2nKF5OVy4mVYdQbAaIL10hiXHVRf9AwvupOo xnO5UYOHo/BqK6x3ytBDHkFhACaXkCDZjIP++OHOk4Ft+MSV5poLTyQzCYniVEf9h70X apBQ== 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=dHQ/4wRfx8YGBT0TyL6p3b/Q07WGij+qVhIqIOji5co=; b=zSFLeMYeNRYiUxcowMWVID9Qm/PyDNZ8UYd/vn+W3/T4r//YwTMjl4NGPeGx5XSWEf e0fxQHT/v20ZFaPOj0EE/RC/p3HK1uO2TEt3F1wGMQ5dfoHxlme27bQZRu6ug2Fjy1UG mDX5FRoNjJxOmvxdyIzGeNFbgFUOdrjrNeKwVJd0f5KGeT169orgRcPkwxBlE6y1Hu+2 V5sWV3kTvG3qCIaKoMfGctqdbmP65IhTSm+euOZaWBkF+bfHom7mM+2e0X/PHLzmtqEC 8VWx+oBHGnkKRSfEar16JLdYVEZitm3PDiNiwKkG7acfNGcANw5PfWyfKi7Sc7xcUo8h pEyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=QkYpZT6J; 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 v5-20020a170902b7c500b001ae5a8856fesi184221plz.189.2023.05.17.02.25.31; Wed, 17 May 2023 02:25:45 -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=QkYpZT6J; 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 S231174AbjEQI73 (ORCPT + 99 others); Wed, 17 May 2023 04:59:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231138AbjEQI7U (ORCPT ); Wed, 17 May 2023 04:59:20 -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 C880F3588 for ; Wed, 17 May 2023 01:58:49 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6436e075166so357214b3a.0 for ; Wed, 17 May 2023 01:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684313929; x=1686905929; 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=dHQ/4wRfx8YGBT0TyL6p3b/Q07WGij+qVhIqIOji5co=; b=QkYpZT6JTZgFCW8g+gHwlD3usHqZW7OZl7/3oBK6EGsOSrFnjcS/IsoCdmA13UbZeg EODYTAlK0P20L372ioqTr4+YuTOAr7N9aj7tscBr5rWLf0oHxfBOH7sqej8hccrOpEaq GzVu2hXKgmar5SOACGxyML1twxQVjxzY9EV/y9pT+8ToUqs7vIzbk7yu9KRqwACOMP92 U6P8OWr4V6wAeSEzkzL1zMhergOyQFTCkUCmJaedD2y5sfSLKFOPC4qm317hWlCuNQAy cXRnFGH7Mk0l/7roCte8CKvnYjrTWFs1OgO1YEP9J9n9Iz2LcGFgqRtukM2Rg3YWhnqz qTWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684313929; x=1686905929; 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=dHQ/4wRfx8YGBT0TyL6p3b/Q07WGij+qVhIqIOji5co=; b=a7edJyos/y88ljiU0zWehXeBvxF2IeW4b6oikfHV/Tn8dQYC19IGVvfv0fPFTlDP7K BXlRfeDRUuiHzCYpO41gKggGSz0fGrRxOuQHLC1f4O7AnjKSb4xstvU4bJUnJSSB6R0V ooHDr6Q1/5Cul0vvtFmfmMFjfeOgpiqWq+fpetTNkSrGKTufRjx2mvpdwrQCHsPKY6TA FRx2zkDpSzvgCa0NMqygmBxYGo7nbgYbCD7feNT3ETXBuBL3jfpwYEU+0YKGqgxC8Vok 4X+Wp4hp4Faa7NPdRRxxyRI13xh3TScO4tx5/W85XXmpleD3VmvFusTctYBvHB09vsBd 0ZCA== X-Gm-Message-State: AC+VfDyBgdceZvK8/DL08qA8yAG2xsjHoT14rdgTMWH2UVQO2GEIJVtG FhHStdO30tlWtRYhfqVv87yF6w== X-Received: by 2002:a05:6a20:1587:b0:101:5171:c880 with SMTP id h7-20020a056a20158700b001015171c880mr35122952pzj.62.1684313929300; Wed, 17 May 2023 01:58:49 -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.46 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 May 2023 01:58:49 -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 01/10] maple_tree: Rework mtree_alloc_{range,rrange}() Date: Wed, 17 May 2023 16:58:00 +0800 Message-Id: <20230517085809.86522-2-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?1766132857336965714?= X-GMAIL-MSGID: =?utf-8?q?1766132857336965714?= Use mas_empty_area{_rev}() to refactor mtree_alloc_{range,rrange}() Signed-off-by: Peng Zhang --- lib/maple_tree.c | 63 ++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 4eb220008f72..e1820e90f167 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -6493,32 +6493,31 @@ 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); - if (mas_nomem(&mas, gfp)) - goto retry; - + ret = mas_empty_area(&mas, min, max, size); + if (!ret) { + 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; + } mtree_unlock(mt); + if (!ret) { + if (mas_is_err(&mas)) + return xa_err(mas.node); + *startp = mas.index; + } return ret; } EXPORT_SYMBOL(mtree_alloc_range); @@ -6529,29 +6528,31 @@ 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); - if (mas_nomem(&mas, gfp)) - goto retry; - + ret = mas_empty_area_rev(&mas, min, max, size); + if (!ret) { + 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; + } mtree_unlock(mt); + if (!ret) { + if (mas_is_err(&mas)) + return xa_err(mas.node); + *startp = mas.index; + } return ret; } EXPORT_SYMBOL(mtree_alloc_rrange); From patchwork Wed May 17 08:58:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 95109 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp987817vqo; Wed, 17 May 2023 02:11:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6SZYXG4iOkXplvffD55eeSNH56Lrr2XOzImiDfuxDj0k9s2l79XZnT0pBPNSYtUaoQKmbt X-Received: by 2002:aa7:88d3:0:b0:63f:120a:1dc3 with SMTP id k19-20020aa788d3000000b0063f120a1dc3mr246311pff.0.1684314661921; Wed, 17 May 2023 02:11:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684314661; cv=none; d=google.com; s=arc-20160816; b=b4JE+sSG9Z9QYT6KGd0OPeALdDui9pEaMKuVMcHtOlA4nJrUd0rEhkbC2fNoG9Q6+Q sJrgFmHeDCgovRvY6Vemkn4I5/O4PtIgxW4rRHFibHZ8PzCEF9a72nCKtixkPJNnmnkE sj/98KO11W5X3lLvMTbkzUZ1QDHNAOWFq3yHtJWCykNFON6/rlW39LAVmIDkRs9qqPS7 bC0C2oca635tyvHDHXjvUK1of7M9O/OOf+/JNRgbg96ZGsGhjOckaAaD2RR/LKmbYM5h 2NHwvURTNACzcxX9w4iP1wZiNn1IleZAc5fb6YUr3ZEy9YGlFGSB24N7mVFmk/b7DfLf Mcgw== 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=muDPH+0qSOjRZteWOxPwTAv/64dXCJZISlqxUy7MmMc=; b=s/ZPkcwpuUfHna7Oirh86SFN69lb76vbFJcafiPtcziS6VUBIb/qpyaan+tuCkOxcD mNNe918NfBZd7Zr+FBa7GOiye4VkAux2JTkRpG0RPiDRjN6mIuvgnF7pvJjV9N+NIn7+ Gfhcj1QaK5rSWaWVAHpn3i5Fhkts0oKjHcvfsXbwqr0YZrqnMHzI1aYqJHxO8JRgkBuI H6JANcvXwvbjML9fv5SLW3PbNcHHYMv8yjAR9Rk4KSW0Nf7SE5Fz68YWDB7G+TBJ4cN9 wlNWYgGDrjYTnoX+wVZkuLRHpoU2Q9DV1uEPK8zT8rBslIiyhN/4212j/cj6BSHmm2+3 YL6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=AiP2PsxH; 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 r3-20020aa79ec3000000b0064b032430cesi9979184pfq.133.2023.05.17.02.10.46; Wed, 17 May 2023 02:11:01 -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=AiP2PsxH; 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 S230358AbjEQI7B (ORCPT + 99 others); Wed, 17 May 2023 04:59:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230262AbjEQI66 (ORCPT ); Wed, 17 May 2023 04:58:58 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1AC53593 for ; Wed, 17 May 2023 01:58:52 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-517c840f181so238593a12.3 for ; Wed, 17 May 2023 01:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684313932; x=1686905932; 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=muDPH+0qSOjRZteWOxPwTAv/64dXCJZISlqxUy7MmMc=; b=AiP2PsxHN0UHtZNnNBLr9fCq5OgdAGQZRi7YFbOy2y/QUmZGsAStn51hGs3WPRvljK svzaf6zF4ms1xX5WJP6W7TogJIGblfgPdXi9w1v1KuiIhKEX8Zk0snQOV4pinKwdWAHN mAULjfjv3Vc5J4MQ/wNoqrLmlADD8RkSavPiFzDEdMa/Clbc/P5o1R1dSgAilJ2mD9qY +oxe+1+zRqvjGRT7Dr+q9A4EhpY3XNl62BHcNLWGtE2/bn5gMbQrlrSwTPcGSMDvSJgW 43EQ7iB8SiNhZZOKQaYKYg1YMadvkVWEgFXQPJpxJ/aUfwBGIFQVBVScKAElsFpAhhG7 e2ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684313932; x=1686905932; 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=muDPH+0qSOjRZteWOxPwTAv/64dXCJZISlqxUy7MmMc=; b=hSsStW9XwdCOHYhOG2sm+XrDb0y3QzcXgh93HD4lRT8L826weKmnYPSKO0B7aSi3kT cZMqZF385u0pjuZtpLmJ8YDUivu+e16wj5p3Vfln2H+nLgXORIrkS3P5SRJ1lZFp8Tj/ Q5aPemx9RP0SKwa2plCotOvshck4Qb8ganvuHgLkRUAall7IioNRB0U2JTTSAsOxYjp/ X3CKmpjfDAUAKfK+ej+iinYdNIY6LynumOCvH05X4EHR/Jc+GbwfAPNskoOkaor8eBKk MtAthiHq0ctGp5lixN+84WBjvw8OmFw+k6duhfgq4OkPLxa9uXkT4qNigH3clbXH2qDY +RVA== X-Gm-Message-State: AC+VfDx5Eb7UhxzOW1h+JNL5v54aeyD9SX3z8RWAqhBucH/1JGmhXiRg uuNMYiK64dARl3AZzOkaDIIXvA== X-Received: by 2002:a05:6a20:1590:b0:105:5086:fd42 with SMTP id h16-20020a056a20159000b001055086fd42mr18006961pzj.45.1684313932035; Wed, 17 May 2023 01:58:52 -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.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 May 2023 01:58:51 -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 02/10] maple_tree: Drop mas_{rev_}alloc() and mas_fill_gap() Date: Wed, 17 May 2023 16:58:01 +0800 Message-Id: <20230517085809.86522-3-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?1766131931258082798?= X-GMAIL-MSGID: =?utf-8?q?1766131931258082798?= mas_{rev_}alloc() and mas_fill_gap() are useless, delete them. Signed-off-by: Peng Zhang --- lib/maple_tree.c | 108 ----------------------------------------------- 1 file changed, 108 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index e1820e90f167..c8176f360dc2 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 Wed May 17 08:58:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 95117 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp992351vqo; Wed, 17 May 2023 02:21:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Xb5QjEYKeWx5y+8blD7tJZCajLY1BOeT7G0LVVZGj6yFJKt3p4nMycFPmMm24QJT2q0WQ X-Received: by 2002:a17:903:64c:b0:1ac:3303:daf5 with SMTP id kh12-20020a170903064c00b001ac3303daf5mr40410048plb.27.1684315262147; Wed, 17 May 2023 02:21:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684315262; cv=none; d=google.com; s=arc-20160816; b=MNbz7/eclwKnBZ8UQGUXONzAf1ZKot+N+Fcnl/XXz7vZOFl13Cy5rSYE5BE2mXG3me RY+Lks0EUqn2Woo7YD5yfdYPY86QthWWvfUFoh3trJE3HMl5jLY0loJtGAlATTUG9fFz sBA4KVhiqV+aoHzAnftDr8aWse1YeK0vWoxWyQmZ/ZZqQfP07nH32hg41XRsLdY9aDyX hr5SDdM9jb8MypZLlJ2eLfKSOJVMaWJ1z1DA2L36Xw4pyZ1gFYNotf5YGDbG31x3RYGY JxHvUFecdVPFyYGCWW4D94o2f55/cAq9n6IymgUBwiKoc3cUPtUSi2ZuTA0FJQI+FGNY NIBg== 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=JHlXin2w6vavc2+J7pEpRe/GvVWd1HUUirBvk9ov2Fw=; b=OfiDsqwkDGhDWMnhyzVmNxH4KPquyYJb/9dVVzz2RFV77XDT30l8ntd3ISohtIy7oH bxCnrQmZKte/y8R7Z5P2/v1w5ibCRAZq6h3mZywz+xy6VzwXd9hV12MsVgHKbr1XKqDx FtsrJtnGhKo780Nzc6V5N1XtZYyOOTHUr0dW83Ou4g93S7dF8k/gIOZghKkmwwt9FSPI YBoXk6hpDhRwNljYgc4rRlH2GKc7TFG7o+OM2a1a/ppoe2ByH0LC7c61kFcaOyPj7MhY gcz1w+YGVx/9d4gc5GHr+hghlTjQPzCaJrP8utoASODsqBU+mG+v6yQM1y2YgeBu6PT/ mcqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=H+MW+AUW; 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 q6-20020a170902dac600b001ac75cbde64si22422728plx.622.2023.05.17.02.20.47; Wed, 17 May 2023 02:21:02 -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=H+MW+AUW; 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 S231229AbjEQI7e (ORCPT + 99 others); Wed, 17 May 2023 04:59:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231179AbjEQI7V (ORCPT ); Wed, 17 May 2023 04:59:21 -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 7BED946BD for ; Wed, 17 May 2023 01:58:55 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-643b60855c8so468878b3a.2 for ; Wed, 17 May 2023 01:58:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684313935; x=1686905935; 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=JHlXin2w6vavc2+J7pEpRe/GvVWd1HUUirBvk9ov2Fw=; b=H+MW+AUW5biA2FNoD0LhWFVRD42pY2bqjWAmvKM0Yoa4zTu8srZy/Gj8H/aG3FvJL/ PA7sqqD+P2gUrAnlcsVHplTZl7wgbKAwHdTslukWmxEbgOXjPNvl10Imxfu9KOfb40wV kDTXMdOHxMgcLMLVn0uEGcjpaDT7ki5Q4pHfq/86IbfqVFgUdd0aXxibTk7EQxs3FXfw Ft/AS4NL32YXcLAJ1KSYOVm/6/qDeLSjmWKXoqRugkYoN74YskuK9j1WX96iwuHAN6EV tX08aUTLefRpOaQIL+Ad8e1kQkrnhOc0fhXJVRy2BGulNjX5fRt6fSezcJyZUWd9vLcM LL1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684313935; x=1686905935; 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=JHlXin2w6vavc2+J7pEpRe/GvVWd1HUUirBvk9ov2Fw=; b=WyhM/h+E+zrxQnRtr47+V3T0JGPUiIt0/5a+cQJCn3K2UaXN+At7/ANPGQhhPW9Y5x qSy9lZPyAQJqDnt9Xx8v2zpYZKWQml/u0nWXlnnz4kNfQUULa124QJPeMSQ6m8WvzNQf WgdYiP9xjTUHT40gLtRoSrTUZ0LfouOuZxVsogedQXvOX0XlZwBnPU44YQCcHQeBRolU Faap8dnAeu94GiD8VFFRGmG6J01EBCHiHbK2JbTMzfEb40IhlmXGkTp5LsxE/2zLXRtL aEu4gL8J6OlWnHI4UwOjIrdj0Qm+G9xmfZF0KgnacwLxQmOc1ukzY8vGCY8qBnJyRFIc 9qFg== X-Gm-Message-State: AC+VfDwb7ydtL9U5l1NIcxlBplow/T1rAa+6lnHmdu8YxChLaVgbCQ3T HTh6tab06wcuFqh3JFa7a58RTQ== X-Received: by 2002:a05:6a00:1a4e:b0:646:2edb:a23 with SMTP id h14-20020a056a001a4e00b006462edb0a23mr135673pfv.1.1684313935021; Wed, 17 May 2023 01:58:55 -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.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 May 2023 01:58:54 -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 03/10] maple_tree: Fix the arguments to __must_hold() Date: Wed, 17 May 2023 16:58:02 +0800 Message-Id: <20230517085809.86522-4-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?1766132560567523641?= X-GMAIL-MSGID: =?utf-8?q?1766132560567523641?= Fix the arguments to __must_hold() to make sparse work. Signed-off-by: Peng Zhang --- 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 c8176f360dc2..bec9906b0c8c 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 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; } From patchwork Wed May 17 08:58:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 95110 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp988142vqo; Wed, 17 May 2023 02:11:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4TBllxMgnki2oJUdh/AtvzJRndn85vdYqLNiqW8Eqsl5gsZ0ajHw70pZ7LMsyjL9/K3NxO X-Received: by 2002:a05:6a00:1594:b0:645:ac97:52a4 with SMTP id u20-20020a056a00159400b00645ac9752a4mr157403pfk.8.1684314701235; Wed, 17 May 2023 02:11:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684314701; cv=none; d=google.com; s=arc-20160816; b=GSKR88CBRDQ7kCUVLfaZhN5jkzmfGRnHiWH3dtzvjJV7MVY4msg3Mh6LRddvVvaTCI 73qvljreKpZ7qXJwysEiYPV5036LoMNZDE/gxugoEGPe7yjUCqjgfJo1Fmtl1SzpxwjZ T6artIIbnfjFDH1RiKQnI0kOURkG3332E0Nq7EzjZL/X2FlOO6j5YGpmHwj+lowUYYos eAlmGAw8sfCKP/dLpxlr/Q6rxj/KoTrBm+dogLzXdE4gYYbN99/NyqyeRkT8n/Wda/Ov jlbPnz9tK/nz8iFXw3bp46h0e83FmMR+XgGT/wUnFRN4DjjqyqZyTzKd5C/HloDC4zTe Je5A== 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=DxGBvrxxE77Ame9f1Z/CNikWB0RCA3Ncw948p+DNd2w=; b=1DI9/aJjMyJ+80PsfNChQGgbfCIInhFkHk4x4j5ReQbp7hO+b/H0iiRI3fIG7nqcwm XsR/DIqOA4i6XuSLXU9tXzP0N2USizjxOyku28TFSen6+6Dj7i7tne8CfTh6OZ56xLCw lN3QEwuddM+4dzJ9or/WfzlEnbA4v7Iv4QA5XA6kPKO9A/+wRp8eBLNy1LLTtI6aazIC HVuv70dPiKUZ2k5GayisrUT37Y7G05DvGkJ3EKaDFKHwjcSTs5fnMTj6FoqpZ0J4f0Vj mkqle+toPM3LYKFxflb2v1D+mx2njdJ8c1/aOTa5hBlZbjOB+9lohrRbed2r/tJinrv4 wErA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=hhZrHVT2; 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 r3-20020aa79ec3000000b0064b032430cesi9979184pfq.133.2023.05.17.02.11.27; Wed, 17 May 2023 02:11:41 -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=hhZrHVT2; 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 S231265AbjEQI7k (ORCPT + 99 others); Wed, 17 May 2023 04:59:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231182AbjEQI70 (ORCPT ); Wed, 17 May 2023 04:59:26 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED0BF30E0 for ; Wed, 17 May 2023 01:59:00 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-51b4ef5378bso439197a12.1 for ; Wed, 17 May 2023 01:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684313940; x=1686905940; 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=DxGBvrxxE77Ame9f1Z/CNikWB0RCA3Ncw948p+DNd2w=; b=hhZrHVT2VkGePkTiFFK4sSJd8tqamGMy8odrTM0tq7wmPGJpAVOC0d1on3Km9zXhzT y8D2OMuQprZsBQ1bkis77HuCjfKIWwbuujAGqKb6WVCab0myyW1TjTLmBulCtJRtb9++ 2nB5U1ur2jcEfvhed4ojCjG7XmkcUqePqFrzix4mfSpruFIr1e8Mm9LUOi4pYiwjBsVG Pb5fkZ6DlRSwVN5ADq+nQsZbVmfD4u/sXOD5KDkFqXds9wgkLdi9ywBUFX9W9V7yLQSP PcvmydPGz6L3A3m5f1hb1GPVXqXcyqapyMDTTKZwica43fM2ZzRKYIb2sGKWzoOhUc6X YQuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684313940; x=1686905940; 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=DxGBvrxxE77Ame9f1Z/CNikWB0RCA3Ncw948p+DNd2w=; b=csPjQV3IJCqht5MXVz7YhumC12g7EHJnlXPzXlqcaghshPl+qgqoZgWQ6rUqEx7RHu exKZePI4UX6W/Sx5A/9x+bFoQEVYHALzgSM88Qn369aWGAJGpt3CEFWSblIkxWq4rDFg En8veSH7lAlV+jQ8rUM52KVf4W62Q/DD0/pyEZqpx93RlTwN4Zuj1u98m83mBAVaWyUv Q1FK1EYZnd6YlAMSvxuOwD/BotzCHuGyvZBqKwqS5g0wJICdn1lCEjJ5HrMLl7AzgBlk myodPFdjm2+dyMlTcBVeTg/+t4btQ4psmrgQ0N0iHXifPC1im9u89TW3ymBK/DG0o/UW 3teQ== X-Gm-Message-State: AC+VfDwMiOIcagNHPQO58wL2eShF902QlnbwjYM/v1c7H5Bl5Fqt5SbR VSotEgmiXnqI2Erpx1nS4adLvw== X-Received: by 2002:a05:6a20:244b:b0:100:a9e3:17d4 with SMTP id t11-20020a056a20244b00b00100a9e317d4mr40707827pzc.0.1684313940513; Wed, 17 May 2023 01:59:00 -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.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 May 2023 01:59:00 -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 05/10] maple_tree: Make the code symmetrical in mas_wr_extend_null() Date: Wed, 17 May 2023 16:58:04 +0800 Message-Id: <20230517085809.86522-6-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?1766131971791403655?= X-GMAIL-MSGID: =?utf-8?q?1766131971791403655?= 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 82dccc660889..f881bce1a9f6 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4262,19 +4262,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 Wed May 17 08:58:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 95119 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp992603vqo; Wed, 17 May 2023 02:21:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7rrsMtjcdZAWMkuZ+mSblZKcTFsm+aHna3oHBFCmKrwFYmuMq8SHakGwf8mpKcQx6spkZO X-Received: by 2002:a17:90b:4c49:b0:24e:1b19:867f with SMTP id np9-20020a17090b4c4900b0024e1b19867fmr39930423pjb.37.1684315300373; Wed, 17 May 2023 02:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684315300; cv=none; d=google.com; s=arc-20160816; b=lmwp/0TTtclyJSLs2N2L68NVbyDGh8TgbIvUhP09xK+amchUvVyX4fXMgrXqV++6in /9kvmHLYw0rmG3nBtXd/c7ID+TuhojPr5PzzXvrJpw3edeyM2jVl/3ZgZYaE1i7vK86M pPXmnFqWog/OHy1rscp9AYMx7BafRd2Vyjzh2MpCKyPZ6B1GqALhe994ghkUvA7h9prr pTqr+4/SXHfQrRruvrt2twaD9a6ny/4SKw8+FhVDkSGZUCnlXF7DQeUhqYFckng/S9+w 9gNNWaNYOHh3RoaNo+EGIfLmMmdkEooc6xrE8TmGsF5vBq/cSgwrrQGzgJ4L2oGj0osw rKnQ== 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=sATgEzrR7h2S265Iki4mbf6UDAayTpXJc+pupXreNbo=; b=aCbtNdtHqttcwi3dUbXoi1GpKfxmXZkXIZvJ9hvmtXays5c3MJUFKrE3bkQQ3Q1ijH +KZS6QRTPRPjrZ7fNfW2wgVCUyclYA0/tUvedV5EmQPgC6m7YJyn7BlEUvcrN57r7cc/ ki+YNgJ3ke9N2h3fGqClSO5bk6LI9YHxhF1YbTc228fd8sbAatX0k3fsfPe/W8098AWb vF0CUBeeORjoffaKTfxSZyFbQnrhyuWVuqCD398896smrCV6XTzCtY9zfFuORSQi5Ybk hMVh5RqejxKyjFWxMDoK8ZlQWwvzeHDYNph/M4v9bVkLYcZKJ+QZ7nLo4VEKI9keEnr7 Zr7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=AhqU7dUp; 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 i125-20020a636d83000000b0052c30fc9fd9si19692147pgc.125.2023.05.17.02.21.26; Wed, 17 May 2023 02:21:40 -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=AhqU7dUp; 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 S230494AbjEQI7O (ORCPT + 99 others); Wed, 17 May 2023 04:59:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231145AbjEQI7F (ORCPT ); Wed, 17 May 2023 04:59:05 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B901A5598 for ; Wed, 17 May 2023 01:59:03 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-53202149ae2so318977a12.3 for ; Wed, 17 May 2023 01:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684313943; x=1686905943; 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=sATgEzrR7h2S265Iki4mbf6UDAayTpXJc+pupXreNbo=; b=AhqU7dUps8kowzB+osQO8so6VQf0rmRE6E4zIjuNyIPM6ywkBKH1KWI+hwH6Hb8grH bCqQ1C89pxuZN6S/Qe2mlxhm/jIwJYn47SJ10Pr+CL6qSbZU4B9m8pibG8gDHXwaGqha BVt/etviuKp+jgzPJWFF1XHYRdgXwLWhKdMu/EIsq8iNLQAuAxCx+XmuV8f4Yk++dfHM zNgtI4hXPq6uzaYEDuOkU3GWF4osZuQlgfHh6H/lds1CnKY1wfGyfMt8sEPGBvtX5fXQ FZNAo6CIYaoCnSAF+GU3yXvBnGH5ReKVI1SptmJCddaenxpFVlVGwF3/6ZCTN1QOOPcH AItg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684313943; x=1686905943; 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=sATgEzrR7h2S265Iki4mbf6UDAayTpXJc+pupXreNbo=; b=IbRD1eQTR4GfSrTHMYmeEpnSnuJzQqQNlb5nHTgwx73gkLyXYKpX58A1DkI6ZUwfwK MltgyrHf6h0XOldPE166IyZRoVumIo3P6Fje3jQmu9m1tLciPTLk1OcHtUGL5LoQJ+ct oADYIaVjeQq/B8vayfkuj/m8uzdviLwrFi6DJm44MnLbLPLUaxWruejJv/aEi4LNF+f9 wfUapj5XiO49xx3eMQyuK5mY25lvOowM6KWZBBMHcPX44llaNDVkpyTkhcFwJe/aI06B b1Ywgq9iVW3CnvmUF1AVU/mXWPoVWuCdWM2jCUzqFTspWq79cCdBPQEbf4jz1zA2lk8l 8h4g== X-Gm-Message-State: AC+VfDy8Aat1oCvnUx9lSqmWqSZQXLAqKv+mzz+Afo441CkQq7POegf2 tx1rb6MwhxEN3suOQmDbJni5KgvXwFde/76r758= X-Received: by 2002:a05:6a21:3298:b0:103:6c36:46db with SMTP id yt24-20020a056a21329800b001036c3646dbmr32420717pzb.55.1684313943206; Wed, 17 May 2023 01:59:03 -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.59.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 May 2023 01:59:03 -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 06/10] maple_tree: Add mas_wr_new_end() to calculate new_end accurately Date: Wed, 17 May 2023 16:58:05 +0800 Message-Id: <20230517085809.86522-7-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?1766132600730980042?= X-GMAIL-MSGID: =?utf-8?q?1766132600730980042?= 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 --- lib/maple_tree.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index f881bce1a9f6..3b9d227f3d7d 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4294,6 +4294,20 @@ 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; @@ -4349,9 +4363,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) { @@ -4361,17 +4374,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 Wed May 17 08:58:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 95111 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp988264vqo; Wed, 17 May 2023 02:11:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ58PNypdQfOHmWHy6kzWZO6YxHmUKvV36VJKMcx8qYC+7AOBtkZJoiZZeTHeGUthH8ju14X X-Received: by 2002:a05:6a00:1ac8:b0:63c:1be4:5086 with SMTP id f8-20020a056a001ac800b0063c1be45086mr174948pfv.6.1684314716142; Wed, 17 May 2023 02:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684314716; cv=none; d=google.com; s=arc-20160816; b=YH0CN3ET639kck911lMPp9Rk4QaRghFADQlZ/V+/gBsfYCvG2B3OoYZS/BcWXKZ8g1 JZlsfc2iPR3pxBNH9X/67SjHlxPhb1ZxZiWpDe3TyRQVsnMEj3zuY2iu9sU3mwGvfwpY ouPKHCRQOpg5u8GCBUQ1xvCXnaHujgL2coqsnqOtGK/2fLiudM61zJ4IjfG30jRoxUBL r5KC/xK8D6KBi837H92mRaTdlsksdjpvZk9CtL5rFFpnM397ZXyqxg9NYzvve0T6xzgF kWQMkKz/jyQg/qJIbjfTAD2A+R5f4ngL5M9358hXVJTqXGWZfxEDoOHWdzEI2Jg34iHF KF0A== 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=QOzzsH+HINl0nPqqyHkNJXvYfvo/GTpdTPT7077/sGQ=; b=V285QbP+/Y8AqF3vGze9eqT1m0DvjjFgoNPRzG+/lkdLAlmTK1J81go3PhOBi4a1q/ 9SFHQLDEd3G+XppCI60b6j5VZaTxf6X4OAu8k247XeYaynIiHxu0sBlG4JMRWGm72iAp nBzh5fMZit+WURc4el7y998TUGjzamhZ+ISW+DDmmktcnpDNK7EzS/Uqyn57mwUXXpLU oInPnaV2rxV2zIgyyzG9DhjdKuyN00tv+qwtrZ+n2XNaN2GAr9TEK/YL35nAC3IvIEGo LwDBfuUTjXDu0bUzbRqZyFHIXPB7KKbcAZJnHsL8+BvFjCSLDq5k6T1Uv+qAZdcf/J9t RJ/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=LEpcP6Z2; 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 r28-20020aa79edc000000b00643ba887601si21966187pfq.307.2023.05.17.02.11.42; Wed, 17 May 2023 02:11: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=LEpcP6Z2; 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 S231156AbjEQJAH (ORCPT + 99 others); Wed, 17 May 2023 05:00:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231215AbjEQI7c (ORCPT ); Wed, 17 May 2023 04:59:32 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69DCF5275 for ; Wed, 17 May 2023 01:59:06 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-52c6f81193cso306501a12.1 for ; Wed, 17 May 2023 01:59:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684313946; x=1686905946; 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=QOzzsH+HINl0nPqqyHkNJXvYfvo/GTpdTPT7077/sGQ=; b=LEpcP6Z2iO5V244pOZDVZ9PD/DssYhxM/g2Dgywp7L5+4So8fiBCWCs+ByEv4uwRGf Lsrr8ZnveVCkcBoJOY7slGzezuGunBr1hkrG0WbES9lRgR4WkaPW3WkN7INx7m+7bNLa b+SJ6BYMLFPicf7kxRDWbsSTeTmNlQfqx0iU2i51i1P6ZXGuBr0QlzliS3x6NlTf2MJy 84wk5jYwGFVMpmaKVNv8+tkrtO5wnPxXEPT/COvyZcL1lvzf3LamcYd/jVgY6tFdIuJK KUFlZld0CYflLmPq/feOirZ1Up6XjBoz2hnunMuxMbHmjp6cuc8TyruCJLUKCE4dPmGy y0rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684313946; x=1686905946; 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=QOzzsH+HINl0nPqqyHkNJXvYfvo/GTpdTPT7077/sGQ=; b=lWyWZ5jrJDnBHtteuK+zIyh87/12K02L8f85iZ9ycqWMz+w5imY7uDBU9dY+qsk+jd TMQd/+QtvjUxIQsrcndQV3wgVuymgV1ZyV/sHRg0AgbBmuoZxI2srCc3AY2KjhUa6MK0 k5inECxD6Zm7btMTAoLXHfZTZOfkBjykdYk5SBB7B4Ama/MEMBq1h16z4Mrvv4KVjHm6 5YQ8Kopbpg/gZRYQgq/7E7YyqmSI1MnFuIx/5d+vROrlN1VK13+txFKlowrz4lfkZqZS oBiXSN6JAIlJv5JXzLuhgjzNAHZKv9di+sZ4oGfpt8dDJCl/NsSUJR1s15aNrVaxOKsr a6pQ== X-Gm-Message-State: AC+VfDyAg64XIwdRiXtqr9x3AOaUZDdiglhPQb0qnNkKXgiyRUfrf+oD 6my7gzAmZsUfuvIPZVZ+aam01w== X-Received: by 2002:a05:6a20:12cd:b0:106:70af:a5b9 with SMTP id v13-20020a056a2012cd00b0010670afa5b9mr10364681pzg.31.1684313945924; Wed, 17 May 2023 01:59:05 -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.59.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 May 2023 01:59:05 -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 07/10] maple_tree: Add comments and some minor cleanups to mas_wr_append() Date: Wed, 17 May 2023 16:58:06 +0800 Message-Id: <20230517085809.86522-8-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?1766131987417523035?= X-GMAIL-MSGID: =?utf-8?q?1766131987417523035?= 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 --- lib/maple_tree.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 3b9d227f3d7d..bbe4c6f2858c 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4308,6 +4308,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; @@ -4315,7 +4321,11 @@ 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->offset == wr_mas->node_end)) + return false; + if ((mas->index != wr_mas->r_min) && (mas->last == wr_mas->r_max)) { + /* Append to end of range */ if (new_end < node_pivots) wr_mas->pivots[new_end] = wr_mas->pivots[end]; @@ -4323,13 +4333,10 @@ static inline bool mas_wr_append(struct ma_wr_state *wr_mas) ma_set_meta(wr_mas->node, maple_leaf_64, 0, new_end); 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)) { + mas->offset = new_end; + } else if ((mas->index == wr_mas->r_min) && (mas->last < wr_mas->r_max)) { + /* Append to start of range */ if (new_end < node_pivots) wr_mas->pivots[new_end] = wr_mas->pivots[end]; @@ -4339,10 +4346,13 @@ static inline bool mas_wr_append(struct ma_wr_state *wr_mas) wr_mas->pivots[end] = mas->last; rcu_assign_pointer(wr_mas->slots[end], wr_mas->entry); - return true; + } else { + return false; } - return false; + if (!wr_mas->content || !wr_mas->entry) + mas_update_gap(mas); + return true; } /* @@ -4382,12 +4392,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 Wed May 17 08:58:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 95112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp989188vqo; Wed, 17 May 2023 02:13:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ74T56cg65YB9HOk/EOGCYyVIXIh/BhHnZ7RR8GBtSzEv9asbMBPszyKDr0nD0zCFK3IYHl X-Received: by 2002:a05:6a21:78a9:b0:102:a593:a158 with SMTP id bf41-20020a056a2178a900b00102a593a158mr32952480pzc.47.1684314814888; Wed, 17 May 2023 02:13:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684314814; cv=none; d=google.com; s=arc-20160816; b=gFVt0/c6X3C2D4VWylzPRqBXaX1khQuiTIY8XBr626xiQn38iZPKJ97g5ICrmVeGSp 3hSEDMbqer3NmVGRgQ7o0AXStGZV0Mv3YXCtzGqJYcPy8Bxv5/uLUp/iN0JFtcCoY3al pbq90vAiLWElDK5C7sHbgI6hvhjkSS5U+LwVRgrgusXK7PlH6UridnflSnjGf3js750T GkTg/PvFg26gkBkztMtFFMLR21j5fuJ8I9DvpB9TT/AAWDJYbHKTRa+1gshK0ZhUeUJC AA54DKvU4O/IWAVkyieyIUtngJbOmCUafMhbVm8bnqPwM8Zzeni6JxNjTgQnYbySTBan VI5g== 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=c2NEt2xRNbAeMZlKbxLJ6YsB/xGL2Lb8EXzhG/zDA3k=; b=zYoBj5YFt0GUdcm6xLXgrzHrToF3BxapCqHofDebsDfZqAw2i2TBdFTAmu8yakJcgt EOG7ENTj5mUoE7iuIWNCb0X9hB/yUCOSIOsYEjD3HCKCUPTj/n9jRAN4C3R5bY6zP3SG elWAggKGlvgg1kq82LnjfPwpEWo8p/ftchsYVhQ3Px3UwAqXfBfFtsN74R511Y83YIXF XaLfT1xk/0gmmd00PTimXS3X8tIl6dlMKMFROe8cCuNjh9uRj9rgfsagoOPUHcfSQ6Mt YHHr3/0C/Rt3qd2wS/2RSKwDJX5sS7bGId8/dpCRvDi1XgThdH6jYQhbKQxQbXEGDcE+ wdfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=e3RVLiwn; 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 v10-20020a63f20a000000b0052c575f1d8dsi11992218pgh.260.2023.05.17.02.13.20; Wed, 17 May 2023 02:13:34 -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=e3RVLiwn; 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 S231232AbjEQJAN (ORCPT + 99 others); Wed, 17 May 2023 05:00:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231246AbjEQI7i (ORCPT ); Wed, 17 May 2023 04:59:38 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B0054225 for ; Wed, 17 May 2023 01:59:09 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-5343c3daff0so312921a12.0 for ; Wed, 17 May 2023 01:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684313949; x=1686905949; 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=c2NEt2xRNbAeMZlKbxLJ6YsB/xGL2Lb8EXzhG/zDA3k=; b=e3RVLiwnNDJjglhqaPR32b6FAYRWgjhUEJc1A7SpY9YkqYyI5oHyho43Tedkc5zwus aHgi1ZYqf7Cq4ND0XTOXDujMqiX5bzPJy2RZGibIBcrC/k5/aMp84AxWTf/aP2NCWhIR DyblUWcmvnVlSZKV9373659tbRllyKFikIOF1Wfpt8NGfxpcQs03vxNQpA/54vh1ICpj 3Zad9u1jj7xtrGQSXDJwfJJMXsx5fPPJuqUZwLmDSF7zeZdf4rOhSEhSkNvecFV/UIdg t7/KJsstAhtGxvKIJXclrTbcZed6B0ndQUqrgy0QJJ0XpDY0DFK9iHTZbSnQnWRdjhrP E4Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684313949; x=1686905949; 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=c2NEt2xRNbAeMZlKbxLJ6YsB/xGL2Lb8EXzhG/zDA3k=; b=ktNTFQRppMFmBEIONQhWociQ6jpPjzRiHMJ1IO67RQvsDUG9UPUd0ernsjBrokJnRc B0aoe+KixCHfbmwdNAZ1tnwwbN+D1SSfV09VNS33z/llb7eDPIKZ1WXSv80cX2+w0gPi a02K5zCVMGuZJn4/d3qlqVyDDfZcQPURrwsnhskbDKaSDjENffey3zhZyvGAWVyruXMB lC1QL/yWNMgOo4UwlzqPxo2VCRBhg8WD7Kc8XygEOXk5dJbOPoRMFxtUSgCh1vPm9o99 bGUpcGUEyyyL8vdzrcPt7ebIqcW/b0foRwGhSr0iSOPfR44WIPtjlm6k8cchLRXzq7cq KsrA== X-Gm-Message-State: AC+VfDz3GrwzK1WUzGAYu2tq6clN1e6rIV9D0DaQiiNnYiWu0JXuNODL 0eRYAE3CB5ao2cqGIbBd9E5MWA== X-Received: by 2002:a05:6a21:150f:b0:ef:7aa2:3cfd with SMTP id nq15-20020a056a21150f00b000ef7aa23cfdmr35267926pzb.50.1684313948739; Wed, 17 May 2023 01:59:08 -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.59.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 May 2023 01:59:08 -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 08/10] maple_tree: Rework mas_wr_slot_store() to be cleaner and more efficient. Date: Wed, 17 May 2023 16:58:07 +0800 Message-Id: <20230517085809.86522-9-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?1766132091056541724?= X-GMAIL-MSGID: =?utf-8?q?1766132091056541724?= 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 --- lib/maple_tree.c | 59 ++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index bbe4c6f2858c..25a8b7d5d598 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4200,49 +4200,38 @@ 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; + unsigned char offset_end = wr_mas->offset_end; + unsigned long lmax = wr_mas->end_piv; /* Logical max. */ + bool gap = false; - if ((wr_mas->r_max > mas->last) && ((wr_mas->r_min != mas->index) || - (offset != wr_mas->node_end))) + if (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; - - /* Overwriting all of offset and a portion of offset + 1. */ + if (mas->index == wr_mas->r_min && mas->last < lmax) { + /* Overwriting the range and over a part of the next range. */ + gap |= !mt_slot_locked(mas->tree, wr_mas->slots, offset); + gap |= !mt_slot_locked(mas->tree, wr_mas->slots, offset + 1); rcu_assign_pointer(wr_mas->slots[offset], wr_mas->entry); wr_mas->pivots[offset] = mas->last; - goto done; - } - - /* Doesn't end on the next range end. */ - if (lmax != mas->last) + } else if (mas->index > wr_mas->r_min && mas->last == lmax) { + /* Overwriting a part of the range and over the next range */ + gap |= !mt_slot_locked(mas->tree, wr_mas->slots, offset); + gap |= !mt_slot_locked(mas->tree, wr_mas->slots, offset + 1); + rcu_assign_pointer(wr_mas->slots[offset + 1], wr_mas->entry); + wr_mas->pivots[offset] = mas->index - 1; + mas->offset++; /* Keep mas accurate. */ + } else { 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; } @@ -4396,7 +4385,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 Wed May 17 08:58:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 95113 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp989436vqo; Wed, 17 May 2023 02:14:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ423RBjRLgLpd2TbvUdNvCN7zPrp0JPvkauteAYGySGLPq41YkIyAs1ynbZWSJvXSg5Ilpi X-Received: by 2002:a05:6a20:6a2a:b0:f6:d4d:2d with SMTP id p42-20020a056a206a2a00b000f60d4d002dmr45984591pzk.31.1684314854821; Wed, 17 May 2023 02:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684314854; cv=none; d=google.com; s=arc-20160816; b=QTEQxkTfqVFM2w7zTbfT07A9bXC0yHWmg0VJ9obTQA+bjcbN5lIxbUMVogvTIWQNZb 2T5I7XjB2i3+6lFFOOPpBx7MREAvOCILVvBRzY/mD5XW75hddJDO6Vw6W+XF2Odq9HBe JT9gKhaiwyeniG1ve0bCBUfNKBJyjDLGkXm3bg20hUmVVEZopyvR77PE/EYhzV/Z93lv VpM+Cmg7KQYrOn2ApfEwa0nnyUp0SUCqjIfXcpSXQ5VxVM7oza647uuKCRQ5wz/HqtMk B8hdgigVw9yA5MhRdIAa2WLjrLel3MQoPu0yummU4FA0KhWhMnmlNrEd10OEYGhFacjB Sv5Q== 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=L9aNGrqQBPjiuab0lkbsDijWS2guYts9Wyl3byUG0bc=; b=X17NzEwH5koNxfq3irnO/St4li6lIA41Hgg95gagnzN6TqL0Jl2jS4rRONAc9i5s6a 3yLQyO+DkZX2ih8PK5xC5Fg2QLjVxw9dzumyI88MMQlP0WXJABmN07ncD+Pxx7EuFuCP 7et7Klvi8vUPs1b6oZe+n0Zn9mnNmisfGg0x3wVm3u6VwRy/7YhXPR7TGoyYn8X8wnE0 XGrJ2C0x3Bg6NCzO+rqwQacZIxfoFS8x7wvqfyMf9tuEEVUk6G2jfTeCxR0pSL11Jr1X VP5zrb2/Q3ln1CMSwG7T6N5L7SVSbudxN/CTPf0w51wH5zGxhM08/+jHpzhWDIuaPtxR AMGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=PVkHjKmN; 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 v10-20020a63f20a000000b0052c575f1d8dsi11992218pgh.260.2023.05.17.02.14.00; Wed, 17 May 2023 02:14:14 -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=PVkHjKmN; 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 S231337AbjEQJAX (ORCPT + 99 others); Wed, 17 May 2023 05:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231266AbjEQI7l (ORCPT ); Wed, 17 May 2023 04:59:41 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3748159E5 for ; Wed, 17 May 2023 01:59:12 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-52160f75920so299944a12.2 for ; Wed, 17 May 2023 01:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684313951; x=1686905951; 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=L9aNGrqQBPjiuab0lkbsDijWS2guYts9Wyl3byUG0bc=; b=PVkHjKmNBRNoPUuywfzQSWpLOEe9y6Le98hPE+07bPGymbDIGtwrSk4xVyi3eR0k2S bX5kBB0H3NlzJfQEoP7sfHuEmEbDGUEcp9HPEsMVuzE+ptHbpQXZPJ7+zrXdwQNJ83ce 8ENSur0Opp8Zbg8MGsz+sUNE0qhL2bVj2HGCLmTOb1inynR0m+UBjc0msDu/7sxqJM2p Aa3bFJ7LFReAOst5AYiFDvfGMDZHcviGgITrQh9bibrxAdKMbOIHjjI+iqCOknwkkP79 K3v1Zx+QjZw5pAMKf58p3Ra2EZ8oyz7Ha+OckwnkN0YlwvSvcwbx3v1bsdc5IkIx16By FVNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684313951; x=1686905951; 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=L9aNGrqQBPjiuab0lkbsDijWS2guYts9Wyl3byUG0bc=; b=ZO0nxJYi1p2yL+oCnS/hBU1u0tPM39+VL93HO+gdOXdJfLeK+nhJWjM1yXl2wuxXRu a1ppDe7TNJZQ84+ha7JFweP9y09XL7WIu6aX4c4COap7lomoRALbUJgpUJ9eV52AlBd+ 3FCY96S6Y7ch1sjskEONAkCdA/yjhG4Pxpxa4CkRqjMuirLatIE4Li/awi4LqZLRReNx RoJHO+OMExl1a37TD0ZxIGMfc1+XCaD9OYLuGH5PjaE59Xoc8ho53BpH052bbezlDTSQ Os+JWwZMdBZE7Z3cTPdhobInfcjdvR85jWplYSjaxEvN/dTQwM/WMMTf0nAdZA3Ja/NZ 4G8Q== X-Gm-Message-State: AC+VfDwEHnmhWgWpRZsd9X9bukxq+saVOEc7asXH7WH0C8/zv8pwpHp/ Zf/qQw/QQjsbI5LqlFLD92PSBV4v6BfEpPM6ub8= X-Received: by 2002:a17:90a:af86:b0:250:5194:b135 with SMTP id w6-20020a17090aaf8600b002505194b135mr35679211pjq.34.1684313951480; Wed, 17 May 2023 01:59:11 -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.59.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 May 2023 01:59:11 -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 09/10] maple_tree: Simplify and clean up mas_wr_node_store() Date: Wed, 17 May 2023 16:58:08 +0800 Message-Id: <20230517085809.86522-10-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?1766132132948247552?= X-GMAIL-MSGID: =?utf-8?q?1766132132948247552?= Simplify and clean up mas_wr_node_store(), remove unnecessary code. Signed-off-by: Peng Zhang --- 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 25a8b7d5d598..b86001ad4632 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4072,52 +4072,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); @@ -4134,47 +4109,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: @@ -4387,7 +4351,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 Wed May 17 08:58:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 95114 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp989493vqo; Wed, 17 May 2023 02:14:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ77oRVxMbLSUGF55nOtfMciCDgVuCE8FQqbd8+CJREqOm8jSV6U8YlHTiJaC7dNi0a5qmWD X-Received: by 2002:a05:6a00:1306:b0:64b:43d8:a575 with SMTP id j6-20020a056a00130600b0064b43d8a575mr69039pfu.25.1684314861054; Wed, 17 May 2023 02:14:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684314861; cv=none; d=google.com; s=arc-20160816; b=npSDEO8FVTmwQJFXkmDu/aJI77zmR4dNUNsLFgrr9m2vyT/b5WR0ZTtsWR/ITErlsi Hy0w1Nn44fUcsOzGx+8g9kbeoJmHjodpGTAlsLX3JRGUNAa2edI4U6tQIjXaoNmpn2kU UGgo69apCD+XdZeJbJeUtLoNPKKDxnY11Bp1c45nG1XYI1N1wOCLA3JD9JIhzTIZexMY YdDZ/S4+UulzKl8+MF0u4DkpkhtLU1ErDSO1likv2sP5CNmItXPPgRW98H23zFzD/YLx zjQUMukS0hQouH6irhHEgI1k9Gxcth6tjd1Hp57Hu7bLKqW80SNWCFMJ9yT2QeyWL1PU Y7Gg== 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=pgm2ZZigrGKuYJY1bIpzJvq5x1Ykz5W1xtqu5E9fs7R0VFeBzzOc/C8tE36n0HmTPC vl7KaSpC5biRbB7Fl0e5eay5+os6nKRvrfQJEw0CL4Eb7Nzg4WOhl05To4QWTuS+Od3N I1bB/VpfY18SAYmOUNvP7F9CyL1b2s9JVwN5NFjgiiFf+KSeupS9t43iOl8XVemtknMP 0xDlqoKJtd7hVIc8YR0zQ6BXxShEy5sIHhE6jFX7SQqsX+S2CNL7E7Hyc228MPF6nX6A vCafdHW8hOYk/SMXSAeQKqsZCoBBqUuJgrtRMUb5n3eG/ncgCAseUMIzdVcC6SHnmJg/ gtiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Q7oXeL4s; 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 r3-20020aa79ec3000000b0064b032430cesi9979184pfq.133.2023.05.17.02.14.06; Wed, 17 May 2023 02:14: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=Q7oXeL4s; 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 S231286AbjEQJAS (ORCPT + 99 others); Wed, 17 May 2023 05:00:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230248AbjEQI7o (ORCPT ); Wed, 17 May 2023 04:59:44 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC7185B82 for ; Wed, 17 May 2023 01:59:14 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-643a1fed360so330454b3a.3 for ; Wed, 17 May 2023 01:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684313954; x=1686905954; 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=Q7oXeL4sctdcQKhumFBqJRf42lgk2FNTENFZu9Qkrb6TOXTEIcxw3K5SI70QmVnuHX 2OCeSnCqCeKxNz0bWKvL1ZvkX9V5aKtUkcZDe+E7XLyPfqXLnSp98eUqDOeL9woLgcpY si1rd8DLRkRyXptPznV12FXg8kcZDXpdfWShJ5yy2oKxn37RsKt+8+Va4+GLTaD/2yqk hyBRT5SBkbQNtwyol39lNKPfWRPA2+YT9s8nqCvwpbEzQi+urdyy27mjKENKLNgztn2B p2kqsdiNl/iwhz4U774B51iyoC0dqLHrV3i4E3vAN1Fi/ZG+zKqZEwvC6eXEiuqoFYD/ 6gQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684313954; x=1686905954; 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=Kjv34F9DRdDI1QrxqhAaAwVPKujopucCU2EgUm4d393/w+iWAwtFhVGnvhV2J2INSe WdIFBL0HtsbWCD0zRDsiSwXBhpdEADD9N6UuBO4OZxNjNBQdfogYLQmhUF6YSv2BiMbF pXp5u3XjKp3xj1ZvnmdtTyrrgxE7aZdAVGRmF4I+LIhzvO3V3kJdvR0xwiutxzXjrEzy kI0qq3UNB8FnakuPm2oZzIhbE+J90aGZPU1suLKLnpuVpV4XB7FZ4KRzsSC3rw0tiUfX Yl2TmwsmqvjnX2AlljSHj2SWOB6JIVS1hTQax/F2znwiK8VkEVMiMwm+4HzXrJg3NQ5T aO5Q== X-Gm-Message-State: AC+VfDz2aBGE3dDOCmGfNePXunZRFRL/zO3ZtMmnXWesbvCpAirEWNPr zJMLhFDYnoPfUgOsfkA4PanwsA== X-Received: by 2002:a05:6a00:2d12:b0:644:ad29:fd37 with SMTP id fa18-20020a056a002d1200b00644ad29fd37mr14335pfb.28.1684313954312; Wed, 17 May 2023 01:59:14 -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.59.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 May 2023 01:59:14 -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 10/10] maple_tree: Relocate the declaration of mas_empty_area_rev(). Date: Wed, 17 May 2023 16:58:09 +0800 Message-Id: <20230517085809.86522-11-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?1766132139459433307?= X-GMAIL-MSGID: =?utf-8?q?1766132139459433307?= 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 --- 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.