From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D60720FAAD for ; Fri, 21 Feb 2025 16:36:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740155792; cv=none; b=Tn6O108VN+41CJjWlepCL3wCmCQ/V/shD8xnPboEe1jZ+fuKkL7gZN7VLOo9FF+fVS6Gs+mXY68ipBBQGR2q1mBuPUFOMvvzMj9fZ0eufia4a1VWmaR1P3UXPAOEIusGCyqZSHJAx3XTqlxFtnZ6bZeHgc7IQaVgXiuzDWu133U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740155792; c=relaxed/simple; bh=6/4cXiGBkrWcp95zlasWks2EOIG1puomFfuMe2q8Uls=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k0yULLcpkdE/KMCUeNHyKqMmJrXbZ0sYSP+LmC3zuphUKyvCxLoZY8EROyQ8rv3hOVtlE67Gie1/n5LCOjWN+8IMnLDBKJ/nlsqztBGVNF3h/2Y7c97qrsKUFFV0zU7EZeGSgt58VEDeHtcY8lnBk8APcmT+2J4U/px/AZ6Cw9Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=a8KFEYqE; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="a8KFEYqE" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51L8fdxP018610; Fri, 21 Feb 2025 16:36:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2023-11-20; bh=lxM6D O0F+QyIrP48GZ8DBI2u4dV0evq288ua9Mia9+E=; b=a8KFEYqEeW8eplIs2Msn5 pkzpGFdBiXIwFTCQDVhx4QZEKsV2JSLYT4lOhay5/My24NI6pySR1A4Ektsapg3b gZ1fgraCtqM6n+FfM/PTuA+7mewmFkMd77rVoHdovagks/yEjHOIK3/royPziLt+ 1PQ3BYgVp6oZFIe5Qmj/vlIAZ4toi/wTiG7beITS9XNlXA/6toFTJnyN/fGlDybX ZXSP3cQoq+Y4UDozAQOz7YXeTEf43vPGiP1DcmdFIkLEaccDL6BTwnyFWpA8JOz0 MgPg6gsD6+YPaENrlGWtYj66bFHZVsmJwO3A1eEGL0FbpQbXO4fgJ6IDIIPGdlLR g== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44w00npq59-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Feb 2025 16:36:16 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 51LFZ5xe010490; Fri, 21 Feb 2025 16:36:15 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 44w07gxm87-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Feb 2025 16:36:14 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 51LGUIXJ005786; Fri, 21 Feb 2025 16:36:14 GMT Received: from sidhakum-ubuntu.osdevelopmeniad.oraclevcn.com (sidhakum-ubuntu.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.108]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 44w07gxm69-5; Fri, 21 Feb 2025 16:36:14 +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, richard.weiyang@gmail.com, Sidhartha Kumar Subject: [PATCH v2 4/6] maple_tree: break on convergence in mas_spanning_rebalance() Date: Fri, 21 Feb 2025 16:36:08 +0000 Message-ID: <20250221163610.578409-5-sidhartha.kumar@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250221163610.578409-1-sidhartha.kumar@oracle.com> References: <20250221163610.578409-1-sidhartha.kumar@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-21_05,2025-02-20_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502100000 definitions=main-2502210118 X-Proofpoint-GUID: fIvW1rKDgQFpsnCwJqLXXVV9ltBKwsOr X-Proofpoint-ORIG-GUID: fIvW1rKDgQFpsnCwJqLXXVV9ltBKwsOr This allows support for using the vacant height to calculate the worst case number of nodes needed for wr_rebalance operation. mas_spanning_rebalance() was seen to perform unnecessary node allocations. We can reduce allocations by breaking early during the rebalancing loop once we realize that we have ascended to a common ancestor. Suggested-by: Liam Howlett Reviewed-by: Wei Yang Signed-off-by: Sidhartha Kumar --- lib/maple_tree.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index ef71af0529f4..4de257003251 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2896,11 +2896,24 @@ static void mas_spanning_rebalance(struct ma_state *mas, mast_combine_cp_right(mast); mast->orig_l->last = mast->orig_l->max; - if (mast_sufficient(mast)) - continue; + if (mast_sufficient(mast)) { + if (mast_overflow(mast)) + continue; + + if (mast->orig_l->node == mast->orig_r->node) { + /* + * The data in b_node should be stored in one + * node and in the tree + */ + slot = mast->l->offset; + /* May be a new root stored in mast->bn */ + if (mas_is_root_limits(mast->orig_l)) + new_height++; + break; + } - if (mast_overflow(mast)) continue; + } /* May be a new root stored in mast->bn */ if (mas_is_root_limits(mast->orig_l)) { -- 2.43.0