I have been trying to use transparent hugepages in my application. For, this I have correctly configured my system with /sys/kernel/mm/transparent_hugepage/enabled
set to [madvise]
. I am allocating a mempool using boost::interprocess in /dev/shm
and trying to later map this memory to hugepages using madvise. As can be seen in the snippet below :
int64_t ptr = (int64_t)mempool_;
ptr = ((ptr >> 21) + 1) << 21; // For aligning to hugepage boundary
int ret_val = madvise((void*)ptr, 2 * 1024 * 1024, MADV_HUGEPAGE);
cout << "start : " << (void*)ptr << endl;
cout << "end : " << (void*)(ptr + 2 * 1024 * 1024) << endl;
cout << "Return value of madvise() : " << ret_val << endl;
cout << "Errno set to : " << errno << endl;
cout << "Error on madvise: " << strerror( errno ) << endl;
The output of this snippet is :
start : 0x7f2d17400000
end : 0x7f2d17600000
Return value of madvise() : 0
Errno set to : 0
Error on madvise: Success
It, seems everything is right but hugepages are not allocated in my system. I do not understand why is this happening ? I let my program run sufficiently long enough for khugepaged to get scheduled. For my system
scan_sleep_millisecs : 10000
alloc_sleep_millisecs: 60000