Skip to content

Commit

Permalink
CPLGetPhysicalRAM(): fix getting right value when running inside Dock…
Browse files Browse the repository at this point in the history
…er on a cgroups v1 system (like Amazon Linux 2) (fixes #8968)
  • Loading branch information
rouault committed Dec 16, 2023
1 parent 66f5be9 commit 5b135a1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion port/cpl_vsisimple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,9 @@ GIntBig CPLGetPhysicalRAM(void)
{
// cgroup V1
// Read memory.limit_in_byte in the whole szGroupName hierarchy
// Make sure to end up by reading
// /sys/fs/cgroup/memory/memory.limit_in_bytes itself, for
// scenarios like https://github.com/OSGeo/gdal/issues/8968
while (true)
{
snprintf(szFilename, sizeof(szFilename),
Expand All @@ -1477,7 +1480,7 @@ GIntBig CPLGetPhysicalRAM(void)
std::min(static_cast<GUIntBig>(nVal), nLimit));
}
char *pszLastSlash = strrchr(szGroupName, '/');
if (!pszLastSlash || pszLastSlash == szGroupName)
if (!pszLastSlash)
break;
*pszLastSlash = '\0';
}
Expand Down

0 comments on commit 5b135a1

Please sign in to comment.