I've written a simple dotnet
app that allocates memory. It uses up all the physical memory on the machine and then crashes with an OutOfMemoryException
. However my system has a swap file and it is never used by dotnet
. Other applications use swap just fine. I have played with the swappiness (60, 100, 1) but this had no effect.
My understanding is that a process on Linux can consume all the physical memory it wants and if there is no memory left that memory will be written to the swap file/partition. Only when the swap and physical memory are both full should an application crash with an OOM. This is what other applications do but not dotnet
applications.
I have tried dotnet core 3.1 and 5.0, the OS used was Ubuntu 20.04.
EDIT: my test code:
namespace TestProject
{
class Program
{
static List<byte[]> l = new List<byte[]>();
static void Main(string[] args)
{
while (true)
{
var b = new byte[100 * 1000 * 1024];
l.Add(b);
}
}
}
}