Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check presence of Hugepagesize field #594

Merged
merged 3 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tbbmalloc/shared_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ T min ( const T& val1, const T& val2 ) {
// TODO: add a constructor to remove warnings suppression
struct parseFileItem {
const char* format;
unsigned long long& value;
long long& value;
};

#if defined(_MSC_VER) && (_MSC_VER<1900) && !defined(__INTEL_COMPILER)
Expand Down
18 changes: 9 additions & 9 deletions src/tbbmalloc/tbbmalloc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,31 +447,31 @@ class HugePagesStatus {
void parseSystemMemInfo() {
bool hpAvailable = false;
bool thpAvailable = false;
unsigned long long hugePageSize = 0;
long long hugePageSize = -1;

#if __unix__
// Check huge pages existence
unsigned long long meminfoHugePagesTotal = 0;
long long meminfoHugePagesTotal = 0;

parseFileItem meminfoItems[] = {
// Parse system huge page size
{ "Hugepagesize: %llu kB", hugePageSize },
{ "Hugepagesize: %lld kB", hugePageSize },
// Check if there are preallocated huge pages on the system
// https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
{ "HugePages_Total: %llu", meminfoHugePagesTotal } };
{ "HugePages_Total: %lld", meminfoHugePagesTotal } };

parseFile</*BUFF_SIZE=*/100>("/proc/meminfo", meminfoItems);

// Double check another system information regarding preallocated
// huge pages if there are no information in /proc/meminfo
unsigned long long vmHugePagesTotal = 0;
long long vmHugePagesTotal = 0;

parseFileItem vmItem[] = { { "%llu", vmHugePagesTotal } };
parseFileItem vmItem[] = { { "%lld", vmHugePagesTotal } };
isaevil marked this conversation as resolved.
Show resolved Hide resolved

// 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 (hugePageSize > -1 && (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 @@ -480,11 +480,11 @@ class HugePagesStatus {
}

// Check if there is transparent huge pages support on the system
unsigned long long thpPresent = 'n';
long long thpPresent = 'n';
parseFileItem thpItem[] = { { "[alwa%cs] madvise never\n", thpPresent } };
parseFile</*BUFF_SIZE=*/100>("/sys/kernel/mm/transparent_hugepage/enabled", thpItem);

if (thpPresent == 'y') {
if (hugePageSize > -1 && thpPresent == 'y') {
MALLOC_ASSERT(hugePageSize != 0, "Huge Page size can't be zero if we found thp existence.");
thpAvailable = true;
}
Expand Down
21 changes: 13 additions & 8 deletions test/common/memory_usage.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,32 @@ namespace utils {
#if __unix__

inline bool isTHPEnabledOnMachine() {
unsigned long long thpPresent = 'n';
long long thpPresent = 'n';
long long hugePageSize = -1;

parseFileItem thpItem[] = { { "[alwa%cs] madvise never\n", thpPresent } };
parseFileItem hpSizeItem[] = { { "Hugepagesize: %lld kB", hugePageSize } };

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

if (thpPresent == 'y') {
if (hugePageSize > -1 && thpPresent == 'y') {
return true;
} else {
return false;
}
}
inline unsigned long long getSystemTHPAllocatedSize() {
unsigned long long anonHugePagesSize = 0;
inline long long getSystemTHPAllocatedSize() {
long long anonHugePagesSize = 0;
parseFileItem meminfoItems[] = {
{ "AnonHugePages: %llu kB", anonHugePagesSize } };
{ "AnonHugePages: %lld kB", anonHugePagesSize } };
parseFile</*BUFF_SIZE=*/100>("/proc/meminfo", meminfoItems);
return anonHugePagesSize;
}
inline unsigned long long getSystemTHPCount() {
unsigned long long anonHugePages = 0;
inline long long getSystemTHPCount() {
long long anonHugePages = 0;
parseFileItem vmstatItems[] = {
{ "nr_anon_transparent_hugepages %llu", anonHugePages } };
{ "nr_anon_transparent_hugepages %lld", anonHugePages } };
parseFile</*BUFF_SIZE=*/100>("/proc/vmstat", vmstatItems);
return anonHugePages;
}
Expand Down