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.freemem() under Linux #27493

Closed
morgan-wild opened this issue Apr 30, 2019 · 9 comments · Fixed by #27718
Closed

Os.freemem() under Linux #27493

morgan-wild opened this issue Apr 30, 2019 · 9 comments · Fixed by #27718
Labels
memory Issues and PRs related to the memory management or memory footprint. os Issues and PRs related to the os subsystem.

Comments

@morgan-wild
Copy link

Version: 10.15.3 (LTS)
Platform: Linux (Ubuntu server 18.10)
Subsystem: Os.freemem()
Under Linux, Os.freemem() returns the used memory instead of the free one.

os freemem

@bnoordhuis
Copy link
Member

Similar to #27386?

Node.js pulls its information straight from the OS by means of the sysinfo(2) system call. If you see the wrong numbers, you've found a kernel bug.

What does cat /proc/meminfo print?

@morgan-wild
Copy link
Author

Thank you for your fast answer!

As asked :

Sans titre 2

@ChALkeR ChALkeR added os Issues and PRs related to the os subsystem. memory Issues and PRs related to the memory management or memory footprint. labels Apr 30, 2019
@bnoordhuis
Copy link
Member

Okay, I think I have an inkling of the cause.

Can you post the output of uname -a, node -p process.arch and the contents of the memory.limit_in_bytes and memory.soft_limit_in_bytes files in /sys/fs/cgroup/memory? Thanks!

@morgan-wild
Copy link
Author

Fore sure, thanks for your help!

Sans titre 2

@morgan-wild
Copy link
Author

I tried the same thing on another distro (Fedora instead of Ubuntu Server) and it works normally.

Ubuntu is in cause.

Sans titre 2

@bnoordhuis
Copy link
Member

My inkling was that this might have been a 32-to-64-bit (or vice versa) kernel compatibility issue but if both kernel and binary are 64 bits, that can't be it. It's probably still a kernel bug, just not that one. :-)

On the bright side, Node.js will start preferring /proc/meminfo over sysinfo(2) in the near future (libuv/libuv#2258) so this issue should cease to exist before too long.

@morgan-wild
Copy link
Author

Thank you for your anwser.
I will wait to try again with the future versions of nodejs.

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 <refack@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
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 <refack@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
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 <refack@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
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 <refack@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@justb
Copy link

justb commented Aug 22, 2022

Any update on this? Still happened at Node.js v16

@bnoordhuis
Copy link
Member

@justb That probably means you don't have /proc mounted or /proc/meminfo doesn't have the expected format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
memory Issues and PRs related to the memory management or memory footprint. os Issues and PRs related to the os subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants