<div dir="ltr">Hi all,<div><br></div><div>I am running into an issue where GDAL is overestimating the amount of physical memory it has leading to it locking up the OS by taking 100% of the memory. Here is an example program that illustrates the issue:<br><br><font face="monospace">#include <stdio.h><br>#include "gdal.h"<br><br>int main(void) {<br>  Â printf("GDAL version is %s\n", GDALVersionInfo("RELEASE_NAME"));<br>  Â printf("GDAL thinks is has %lld bytes of physical memory\n", CPLGetPhysicalRAM());<br>  Â printf("GDAL thinks it has %lld bytes of usable physical memory\n", CPLGetUsablePhysicalRAM());<br>  Â return 0;<br>}</font><br></div><div><font face="monospace"><br></font></div><div>When this is compiled with GDAL 3.5.1 on Ubuntu 22.04 we get:<br></div><div><br></div><div><font face="monospace">$ ./get_gdal_memory </font><br><font face="monospace">GDAL version is 3.5.1</font><br><font face="monospace">GDAL thinks is has 811526475776 bytes of physical memory</font><br><font face="monospace">GDAL thinks it has 811526475776 bytes of usable physical memory</font><br><br><font face="arial, sans-serif">Which is not consistent with the actual available memory:</font></div><div><font face="monospace"><br>$ free -h<br>  Â  Â  Â  Â  Â  Â  Â total Â  Â  Â  Â used Â  Â  Â  Â free Â  Â  Â shared Â buff/cache Â  available<br>Mem: Â  Â  Â  Â  Â  2.0Gi Â  Â  Â  148Mi Â  Â  Â  1.2Gi Â  Â  Â  0.0Ki Â  Â  Â  639Mi Â  Â  Â  1.8Gi<br>Swap: Â  Â  Â  Â  Â 256Mi Â  Â  Â  Â  Â 0B Â  Â  Â  256Mi</font><br></div><div><font face="monospace"><br></font></div><div><font face="arial, sans-serif">So GDAL thinks it has 755GB of memory but it only has 2GB, this causes issues with the raster read cache and maybe elsewhere. I suspect this is happening because it is running in a <a href="https://linuxcontainers.org/">Linux container</a> and GDAL is getting the total physical memory of the host, not the container. The strange thing is Linux containers use cgroups for memory restrictions and the API docs <a href="https://gdal.org/api/cpl.html#_CPPv417CPLGetPhysicalRAMv">mention it was fixed in GDAL 2.4.0</a> but I am still seeing the issue in 3.5.1.</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Any help or insight would be appreciated; I am happy to provide any additional information or testing.</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Thanks,</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Angus</font></div></div>