Skip to contentSkip to conversation

tools/mm/thp_swap_allocator_test: Fix small folio alignment

PATCH Applied Kaushlendra Kumar 2 participants 3 messages Dec 9, 2025 – Dec 18, 2025 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/mm/thp_swap_allocator_test: Fix small folio alignment

Use ALIGNMENT_SMALLFOLIO instead of ALIGNMENT_MTHP when allocating small folios to ensure correct memory alignment for the test case.

---
 tools/mm/thp_swap_allocator_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/mm/thp_swap_allocator_test.c +1 -1
index 83afc52275a5..d4434df3dcff 100644
@@ -142,7 +142,7 @@ int main(int argc, char *argv[])
 	}
 
 	if (use_small_folio) {
-		mem2 = aligned_alloc_mem(MEMSIZE_SMALLFOLIO, ALIGNMENT_MTHP);
+		mem2 = aligned_alloc_mem(MEMSIZE_SMALLFOLIO, ALIGNMENT_SMALLFOLIO);
 		if (mem2 == NULL) {
 			fprintf(stderr, "Failed to allocate small folios memory\n");
 			free(mem1);
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 8 lines · On Tue, 9 Dec 2025 08:47:45 +0530 Kaushlendra Kumar…

Use ALIGNMENT_SMALLFOLIO instead of ALIGNMENT_MTHP when allocating small folios to ensure correct memory alignment for the test case.

...

tools/mm/thp_swap_allocator_test.c int main(int argc, char *argv[]) · line 148

Quoted 8 lines
tools/mm/thp_swap_allocator_test.c +1 -1
@@ -142,7 +142,7 @@ int main(int argc, char *argv[])
 	}
 
 	if (use_small_folio) {
-		mem2 = aligned_alloc_mem(MEMSIZE_SMALLFOLIO, ALIGNMENT_MTHP);
+		mem2 = aligned_alloc_mem(MEMSIZE_SMALLFOLIO, ALIGNMENT_SMALLFOLIO);
 		if (mem2 == NULL) {
 			fprintf(stderr, "Failed to allocate small folios memory\n");
 			free(mem1);

What are the worst-case userspace visible runtime effects of this change?

Thanks.

#2 lore raw
Quoted 11 lines · Andrew Morton
Quoted 10 lines · On Tue, 9 Dec 2025 08:47:45 +0530 Kaushlendra Kumar wrote:

Use ALIGNMENT_SMALLFOLIO instead of ALIGNMENT_MTHP when allocating small folios to ensure correct memory alignment for the test case.

...

tools/mm/thp_swap_allocator_test.c +0 -0
@@ -142,7 +142,7 @@ int main(int argc, char *argv[])
 	}
 
Quoted 8 lines

tools/mm/thp_swap_allocator_test.c int main(int argc, char *argv[]) · line 148

Quoted 6 lines
tools/mm/thp_swap_allocator_test.c +1 -1
 	if (use_small_folio) {
-		mem2 = aligned_alloc_mem(MEMSIZE_SMALLFOLIO, ALIGNMENT_MTHP);
+		mem2 = aligned_alloc_mem(MEMSIZE_SMALLFOLIO, ALIGNMENT_SMALLFOLIO);
 		if (mem2 == NULL) {
 			fprintf(stderr, "Failed to allocate small folios memory\n");
 			free(mem1);

What are the worst-case userspace visible runtime effects of this change?

Before: test allocates small folios with 64KB alignment (ALIGNMENT_MTHP) when only 4KB alignment (ALIGNMENT_SMALLFOLIO) is needed. This wastes address space and may cause allocation failures on systems with fragmented memory. Worst-case impact: this only affects thp_swap_allocator_test tool behavior.

-Kaushlendra