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

os.totalmem() missleading output in docker-container with memory-limit #51095

Closed
the-hotmann opened this issue Dec 8, 2023 · 4 comments
Closed
Labels
libuv Issues and PRs related to the libuv dependency or the uv binding. os Issues and PRs related to the os subsystem.

Comments

@the-hotmann
Copy link

the-hotmann commented Dec 8, 2023

Version

v18.17.0

Platform

Linux wikijs 6.5.0-5-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.5.13-1 (2023-11-29) x86_64 Linux

What steps will reproduce the bug?

Use any NodeJS Dockercontainer and limit its memory down to any number.
Now check `os.totalmem()` - it will still report the whole memory of the VM/Machine, not the limited memory of the container, but it should report the total available Memory, which in a memory limited container is not the whole Memory of the machine.

How often does it reproduce? Is there a required condition?

Everytime

What is the expected behavior? Why is that the expected behavior?

VM = 12GB RAM
Docker container = 300MB RAM

When I run `os.totalmem()` in the docker-container it reports 12GB RAM.

What do you see instead?

requarks/wiki#6863

@VoltrexKeyva VoltrexKeyva added the os Issues and PRs related to the os subsystem. label Dec 8, 2023
@jfhr
Copy link

jfhr commented Dec 8, 2023

You can probably get the memory limit inside the container via cgget as described by this thread on StackOverflow.com.

Depending on the Docker version you might be able to read either /sys/fs/cgroup/memory/memory.limit_in_bytes or /sys/fs/cgroup/memory.max, which contain the container memory limit in bytes as an integer.

@MrJithil MrJithil added the libuv Issues and PRs related to the libuv dependency or the uv binding. label Dec 9, 2023
@MrJithil
Copy link
Member

MrJithil commented Dec 9, 2023

This is working as expected and currently, we don't have an property which will show the max memory limit in the os module.

You may try with the process.constrainedMemory() || 0 where 0 will be no_limit as a workaround. It would be very helpful, if you can provide the output after running this suggestion.

Also, I have created a PR to address this #51102

@juanarbol
Copy link
Member

Could be related to #27170

@targos
Copy link
Member

targos commented Dec 15, 2023

process.constrainedMemory() is the right API for that.

@targos targos closed this as completed Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libuv Issues and PRs related to the libuv dependency or the uv binding. os Issues and PRs related to the os subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants