[PATCH v5 1/1] Created tunable to force small pages on stack allocation.
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Thu Apr 13 15:43:25 GMT 2023
Hi Adhemerval,
I agree doing this automatically sounds like a better solution.
However:
+static __always_inline int
+advise_thp (void *mem, size_t size, size_t guardsize)
+{
+ enum malloc_thp_mode_t thpmode = __malloc_thp_mode ();
+ if (thpmode != malloc_thp_mode_always)
+ return 0;
+
+ unsigned long int thpsize = __malloc_default_thp_pagesize ();
+ if ((uintptr_t) mem % thpsize != 0
+ || size % thpsize != 0
+ || (size - guardsize) % thpsize != 0)
+ return 0;
Isn't the last part always true currently given the guard page size is based on
the standard page size? IIRC the issue was the mmap succeeds but the guard
page is taken from the original mmap which then causes the decomposition.
So you'd need something like:
|| guardsize % thpsize == 0)
Ie. we return without the madvise if the size and alignment is wrong for a huge
page or it is correct and the guardsize is a multiple of a huge page (in which
case it shouldn't decompose).
+ return __madvise (mem, size, MADV_NOHUGEPAGE);
+}
Cheers,
Wilco
More information about the Libc-alpha
mailing list