From patchwork Fri Jun 9 12:03:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13273778 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 770BDC7EE29 for ; Fri, 9 Jun 2023 12:04:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1287C8E0007; Fri, 9 Jun 2023 08:04:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B1A18E0001; Fri, 9 Jun 2023 08:04:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBBBE8E0007; Fri, 9 Jun 2023 08:04:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DD6028E0001 for ; Fri, 9 Jun 2023 08:04:43 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 633D116021C for ; Fri, 9 Jun 2023 12:04:43 +0000 (UTC) X-FDA: 80883077646.08.41F2F2D Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf05.hostedemail.com (Postfix) with ESMTP id 524A510001C for ; Fri, 9 Jun 2023 12:04:41 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=kMMLpjBw; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf05.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686312281; 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=ThxP1hd6NEaJLYq/dTfUmO4X1zEOytHqUc71DH0irxQ=; b=k9Wtvi6SQyPj96YArZh3nfcV77XYFcKmG6gGJA5JSjoeqwqj5uPLD4GkQPLtc9zvFfWwdJ L3EDZwkfaNgOIBFT2niBXmF/r4HNlyWhHietK3dQr+8rSz3Dc2IVKsW1QLEzxgGWVX1pCx rFHPUh7sbVlclioqkM+Vhy5qBGCRvzY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=kMMLpjBw; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf05.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686312281; a=rsa-sha256; cv=none; b=5RA9rExC0bnwgw6rrMkGX3jnRQYK3L05k4vHlAxru5w9YtYcrCe/nYd1opevpCM5Z9TXvE yOV1aTXs7dO/8q5CFZy0B8tHPSjXlAwRFhGtkY6dTokStFApfJZ4jssXNAa7oQUrxXedba 1dnT7uGTUuCo+hyVZV6QfX6aX/ajOuc= Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-651ffcc1d3dso1328120b3a.3 for ; Fri, 09 Jun 2023 05:04:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1686312280; x=1688904280; 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=ThxP1hd6NEaJLYq/dTfUmO4X1zEOytHqUc71DH0irxQ=; b=kMMLpjBwxBk6nSkMVj2MvpBmf13W42BxXy8TzuQQLpO1GcgdjEnhCRcGYOseOwBWN9 p2PamcOYR13FsRJBqxk/qPIzItSO1QQIWMo7G3dN+QyrlK9Grk8SkdJxDikiQeP4Es7U y+z7xVJIbraUjhaDT0+yEkT8TIBWpFLDTvMhgkiXeO+iqB/LcWp6nufUcz+Vwh06+eIv K1H3DsHCciHA0j6sg69MIn40X2CsiibTE9IiJuYta8HibBzJWhjRYVzwj1oYEJHlu8Ws TnEQvPGQulRU6wMKpNfJX3UD6UnfTmez4XNWpUcZFQHLg6hAQILHJUG+xr9h8u8nRftx jFQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686312280; x=1688904280; 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=ThxP1hd6NEaJLYq/dTfUmO4X1zEOytHqUc71DH0irxQ=; b=IVHW8jMs/cYl3CoQ8SH96fHG92TjyvsThuxefu191Tb0c3F6PdRgfPdNYDA7a/3Ttx 8dzW9r34B8o2pufnCPxSuOEs7cCfoKFg2myZ0OiwKxL5umEBX3vxiSRZLw1EkQ1hzKQh ccseEFr0CgV6S8gcMBVXcKiZT6L+cUNI+vVgwqykWgSkoVR6f8YuRH1GEMs7X5mlX1Cw JQBERc/0IWfr37kDqizkhoxyOCNQr47nsGRlu4pXsmBM0oS4gFvOGqLpFddMJ0Zk4vjX LyleV0toFAaH+bd0ddRPxfdPH8jc8o+qrRdUbSjlqXiSkSB7+QZObpXYxs4i07CLVOWt jGzg== X-Gm-Message-State: AC+VfDzEU5QPSTUiQu38fYToxOAUO0oYKGfcpfp/+THj3r76LML3jVJH Eies5q9wQv7X5tdr2SZU9cD+bw== X-Google-Smtp-Source: ACHHUZ5VTTHHjw53wUTNz1vUMTc24VjUz/r/h9LU8ikZx7DTRD/CLTI0AgOZICIklb1Pe/GoYz6dvw== X-Received: by 2002:a05:6a20:1445:b0:111:2f20:d48f with SMTP id a5-20020a056a20144500b001112f20d48fmr803105pzi.53.1686312280069; Fri, 09 Jun 2023 05:04:40 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id v12-20020a65568c000000b00514256c05c2sm2619168pgs.7.2023.06.09.05.04.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 09 Jun 2023 05:04:39 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH v2 3/3] maple_tree: add a fast path case in mas_wr_slot_store() Date: Fri, 9 Jun 2023 20:03:47 +0800 Message-Id: <20230609120347.63936-4-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230609120347.63936-1-zhangpeng.00@bytedance.com> References: <20230609120347.63936-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 524A510001C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 4u6f9au8cxztdah6dfjw5sgzi975rcio X-HE-Tag: 1686312281-245293 X-HE-Meta: U2FsdGVkX1/PjP6zyC7d+uRtB+xQa9392S00QtMYkyPYw0whmbesYwnyH16DtKWEO0R8K37TXOOuZ06pIck83B59ObhYydEdFCRQvVQhzo2MshVWAkz4CcV6CID1ldpSTsw6etBt0lhvikGicJpIlNm988ynisWMlgCiVeF4Bp47yjB0KnAq3NhlzRkxYx8+lKPFo0xy0zop/uPdOIcpjeNaZQzfJdgjDkOtDQR1xXfcEypj1lWx7M6aV1eC8BSe9Ww5DPP25zH1B47bBApw9sLyWSvd2Y9X/hQyFvaDDgvODx6BXkcf1Ce7wlhdR2BOtTdBRQ8sCgc3NM3HcBEPUCsw4zC1KyP0tl/mVXTswwIo4vHom6dhM8hBUu7Tc+0IjsfhcW9D8T3bznDcY3pU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ity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When expanding a range in two directions, only partially overwriting the previous and next ranges, the number of entries will not be increased, so we can just update the pivots as a fast path. However, it may introduce potential risks in RCU mode (although it may pass the test), because it updates two pivots. We only enable it in non-RCU mode for now. Signed-off-by: Peng Zhang --- lib/maple_tree.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index a96eb646e839..d3072858c280 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4167,23 +4167,35 @@ static inline bool mas_wr_slot_store(struct ma_wr_state *wr_mas) { struct ma_state *mas = wr_mas->mas; unsigned char offset = mas->offset; + void __rcu **slots = wr_mas->slots; bool gap = false; - if (wr_mas->offset_end - offset != 1) - return false; - - gap |= !mt_slot_locked(mas->tree, wr_mas->slots, offset); - gap |= !mt_slot_locked(mas->tree, wr_mas->slots, offset + 1); + gap |= !mt_slot_locked(mas->tree, slots, offset); + gap |= !mt_slot_locked(mas->tree, slots, offset + 1); - if (mas->index == wr_mas->r_min) { - /* Overwriting the range and over a part of the next range. */ - rcu_assign_pointer(wr_mas->slots[offset], wr_mas->entry); - wr_mas->pivots[offset] = mas->last; - } else { - /* Overwriting a part of the range and over the next range */ - rcu_assign_pointer(wr_mas->slots[offset + 1], wr_mas->entry); + if (wr_mas->offset_end - offset == 1) { + if (mas->index == wr_mas->r_min) { + /* Overwriting the range and a part of the next one */ + rcu_assign_pointer(slots[offset], wr_mas->entry); + wr_mas->pivots[offset] = mas->last; + } else { + /* Overwriting a part of the range and the next one */ + rcu_assign_pointer(slots[offset + 1], wr_mas->entry); + wr_mas->pivots[offset] = mas->index - 1; + mas->offset++; /* Keep mas accurate. */ + } + } else if (!mt_in_rcu(mas->tree)) { + /* + * Expand the range, only partially overwriting the previous and + * next ranges + */ + gap |= !mt_slot_locked(mas->tree, slots, offset + 2); + rcu_assign_pointer(slots[offset + 1], wr_mas->entry); wr_mas->pivots[offset] = mas->index - 1; + wr_mas->pivots[offset + 1] = mas->last; mas->offset++; /* Keep mas accurate. */ + } else { + return false; } trace_ma_write(__func__, mas, 0, wr_mas->entry);