Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 6046

How to allow full use of all available swap space by a process running inside a Docker container

$
0
0

I have written a test Node app which eats memory (in 100MB chunks). I am trying to get it to continue allocating memory beyond the physical memory limit of 8GB by using the swap space (16GB) which is configured on the Ubuntu (Ubuntu 20.04.4 LTS) box it is running on.

This is working fine when running in Node, like this (no container):

node --max-old-space-size=16384 ./memtest/memtest.js

When I run it inside a Docker container, it is being terminated at the limit of physical memory (8GB). Actually it seems to be killed before this at around 3gb. Even with 5gb free it is killed at 3gb.

I have tried some Docker options to try and get it to use the swap space, but it's still getting killed at the same point as with the default memory configuration.

docker run -m 8g --memory-swap -1 --memory-swappiness 100 ...Amount allocated before container is killed: 3037.08 MB# swapon --showNAME      TYPE SIZE USED PRIO/swapfile file  16G 187M   -2# free              total        used        free      shared  buff/cache   availableMem:        8148324     1022788     5538364         124     1587172     6813484Swap:      16777212      191228    16585984

From the docs below it would appear that the default behaviour should be to allow unbounded use of memory + swap - as I am trying to achieve. However, I am not seeing this.

https://docs.docker.com/config/containers/resource_constraints/

I am seeking to understand the reason why the behaviour is different inside Docker and how to allow full use of all available swap spacewhen the process is running inside a Docker container.

NB I am not using Docker Desktop, this question is not about Docker Desktop.

UPDATE:

Here is the JS code I'm using to test with:

const bufs = [];

function testMemory() {  setInterval(() => {    console.log(`${(process.memoryUsage().heapUsed / (1024 * 1024)).toFixed(2)} MB`);//    bufs.push(new Array(1e7));  }, 100);}testMemory();

Viewing all articles
Browse latest Browse all 6046

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>