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() incorrect when called on container (LXD) #27170

Closed
voxsoftware opened this issue Apr 10, 2019 · 1 comment · Fixed by #27718
Closed

os.totalmem() incorrect when called on container (LXD) #27170

voxsoftware opened this issue Apr 10, 2019 · 1 comment · Fixed by #27718
Labels
libuv Issues and PRs related to the libuv dependency or the uv binding. os Issues and PRs related to the os subsystem.

Comments

@voxsoftware
Copy link

os.totalmem() reports an invalid value when use on a continaer - tested on lxd -
How reproduce:

apt install lxd 
lxd init 
# .....

lxc launch ubuntu:18.04 machine1
lxc config set machine1 limits.memory 2500MB
lxc exec machine1 /bin/bash

# install node ......
node 
> os.totalmem()
32xxxxxxxxxx // 32GB 
# result here is the total memory of host no the container

htop shows the correct value
good htop

@bnoordhuis bnoordhuis added libuv Issues and PRs related to the libuv dependency or the uv binding. os Issues and PRs related to the os subsystem. labels Apr 10, 2019
@bnoordhuis
Copy link
Member

os.totalmem() makes a sysinfo(2) system call to get the total memory (IOW, it merely reports what the operating system reports); htop on the other hand reads from /proc/meminfo, which lxcfs intercepts.

Libuv prefers sysinfo(2) for reasons of portability and robustness (/proc isn't always mounted) but I guess it could try /proc/meminfo first and fall back to sysinfo(2).

I'll close this out and open a new issue over at libuv/libuv. Thanks for the report.

cjihrig added a commit to cjihrig/node that referenced this issue May 21, 2019
Notable changes:

- uv_get_constrained_memory() has been added.
- A race condition in uv_async_send() has been fixed.
- uv_get_free_memory() and uv_get_total_memory() now read from
  /proc/meminfo, which should improve correctness when called
  from inside an lxc container.
- A failed assertion in uv_fs_poll_stop() has been fixed.
- A bug in MAC addresses for IP-aliases has been fixed.

Fixes: nodejs#27170
Fixes: nodejs#27493
PR-URL: nodejs#27718
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
BridgeAR pushed a commit that referenced this issue May 22, 2019
Notable changes:

- uv_get_constrained_memory() has been added.
- A race condition in uv_async_send() has been fixed.
- uv_get_free_memory() and uv_get_total_memory() now read from
  /proc/meminfo, which should improve correctness when called
  from inside an lxc container.
- A failed assertion in uv_fs_poll_stop() has been fixed.
- A bug in MAC addresses for IP-aliases has been fixed.

Fixes: #27170
Fixes: #27493
PR-URL: #27718
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
BethGriggs pushed a commit to BethGriggs/node that referenced this issue Feb 26, 2020
Notable changes:

- uv_get_constrained_memory() has been added.
- A race condition in uv_async_send() has been fixed.
- uv_get_free_memory() and uv_get_total_memory() now read from
  /proc/meminfo, which should improve correctness when called
  from inside an lxc container.
- A failed assertion in uv_fs_poll_stop() has been fixed.
- A bug in MAC addresses for IP-aliases has been fixed.

Fixes: nodejs#27170
Fixes: nodejs#27493
PR-URL: nodejs#27718
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
BethGriggs pushed a commit that referenced this issue Mar 2, 2020
Notable changes:

- uv_get_constrained_memory() has been added.
- A race condition in uv_async_send() has been fixed.
- uv_get_free_memory() and uv_get_total_memory() now read from
  /proc/meminfo, which should improve correctness when called
  from inside an lxc container.
- A failed assertion in uv_fs_poll_stop() has been fixed.
- A bug in MAC addresses for IP-aliases has been fixed.

Fixes: #27170
Fixes: #27493
PR-URL: #27718
Backport-PR-URL: #31969
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
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.

2 participants