From patchwork Wed Aug 14 16:19:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sidhartha Kumar X-Patchwork-Id: 13763707 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 2BEA0C3DA4A for ; Wed, 14 Aug 2024 16:20:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 900F56B00A4; Wed, 14 Aug 2024 12:20:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 74E9E6B00A5; Wed, 14 Aug 2024 12:20:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EDC86B00A6; Wed, 14 Aug 2024 12:20:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 380966B00A4 for ; Wed, 14 Aug 2024 12:20:12 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id ACA0D1610EF for ; Wed, 14 Aug 2024 16:20:10 +0000 (UTC) X-FDA: 82451362980.07.335F6B1 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf27.hostedemail.com (Postfix) with ESMTP id 8C88540012 for ; Wed, 14 Aug 2024 16:20:08 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=mPpvf9Vl; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf27.hostedemail.com: domain of sidhartha.kumar@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=sidhartha.kumar@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723652396; a=rsa-sha256; cv=none; b=Qz6S8QgyGrp3/KJ4GkRK8WiE0b2ATn94Ax4p3tbYnVj+nRexQFnbowdUaTYrptkVPixFzo g0//j4yQMRcyKyysKj76cRXotcNXUYUy0lXH2BBElv7eLWXBby5x0t8hoSmlBVtFQiGke+ eHca5jAOAlOEDIO7/aGp19HgaBwNwAY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=mPpvf9Vl; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf27.hostedemail.com: domain of sidhartha.kumar@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=sidhartha.kumar@oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723652396; 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=JU3MqvLejtF8so20hIcXMrVIJrbiyTBFwoucx2atG8c=; b=ejw2GGTGPUTCp0vD48KpcAoVVhJT+tAF5VTW4sbZqbsBGyuluN+llplFw1eE8VnWbFoisB StJL1cFHnTe7pqeyS7YPKtVDcvp27LeDcLCXdI4eeOM6WGJOujQsl792CHXNFxFhIUfwVG 1N0xGJ6jXei2JkQJ0YRv7iXjgz+Hh74= Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47EBtWAu015137; Wed, 14 Aug 2024 16:19:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=J U3MqvLejtF8so20hIcXMrVIJrbiyTBFwoucx2atG8c=; b=mPpvf9Vl7mi+SK9ak g8xRjjdemhfyKdIX9++Pje+cowzRNYPv69qLf+lhPmswetGAPmywA94Id71fp6Qy 0iU8aO0zPpYkqZyyeqWGQpWTgfHo4IJNzChyUMQT7xqcGXxeNwRUGYWNDqK4ycp6 ckS9nCQkSiQXU+mz7fkJmyARzi9oRLlUeADEFxDHWZ6aayG5XifxaF6SCCjbwOSc OFN+BdlaWQXnNuYfAOpVnNNe4hOPJ3eYCcF00TuzdTs8TjTOcnpWC1J48wAYSSSE TUeW3E9oh0v7o4v/dABXZg+SCtgIixW4D7Gn2DjlZJ1EtCbR0garOcAatdLbuQeU IVjPA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40wy030v8x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 Aug 2024 16:19:58 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 47EFoG8d021115; Wed, 14 Aug 2024 16:19:58 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 40wxngn7s9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 Aug 2024 16:19:57 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 47EGIvCM035951; Wed, 14 Aug 2024 16:19:57 GMT Received: from sidkumar-mac.us.oracle.com (dhcp-10-65-174-212.vpn.oracle.com [10.65.174.212]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 40wxngn7gt-14; Wed, 14 Aug 2024 16:19:57 +0000 From: Sidhartha Kumar To: linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, liam.howlett@oracle.com, willy@infradead.org, surenb@google.com, Sidhartha Kumar , "Liam R. Howlett" Subject: [PATCH v4 13/17] maple_tree: have mas_store() allocate nodes if needed Date: Wed, 14 Aug 2024 12:19:40 -0400 Message-ID: <20240814161944.55347-14-sidhartha.kumar@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240814161944.55347-1-sidhartha.kumar@oracle.com> References: <20240814161944.55347-1-sidhartha.kumar@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-14_12,2024-08-13_02,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 bulkscore=0 phishscore=0 malwarescore=0 suspectscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408140111 X-Proofpoint-GUID: v3cAlC_zKdtNYKss_wgLLRbQp1Xvee2n X-Proofpoint-ORIG-GUID: v3cAlC_zKdtNYKss_wgLLRbQp1Xvee2n X-Rspam-User: X-Rspamd-Queue-Id: 8C88540012 X-Rspamd-Server: rspam01 X-Stat-Signature: h61qc5njesgnxuwqposz4ea76s5zgozn X-HE-Tag: 1723652408-718381 X-HE-Meta: U2FsdGVkX19qF/QOfUw63L+dEY9JOw4lKne/HthL6vKL/Jtw8mfgx/SqsvKwIp1gDvxYlz2uEobySHp//K3XFvqqFehUv5JtVmSa1InARYy92yq3IgkLmXLDslbev4oZFO973ei0J1z84GXmCLqM3j3EqAShbnkNIws/onXjeb1gtmPW274WJ7zdBeatLypEvykw+KRfP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ogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Not all users of mas_store() enter with nodes already preallocated. Check for the MA_STATE_PREALLOC flag to decide whether to preallocate nodes within mas_store() rather than relying on future write helper functions to perform the allocations. This allows the write helper functions to be simplified as they do not have to do checks to make sure there are enough allocated nodes to perform the write. Reviewed-by: Liam R. Howlett Signed-off-by: Sidhartha Kumar --- lib/maple_tree.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 6640ca775808..d5e020dd93fa 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5477,13 +5477,12 @@ static inline void mte_destroy_walk(struct maple_enode *enode, * @entry: The entry to store. * * The @mas->index and @mas->last is used to set the range for the @entry. - * Note: The @mas should have pre-allocated entries to ensure there is memory to - * store the entry. Please see mas_expected_entries()/mas_destroy() for more details. * * Return: the first entry between mas->index and mas->last or %NULL. */ void *mas_store(struct ma_state *mas, void *entry) { + int request; MA_WR_STATE(wr_mas, mas, entry); trace_ma_write(__func__, mas, 0, entry); @@ -5506,7 +5505,23 @@ void *mas_store(struct ma_state *mas, void *entry) */ mas_wr_prealloc_setup(&wr_mas); mas_wr_store_type(&wr_mas); + if (mas->mas_flags & MA_STATE_PREALLOC) { + mas_wr_store_entry(&wr_mas); + MAS_WR_BUG_ON(&wr_mas, mas_is_err(mas)); + return wr_mas.content; + } + + request = mas_prealloc_calc(mas, entry); + if (!request) + goto store; + + mas_node_count(mas, request); + if (mas_is_err(mas)) + return NULL; + +store: mas_wr_store_entry(&wr_mas); + mas_destroy(mas); return wr_mas.content; } EXPORT_SYMBOL_GPL(mas_store);