From patchwork Mon May 22 05:06:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13249775 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 79A1CC7EE23 for ; Mon, 22 May 2023 05:07:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 170C4900010; Mon, 22 May 2023 01:07:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 121AB900002; Mon, 22 May 2023 01:07:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F02C3900010; Mon, 22 May 2023 01:07:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E044D900002 for ; Mon, 22 May 2023 01:07:47 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C62F4C0420 for ; Mon, 22 May 2023 05:07:47 +0000 (UTC) X-FDA: 80816708574.08.E82B3E2 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf21.hostedemail.com (Postfix) with ESMTP id EF3821C0007 for ; Mon, 22 May 2023 05:07:45 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=BKOlFfw7; spf=pass (imf21.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684732066; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zXcykhEsvUWhqgulB/awfwAbXbqU+zgrczKRgN6cHyY=; b=U6s+JOYZxojihArmtAV9QOuRUIvBu7vzLiZwc2Mzu1Ulliu2Up7LCtw0TJ/qIASP7ztmo4 6gNfya5yK105CoRzaSuMfY8+AiDmINgr1m1V3pQ/7zgHJ4MAbyGOhKuGxN65ppi0q0MQRN jl0fND6tboz2PkJ0lYDdagaCC09IG58= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=BKOlFfw7; spf=pass (imf21.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684732066; a=rsa-sha256; cv=none; b=0XbTlq/amElfzEyuSiy6QZQpTxLhA3Kfy9D77hIhcI6xCFSx0oO0O34yrUKHkZ1bnN5Q+2 Dt3+fUnpCjOl2u9RMz8Jr15KraRYi3aTJgMRdm7T1lzOhMvBdE3a89IpdssFq56VLnNuKd ZM9Aebt9Wa1qcItrcGHsB9uVrQq9DE0= Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-64d2c865e4eso2485348b3a.0 for ; Sun, 21 May 2023 22:07:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684732065; x=1687324065; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zXcykhEsvUWhqgulB/awfwAbXbqU+zgrczKRgN6cHyY=; b=BKOlFfw73MQsx7LKzihVb1eW2ku1Xa0uxS543oAZwXAeguF1RrGxaXVIbOQY17SQAQ kV1Uhnt0EvCzfgZCQJRhJA1pjbp8GCJmlUxZ8ozuWFSLCFY8c/MplHp2+j7uwMSrHVBa zU4r2Q45Vv1cofp/3n9tPjiEhbtoj/DxS6hNtjdbzivBv8C2Czl+xRXGAS+dhMiWKz0r /CIdRyWY17x9u18PW8dv9F5DlJFuCEK3kFjIekHWt3qgvtdh/p5TxWQX/VTgOScLeSHE 7x32o2kDITVj9QcRo0K2UK8/Mgua27wg8lQIjh01Up1//2t3VGz9t58HMSjr+JHyVx+X DncQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732065; x=1687324065; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zXcykhEsvUWhqgulB/awfwAbXbqU+zgrczKRgN6cHyY=; b=epk21wUYFvH5Ivgzu1Szb24s/kbvhZLn5NlQZVxKGPsNGRfhrpp8BrYaEpgfdjtQal 9zVGEJmi8fG5PHpXrjFzTp6s9e6k0I0R/l6PPiSGEValC1kAcLMq2/YkXieIt+bAd/x8 bsrgiGOK2Rru2w0KjTIuRcaty9BhVIItz4WCZGFEzcwQewXFjzjG1RLHuXvRTD/P3+lI 6HshhVW7wohNyn4/Nbsl5gj0Q4RS4csV26wDc/zRrtlq4CMfAwPAsc89YI+K3ITidR7g nOi1BcIl3x37GC6vlEbndNfbFLwZeX/JHGzc/MLLftscKxXFs4ZYdhRgFFjGlvPz3Pbo 92MQ== X-Gm-Message-State: AC+VfDwrNaCBegLriI2NOtsM4/I8f3/m25IZKPtp4sK5x6YilPU67ZZB Q2ufvHUKR9VlqfAUObuKgXG2gg== X-Google-Smtp-Source: ACHHUZ4GwWTWE5gkEqNoMIf2XcDiWGmxfbFx8zj08GpTeiP2eOnG/1Io/VG9zQ4q7LRUwyQxcVeeSA== X-Received: by 2002:a05:6a00:1803:b0:643:6aed:3a9 with SMTP id y3-20020a056a00180300b006436aed03a9mr12429588pfa.0.1684732064880; Sun, 21 May 2023 22:07:44 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id t10-20020a62ea0a000000b0063b5776b073sm3247519pfh.117.2023.05.21.22.07.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 21 May 2023 22:07:44 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v3 09/10] maple_tree: Simplify and clean up mas_wr_node_store() Date: Mon, 22 May 2023 13:06:55 +0800 Message-Id: <20230522050656.96215-10-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230522050656.96215-1-zhangpeng.00@bytedance.com> References: <20230522050656.96215-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: EF3821C0007 X-Rspam-User: X-Stat-Signature: yanx9539woh8x9pxbp7e98zqgfkidew9 X-Rspamd-Server: rspam01 X-HE-Tag: 1684732065-487965 X-HE-Meta: U2FsdGVkX1/IoiJBzjmsovzxxoQMfjjpQITHmh2K3+PapmB3V1Hj8ID6moQWhhoP+2ClTP84FUWoXptTWw7tyXxVeFT89MNzrqklOJJnNcpsG6q4AabJB+cuqBS0Gk8mFDOGuO3A8gjAKTvhTC0wk464bUeSGtiHRrwdWUjah5a4folXTC6PQpMEmSzygus5lW/V18yvs8A6elLuIjILaFu218fsU4y7VkT+YnLIEcLblS6AMWunfHAJiBjBuDFTXJkEwOd7uVKsvsYb2d8lehH0qz/7RpkoO54enSDTbZTtJFMzubt9SHvVVWcR/2uIzWXipYuo9OB9Gjpsg/5CrHO75IfB5RpVt6nLh/7Z5gCuhPKHjG0VA+t7lEScQDw1QJ0ET2kPQlHBBwfFLgdNw2HguEQNILJzNuCkmBQ3tjpE8wyD+0Q5G7/5/Guulyr/xE3HN2PhFJB54RW88x8bGC4O3vP4CYoZfV8jbaT+AbpVObJQXc0jMVgl8e1EgWEIRrWnomlOXskstU9WmL0+2gxCaiIEvGbmTbCWlqHFariRcPh1hkywho8KHKABBs153AWgUO357tJJWOIGkZpsUqzHVTf7Wsj9wRNRLdci/aRxM89qqDGsZLXcvKTv72P+6ronjdeeVJrAnSbQ5bLdi52HeR+/qlK5xlHnqfLFmVQBA8R7Fh477YBe1TbFeqGyuUTBxwldOfRUenWtT9/LI3LfTrdhqdUpN4wg3hbHh7v4GQpV90KAWpP2WVHtxb2SS76lWQbMJ1nfbMQVfC6xTZxjagVJo945H1IR33VTx695m75JchaegPxaaPTYvJ9gIBT3wOavJNWnuE8FIcYhUVWguHvEOtHp58jfSmpwQFiJF8+2HpTGVnHADDq8xKB/oKKRCfM789yKk+n4iMKDmyXX7Jukrtcq0oT6H5YACD33NFOhMa8d2o9Jpz5ZmYEpkJV0CIVs+0xhum2Md4w V3LWh/BE q2G44WZzr3MjErsQdCUfilTGyusksQ/pFexriLrr18mbIsqCJ8mjSFtVKTPGISEM4fNljqFgjEacBGAjxfNmJWA/OFpven32mEcPgWcOHgAv/TGMt1BfZIOEUP2i+7Vdj60iP5u6ZjHusaCawgV/vfpJ/H7OBQ1CuTiB9yHIGPFnU3JO6zoyP+e+ACouClBcTWKt2u3y2PYbFrkTp0zI88ayAJxsCqVqZxM70DiKe/704gYipd8iuiQfRWNpZ1WgH3P43IdiOLPXWYGz68tyKEoCJZP2+VKrBg3ETabdDc+G+77X35MTS0gGmXzYb6uWTZVV7WISG6FO6vuWW+/hKkJJk4Zgt9pJOn//3OP1gpeDbedUPfAtIvejGT3JWjvA8St223kc5oO+TWy5x9LxdfVVYg+W9pEXk0MD1aN5rtgW7g/MhWc50deaPBQ4ug1OX3izlCDeTF1fMFuc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Simplify and clean up mas_wr_node_store(), remove unnecessary code. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 87 +++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 61 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 1fc872f7683c..aa1472c45757 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4075,52 +4075,27 @@ static inline int mas_wr_spanning_store(struct ma_wr_state *wr_mas) * * Return: True if stored, false otherwise */ -static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas) +static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas, + unsigned char new_end) { struct ma_state *mas = wr_mas->mas; void __rcu **dst_slots; unsigned long *dst_pivots; - unsigned char dst_offset; - unsigned char new_end = wr_mas->node_end; - unsigned char offset; - unsigned char node_slots = mt_slots[wr_mas->type]; + unsigned char dst_offset, offset_end = wr_mas->offset_end; struct maple_node reuse, *newnode; - unsigned char copy_size, max_piv = mt_pivots[wr_mas->type]; + unsigned char copy_size, node_pivots = mt_pivots[wr_mas->type]; bool in_rcu = mt_in_rcu(mas->tree); - offset = mas->offset; - if (mas->last == wr_mas->r_max) { - /* runs right to the end of the node */ - if (mas->last == mas->max) - new_end = offset; - /* don't copy this offset */ - wr_mas->offset_end++; - } else if (mas->last < wr_mas->r_max) { - /* new range ends in this range */ - if (unlikely(wr_mas->r_max == ULONG_MAX)) - mas_bulk_rebalance(mas, wr_mas->node_end, wr_mas->type); - - new_end++; - } else { - if (wr_mas->end_piv == mas->last) - wr_mas->offset_end++; - - new_end -= wr_mas->offset_end - offset - 1; - } - - /* new range starts within a range */ - if (wr_mas->r_min < mas->index) - new_end++; - - /* Not enough room */ - if (new_end >= node_slots) - return false; - - /* Not enough data. */ + /* Check if there is enough data. The room is enough. */ if (!mte_is_root(mas->node) && (new_end <= mt_min_slots[wr_mas->type]) && !(mas->mas_flags & MA_STATE_BULK)) return false; + if (mas->last == wr_mas->end_piv) + offset_end++; /* don't copy this offset */ + else if (unlikely(wr_mas->r_max == ULONG_MAX)) + mas_bulk_rebalance(mas, wr_mas->node_end, wr_mas->type); + /* set up node. */ if (in_rcu) { mas_node_count(mas, 1); @@ -4137,47 +4112,36 @@ static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas) dst_pivots = ma_pivots(newnode, wr_mas->type); dst_slots = ma_slots(newnode, wr_mas->type); /* Copy from start to insert point */ - memcpy(dst_pivots, wr_mas->pivots, sizeof(unsigned long) * (offset + 1)); - memcpy(dst_slots, wr_mas->slots, sizeof(void *) * (offset + 1)); - dst_offset = offset; + memcpy(dst_pivots, wr_mas->pivots, sizeof(unsigned long) * mas->offset); + memcpy(dst_slots, wr_mas->slots, sizeof(void *) * mas->offset); /* Handle insert of new range starting after old range */ if (wr_mas->r_min < mas->index) { - mas->offset++; - rcu_assign_pointer(dst_slots[dst_offset], wr_mas->content); - dst_pivots[dst_offset++] = mas->index - 1; + rcu_assign_pointer(dst_slots[mas->offset], wr_mas->content); + dst_pivots[mas->offset++] = mas->index - 1; } /* Store the new entry and range end. */ - if (dst_offset < max_piv) - dst_pivots[dst_offset] = mas->last; - mas->offset = dst_offset; - rcu_assign_pointer(dst_slots[dst_offset], wr_mas->entry); + if (mas->offset < node_pivots) + dst_pivots[mas->offset] = mas->last; + rcu_assign_pointer(dst_slots[mas->offset], wr_mas->entry); /* * this range wrote to the end of the node or it overwrote the rest of * the data */ - if (wr_mas->offset_end > wr_mas->node_end || mas->last >= mas->max) { - new_end = dst_offset; + if (offset_end > wr_mas->node_end) goto done; - } - dst_offset++; + dst_offset = mas->offset + 1; /* Copy to the end of node if necessary. */ - copy_size = wr_mas->node_end - wr_mas->offset_end + 1; - memcpy(dst_slots + dst_offset, wr_mas->slots + wr_mas->offset_end, + copy_size = wr_mas->node_end - offset_end + 1; + memcpy(dst_slots + dst_offset, wr_mas->slots + offset_end, sizeof(void *) * copy_size); - if (dst_offset < max_piv) { - if (copy_size > max_piv - dst_offset) - copy_size = max_piv - dst_offset; - - memcpy(dst_pivots + dst_offset, - wr_mas->pivots + wr_mas->offset_end, - sizeof(unsigned long) * copy_size); - } + memcpy(dst_pivots + dst_offset, wr_mas->pivots + offset_end, + sizeof(unsigned long) * (copy_size - 1)); - if ((wr_mas->node_end == node_slots - 1) && (new_end < node_slots - 1)) + if (new_end < node_pivots) dst_pivots[new_end] = mas->max; done: @@ -4379,7 +4343,8 @@ static inline void mas_wr_modify(struct ma_wr_state *wr_mas) if (new_end == wr_mas->node_end && mas_wr_slot_store(wr_mas)) return; - else if (mas_wr_node_store(wr_mas)) + + if (mas_wr_node_store(wr_mas, new_end)) return; if (mas_is_err(mas))