Skip to contentSkip to conversation

mm-remove-the-branch-from-compound_head.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Mar 24

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm: remove the branch from compound_head()
has been removed from the -mm tree. Its filename was
mm-remove-the-branch-from-compound_head.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Kiryl Shutsemau <[email protected]>
Subject: mm: remove the branch from compound_head()
Date: Fri, 27 Feb 2026 19:42:54 +0000

The compound_head() function is a hot path. For example, the zap path calls it for every leaf page table entry.

Rewrite the helper function in a branchless manner to eliminate the risk of CPU branch misprediction.

Cc Albert Ou <[email protected]>
Cc Alexandre Ghiti <[email protected]>
Cc Baoquan He <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc David Rientjes <[email protected]>
Cc Frank van der Linden <[email protected]>
Cc Harry Yoo <[email protected]>
Cc Huacai Chen <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Matthew Wilcox (Oracle) <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Paul Walmsley <[email protected]>
Cc Roman Gushchin <[email protected]>
Cc Usama Arif <[email protected]>
Cc WANG Xuerui <[email protected]>

---

 include/linux/page-flags.h |   27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
include/linux/page-flags.h renamed from include/linux/page-flags.h~mm-remove-the-branch-from-compound_head +17 -10
@@ -224,25 +224,32 @@ static __always_inline bool compound_inf
 static __always_inline unsigned long _compound_head(const struct page *page)
 {
 	unsigned long info = READ_ONCE(page->compound_info);
+	unsigned long mask;
 
-	/* Bit 0 encodes PageTail() */
-	if (!(info & 1))
-		return (unsigned long)page;
+	if (!compound_info_has_mask()) {
+		/* Bit 0 encodes PageTail() */
+		if (info & 1)
+			return info - 1;
 
-	/*
-	 * If compound_info_has_mask() is false, the rest of compound_info is
-	 * the pointer to the head page.
-	 */
-	if (!compound_info_has_mask())
-		return info - 1;
+		return (unsigned long)page;
+	}
 
 	/*
 	 * If compound_info_has_mask() is true the rest of the info encodes
 	 * the mask that converts the address of the tail page to the head page.
 	 *
 	 * No need to clear bit 0 in the mask as 'page' always has it clear.
+	 *
+	 * Let's do it in a branchless manner.
 	 */
-	return (unsigned long)page & info;
+
+	/* Non-tail: -1UL, Tail: 0 */
+	mask = (info & 1) - 1;
+
+	/* Non-tail: -1UL, Tail: info */
+	mask |= info;
+
+	return (unsigned long)page & mask;
 }
 
 #define compound_head(page)	((typeof(page))_compound_head(page))

_

Patches currently in -mm which might be from [email protected] are