From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 DFC7A4279E9 for ; Mon, 29 Jun 2026 14:43:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782744183; cv=none; b=g5uzyhIa+Z+1Vs+wY5ebYwdCxQlY7WnYwszajp52XS7Em3QHZTY5FwiJCAWLTzcR5LRzAPZzi/q98z5MHP5KGA+1/9Vtd7L8dBtk9+sz9bteJdPEPKQwqFzu0O6U+PMBzPEfTu53PXan+a7XxkJkPefo4q7ADU/LXNbA9uVLgV4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782744183; c=relaxed/simple; bh=RG84vaemgyIyhyiyCNxRvtXu1lfrRFthsRWf7LahA78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gRthMl8rwlGPYK9VqpAtEXTDcGzzouc0YnuCGeuiknA52zzXFnJ4x+prqSc5V8WevyUTBDcO/iSqGeS0q/KhuvtJ66PVWoXp7A2WzwypQ27UzF/h1yzjWF9CodiyceHP5IFfmEkBCQ+68m501x47p/xMybpwNc8py5nj8cK1qpM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=alw+9xXW; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="alw+9xXW" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=B1Ckdeltb95QFCGV04iFuxHQugOzeBjtc5c251+J6Es=; b=alw+9xXWMdTxaibSc1faZFb44V nE8Z+84GTAXISWMVlfUiwcGJBiYuk0BvqtUunVvw/eybz4mdwwpzve8M53pozZQ4CqycaEUkrpa3/ gbtwlUsjBtkxC7qKs5hiD8I/0h4G+KtoCt3EMzrCE8VIJPv/6aTCrYP/OvuKOni31FSBPMg50k3DO ydW0zh8LanBg0kOucKEiYB9ANvlaSnZSFDRnLUKgRRvKJ4CJNuqZgAhMTBPplyG/rFccryTMyWRLH FGEkGInd/rSlNSNtvaIW77vmlp1rOOtLNmZTkwKhdOM/bnwySNcw9qigASknzBECf/bj05tVGBmMV lB9HJvoA==; Received: from [38.23.173.23] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1weDCP-0000000Euiy-13Vm; Mon, 29 Jun 2026 14:43:01 +0000 From: "Liam R. Howlett (Oracle)" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, "Liam R. Howlett (Oracle)" Subject: [PATCH 18/18] maple_tree: Avoid extra gap calculation Date: Mon, 29 Jun 2026 10:41:45 -0400 Message-ID: <20260629144145.1572283-19-liam@infradead.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260629144145.1572283-1-liam@infradead.org> References: <20260629144145.1572283-1-liam@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Prior to ending the ascension loop of larger operations like split, rebalance, and spanning store the gap in the node had been calculated. Once the node is inserted into the tree, the gap is recalculated in mas_update_gap(). This can be avoided by creating a helper for mas_update_gap() that accepts the known gap value, which reduces the operations required for gap updating path. Signed-off-by: Liam R. Howlett (Oracle) --- lib/maple_tree.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 94f2d5b9bc881..6d71fdc414706 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1602,14 +1602,26 @@ static inline void mas_parent_gap(struct ma_state *mas, unsigned char offset, goto ascend; } +static __always_inline void mas_update_gap_known(struct ma_state *mas, + unsigned long gap) +{ + unsigned char pslot; + unsigned long p_gap; + + pslot = mte_parent_slot(mas->node); + p_gap = ma_gaps(mte_parent(mas->node), + mas_parent_type(mas, mas->node))[pslot]; + + if (p_gap != gap) + mas_parent_gap(mas, pslot, gap); +} + /* * mas_update_gap() - Update a nodes gaps and propagate up if necessary. * @mas: the maple state. */ static inline void mas_update_gap(struct ma_state *mas) { - unsigned char pslot; - unsigned long p_gap; unsigned long max_gap; if (!mt_is_alloc(mas->tree)) @@ -1619,13 +1631,7 @@ static inline void mas_update_gap(struct ma_state *mas) return; max_gap = mas_max_gap(mas); - - pslot = mte_parent_slot(mas->node); - p_gap = ma_gaps(mte_parent(mas->node), - mas_parent_type(mas, mas->node))[pslot]; - - if (p_gap != max_gap) - mas_parent_gap(mas, pslot, max_gap); + mas_update_gap_known(mas, max_gap); } /* @@ -2173,8 +2179,8 @@ static inline void mas_wmb_replace(struct ma_state *mas, struct maple_copy *cp) mas->node = mt_slot_locked(mas->tree, cp->slot, 0); /* Insert the new data in the tree */ mas_topiary_replace(mas, old_enode, cp->height); - if (!mte_is_leaf(mas->node)) - mas_update_gap(mas); + if (mt_is_alloc(mas->tree) && !mte_is_root(mas->node)) + mas_update_gap_known(mas, cp->gap[0]); mtree_range_walk(mas); } -- 2.47.3