From patchwork Thu Sep 19 23:48:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13808063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB427CF397B for ; Fri, 20 Sep 2024 00:40:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B6DD6B008A; Thu, 19 Sep 2024 20:40:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63D5F6B008C; Thu, 19 Sep 2024 20:40:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41AC86B0092; Thu, 19 Sep 2024 20:40:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1B0376B008A for ; Thu, 19 Sep 2024 20:40:14 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8E7FB1A112F for ; Fri, 20 Sep 2024 00:40:13 +0000 (UTC) X-FDA: 82583259906.16.259260C Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by imf22.hostedemail.com (Postfix) with ESMTP id C69EEC000B for ; Fri, 20 Sep 2024 00:40:11 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HHmmCwCC; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726792728; a=rsa-sha256; cv=none; b=rni2rrBitYjGjQ1iMUWCdPQQuRKLXdOJdflODqvlFPnF0DUxwo/v6qxo8dyiLRvbxqalLi F0+ZLMVTjJQYjyu3aXsGtus3v5UMlKh+1HMcBPy3lAz2x11XfNtuCAETaGvyjm5o4jxdqm wCOePjcmu1v7o7AbZqsf3EaS6iskwrk= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HHmmCwCC; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726792728; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=fmbAFMGUuyPIVLChk1SjH2boTL+656uQ3JpO53WmJ0A=; b=sbo5KY/Qyh5qSjcqAHQ9dNrGodHzV8xkqriulNrwOks1lisDm3T0RJqYkzO6pr7/QDqXMY WvrbMRGMU/mDXRIBj3TdYWbRsZpNQdqAg1v3a6n7SaCA3UVE3NrUYVzp67CxVDq/c2WRWQ 0dguyLRQYzRaPUBGMKoHgZd3GXrwK10= Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5c42e7adbe0so1593348a12.2 for ; Thu, 19 Sep 2024 17:40:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726792810; x=1727397610; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=fmbAFMGUuyPIVLChk1SjH2boTL+656uQ3JpO53WmJ0A=; b=HHmmCwCCJNWxc1KZp9OKQb3L8uvtGY6BRsINvuCUR2NTquWuYIDdg+wfv2e8e+yhwz ZjgJ8wnqOFpyNnny0rDb42ghSg+gUBKcTNoZ9KQTQ1I5BL/JmJSX03KGLWLNnVsVNJg0 lrNi8/uM8iYbVmrWSXPXBOBMKAFXZjQTKrCS67ClduMFeT2Pi0HdXqXWTxVa7mrTHrYj oQQAQzslZP/Y9403AotYrk5ZJXrjMWXdFTTye+fyw683388tjkzIk4wi3vkJUtml+jrB +tLef9cgL7edhrA7XUD4LrpjxgwbnXImU2cHX7Y37Kgx6S1TMveq9aW/t345A3LSalOs A4TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726792810; x=1727397610; h=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=fmbAFMGUuyPIVLChk1SjH2boTL+656uQ3JpO53WmJ0A=; b=oFrSd9edynB/6KRp4bFXJTXPrNbPiYZXseREitsW5niMsMyAjtMYOLBivn/tJ1byao Ms/sxbu5W+gcb9/Kuc/4GQ82i5LYlYtk7Qcc+s2tRuVLswrXseYxTcLifgBP+Ft1NJ5c DAW+Nvgaaf5PEoe7gvewnOciSX1bTgwk1OwG4SfnnnUo0gzX8/QxbE52d+zbxAmHuLGo B1o0vF2ngn60g7PTJIYfOJwVZJz9Dc2ghMhxpWvWRYsAfCYKM/FhJj2b7j1l1QyXZpcp k9cmovtvlMeOhdKcuHtD+QJmykQLQ/sgRsPrXxbRxbN0L2m1GcsLVj03gnOXePgNuDSn G75A== X-Forwarded-Encrypted: i=1; AJvYcCWb0I2cqnX2L9/l+4sObLd8vwbn+esGp+yEZdrYf/IUgAbIcJARMurC+rBV8I2cW2TJpr4CSrvUrg==@kvack.org X-Gm-Message-State: AOJu0Yy25JO3BcVdw4b5yDYn2kWARtKGlYkkK0U3wcSayxuMC+fhHxlF cOx+7vwKSrwpsD/CIS2TtKcR3LFII8MfZhb00EEKhcXIOIDcdm17 X-Google-Smtp-Source: AGHT+IEBKkZHRVaDyhKGiI6GVXPDcRT/TmGFW23gZOzbRg7Q4uESeMDfM6pLOzlvE1if7genczIWxA== X-Received: by 2002:a17:907:1c28:b0:a8a:3ece:d073 with SMTP id a640c23a62f3a-a90d5672848mr55267266b.10.1726792809964; Thu, 19 Sep 2024 17:40:09 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90cbc7122esm111084366b.124.2024.09.19.17.40.07 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Sep 2024 17:40:08 -0700 (PDT) From: Wei Yang To: akpm@linux-foundation.org, Liam.Howlett@oracle.com Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, Wei Yang Subject: [PATCH 3/4] maple_tree: copy to mt_pivot_count() instead of mt_slot_count() Date: Thu, 19 Sep 2024 23:48:31 +0000 Message-Id: <20240919234832.24237-4-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240919234832.24237-1-richard.weiyang@gmail.com> References: <20240919234832.24237-1-richard.weiyang@gmail.com> X-Rspamd-Queue-Id: C69EEC000B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: mku5qc5zk9gasc97sddfgwziwe1iwoyp X-HE-Tag: 1726792811-839278 X-HE-Meta: U2FsdGVkX1/2vHhqzd7xMHJMJdkCBf40vu79xLQZOLNpyL3kHV5eGGELIUdBRI6GWY0X8TrU7rimzDLr3DpFRcegio2xgwv/q8pS1m6rM7cFjnuY0XIvSWM3JtbtueTFZIF8pf0D946aNTH20KK4deY+1SWMnRQeXy5ND2z4tKaB96YaOBDJU2H+vj2lJXIQ4zTR0mJRPZqbQl+cB5RM8geK/zvPME6OdST20886HgviWJgg2euYKeLZxEr1WS6+iSkm9sILTsvTGrdV8oVu+y3IRf/YenWVdV7uZqyeYsYPEefgskGhBIA2KfFSFX7POuTge4xOwQi3t23Lrv+I08DYr7z3TYA+OlquA72pwrthPmkq6V0U9jnEm4gZ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MO57pXc5x3M/mb/ X-Bogosity: Ham, tests=bogofilter, spamicity=0.011445, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: mas_mab_cp() copy a maple_node's range inclusively, and the maximum valid data index is (mt_slot_count() - 1) instead of mt_slot_count(). But if using (mt_slot_count() - 1) directly, it would have more instructions. The good news is we have defined mt_pivot_count() == (mt_slot_count - 1), except for maple_dense node. And mas_mab_cp() doesn't handle maple_dense node. So it is safe to use it. By doing so have almost identical generated code: Current: lib/maple_tree.c:2209: mas_mab_cp(mast->orig_r, 0, mt_slot_count(mast->orig_r->node), movl %esi, (%esp) # _135, movl -88(%ebp), %eax # %sfp, _137 movzbl mt_slots(%edx), %ecx # mt_slots[_142], mt_slots[_142] xorl %edx, %edx # movl %eax, 4(%esp) # _137, movl %ebx, %eax # _138, call mas_mab_cp # After applying this patch: lib/maple_tree.c:2209: mas_mab_cp(mast->orig_r, 0, mt_pivot_count(mast->orig_r->node), movl %esi, (%esp) # _135, movl -88(%ebp), %eax # %sfp, _137 movzbl mt_pivots(%edx), %ecx # mt_pivots[_142], mt_pivots[_142] xorl %edx, %edx # movl %eax, 4(%esp) # _137, movl %ebx, %eax # _138, call mas_mab_cp # The difference is we access mt_pivots to get ecx instead of mt_slots, which doesn't expect performance difference. Signed-off-by: Wei Yang --- 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 8ff075645f21..bb4183b973d4 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2211,7 +2211,7 @@ static inline void mast_rebalance_next(struct maple_subtree_state *mast) { unsigned char b_end = mast->bn->b_end; - mas_mab_cp(mast->orig_r, 0, mt_slot_count(mast->orig_r->node), + mas_mab_cp(mast->orig_r, 0, mt_pivot_count(mast->orig_r->node), mast->bn, b_end); mast->orig_r->last = mast->orig_r->max; } @@ -2692,7 +2692,7 @@ static inline void mast_combine_cp_right(struct maple_subtree_state *mast) return; mas_mab_cp(mast->orig_r, mast->orig_r->offset + 1, - mt_slot_count(mast->orig_r->node), mast->bn, + mt_pivot_count(mast->orig_r->node), mast->bn, mast->bn->b_end); mast->orig_r->last = mast->orig_r->max; } @@ -2963,7 +2963,7 @@ static inline int mas_rebalance(struct ma_state *mas, l_mas = r_mas = *mas; if (mas_next_sibling(&r_mas)) { - mas_mab_cp(&r_mas, 0, mt_slot_count(r_mas.node), b_node, b_end); + mas_mab_cp(&r_mas, 0, mt_pivot_count(r_mas.node), b_node, b_end); r_mas.last = r_mas.index = r_mas.max; } else { mas_prev_sibling(&l_mas);