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

Guard against -1 Returned from sysconf for the Cache Sizes Causing Large Gen0 Sizes and Budgets for Certain Linux Distributions. #100502

Merged
merged 14 commits into from
Apr 3, 2024
12 changes: 8 additions & 4 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ bool ReadMemoryValueFromFile(const char* filename, uint64_t* val)
return result;
}

#define UPDATE_CACHE_SIZE_AND_LEVEL(NEW_CACHE_SIZE, NEW_CACHE_LEVEL) if (NEW_CACHE_SIZE > cacheSize) { cacheSize = NEW_CACHE_SIZE; cacheLevel = NEW_CACHE_LEVEL; }
#define UPDATE_CACHE_SIZE_AND_LEVEL(NEW_CACHE_SIZE, NEW_CACHE_LEVEL) if ((NEW_CACHE_SIZE != SIZE_MAX) && (NEW_CACHE_SIZE > cacheSize)) { cacheSize = NEW_CACHE_SIZE; cacheLevel = NEW_CACHE_LEVEL; }
mrsharm marked this conversation as resolved.
Show resolved Hide resolved

static size_t GetLogicalProcessorCacheSizeFromOS()
{
Expand Down Expand Up @@ -912,7 +912,9 @@ static size_t GetLogicalProcessorCacheSizeFromOS()
{
path_to_size_file[index] = (char)(48 + i);

if (ReadMemoryValueFromFile(path_to_size_file, &size))
// Only accept reading cache sizes from size files if they are
// non-bogus values i.e., non-zero and != SIZE_MAX.
if (ReadMemoryValueFromFile(path_to_size_file, &size) && ((size != SIZE_MAX) || (size != 0)))
mrsharm marked this conversation as resolved.
Show resolved Hide resolved
{
path_to_level_file[index] = (char)(48 + i);

Expand All @@ -930,7 +932,7 @@ static size_t GetLogicalProcessorCacheSizeFromOS()
#endif

#if (defined(HOST_ARM64) || defined(HOST_LOONGARCH64)) && !defined(TARGET_APPLE)
if (cacheSize == 0)
if (cacheSize == 0 || cacheSize == SIZE_MAX)
{
// We expect to get the L3 cache size for Arm64 but currently expected to be missing that info
// from most of the machines.
Expand Down Expand Up @@ -958,7 +960,7 @@ static size_t GetLogicalProcessorCacheSizeFromOS()
#endif

#if HAVE_SYSCTLBYNAME
if (cacheSize == 0)
if (cacheSize == 0 || cacheSize == SIZE_MAX)
{
int64_t cacheSizeFromSysctl = 0;
size_t sz = sizeof(cacheSizeFromSysctl);
Expand All @@ -974,6 +976,7 @@ static size_t GetLogicalProcessorCacheSizeFromOS()
if (success)
{
assert(cacheSizeFromSysctl > 0);
assert(cacheSizeFromSysctl != SIZE_MAX);
cacheSize = ( size_t) cacheSizeFromSysctl;
}
}
Expand Down Expand Up @@ -1011,6 +1014,7 @@ static size_t GetLogicalProcessorCacheSizeFromOS()
}
#endif

assert (cacheSize != SIZE_MAX);
return cacheSize;
}

Expand Down
Loading