Skip to content

Commit

Permalink
Check presence of Hugepagesize field
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Isaev <[email protected]>
  • Loading branch information
isaevil committed Sep 30, 2021
1 parent f13f3ef commit f90e202
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/tbbmalloc/tbbmalloc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ class HugePagesStatus {
bool hpAvailable = false;
bool thpAvailable = false;
unsigned long long hugePageSize = 0;
unsigned long long hugePageSizePresent = 0;

#if __unix__
// Check huge pages existence
Expand All @@ -456,6 +457,7 @@ class HugePagesStatus {
parseFileItem meminfoItems[] = {
// Parse system huge page size
{ "Hugepagesize: %llu kB", hugePageSize },
{ "Hugepagesiz%c:", hugePageSizePresent },
// Check if there are preallocated huge pages on the system
// https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
{ "HugePages_Total: %llu", meminfoHugePagesTotal } };
Expand All @@ -471,7 +473,7 @@ class HugePagesStatus {
// We parse a counter number, it can't be huge
parseFile</*BUFF_SIZE=*/100>("/proc/sys/vm/nr_hugepages", vmItem);

if (meminfoHugePagesTotal > 0 || vmHugePagesTotal > 0) {
if (hugePageSizePresent == 'e' && (meminfoHugePagesTotal > 0 || vmHugePagesTotal > 0)) {
MALLOC_ASSERT(hugePageSize != 0, "Huge Page size can't be zero if we found preallocated.");

// Any non zero value clearly states that there are preallocated
Expand All @@ -484,7 +486,7 @@ class HugePagesStatus {
parseFileItem thpItem[] = { { "[alwa%cs] madvise never\n", thpPresent } };
parseFile</*BUFF_SIZE=*/100>("/sys/kernel/mm/transparent_hugepage/enabled", thpItem);

if (thpPresent == 'y') {
if (thpPresent == 'y' && hugePageSizePresent == 'e') {
MALLOC_ASSERT(hugePageSize != 0, "Huge Page size can't be zero if we found thp existence.");
thpAvailable = true;
}
Expand Down
7 changes: 6 additions & 1 deletion test/common/memory_usage.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,15 @@ namespace utils {

inline bool isTHPEnabledOnMachine() {
unsigned long long thpPresent = 'n';
unsigned long long hugePageSizePresent = 0;

parseFileItem thpItem[] = { { "[alwa%cs] madvise never\n", thpPresent } };
parseFileItem hpSizeItem[] = { { "Hugepagesiz%c:", hugePageSizePresent } };

parseFile</*BUFF_SIZE=*/100>("/sys/kernel/mm/transparent_hugepage/enabled", thpItem);
parseFile</*BUFF_SIZE=*/100>("/proc/meminfo", hpSizeItem);

if (thpPresent == 'y') {
if (hugePageSizePresent == 'e' && thpPresent == 'y') {
return true;
} else {
return false;
Expand Down

0 comments on commit f90e202

Please sign in to comment.