The transparent huge page shrinker
The transparent huge page shrinker
Posted Sep 10, 2022 18:23 UTC (Sat) by WolfWings (subscriber, #56790)In reply to: The transparent huge page shrinker by linoliumz
Parent article: The transparent huge page shrinker
I guess that's my point: It is enabled by default and has been for almost a decade now, just behind madvise where the interface to use it becomes trivial.
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h> // Also used for various posix functions, cross platform
const int alignment = 1 << 21;
const int size = 16 << 21;
int main( void ) {
void *x = aligned_alloc( alignment, size );
#ifdef MADV_HUGEPAGE
if ( x != NULL ) {
madvise( x, size, MADV_HUGEPAGE );
}
#endif
printf( "Go run: grep -i hugepage /proc/meminfo\nPausing for 60 seconds.\n" );
sleep( 60 );
return 0;
}
