Skip to content

OS API is missing available memory call in NodeJS #31243

Closed

Description

@melroy89
  • Version: all
  • Platform: Unix
  • Subsystem: -

The free commands says actually that I have 1832 MBs available, which is the free amount + some part of the buff/cache that can be cleared directly when needed.

The free column should be small, since this is memory which is not used is simply wasted. Available memory is the amount of memory which is available for allocation to a new process or to existing processes.

$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7971        5907         149         135        1914        1832
Swap:          9541        2122        7419

Knowing all this, the NodeJs OS API (var os = require('os')) only provides os.freemem and os.totalmem. The free memory NodeJS API call indeed shows the same value as what the free command gives me. But the OS API does NOT have any call like: os.availablemem or something simular.

Bottom-line: I'm missing the available memory call in NodeJS. Which is often way more useful.

For info:

Regards,
Melroy van den Berg

Activity

  1. added
    feature requestIssues requesting new Node.js features.
    libuvIssues and PRs related to the libuv dependency or the uv binding.
    linuxIssues and PRs related to the Linux platform.
    on Jan 7, 2020
  2. bnoordhuis commented on Jan 7, 2020

    @bnoordhuis
    Member

    This is ultimately a libuv issue because node calls uv_get_free_memory() and that in turn either reads /proc/meminfo (parsing the MemFree: field) or makes a sysinfo(2) system call (reading the freeram field.)

    /proc/meminfo has a MemAvailable: field and sysinfo(2) lets you approximate it via the bufferram field so you could start by opening a libuv pull request if you want to move forward with this. On other platforms, you could just do:

    uint64_t uv_get_available_memory(void) {
      return uv_get_free_memory();
    }

    That said...

    I'm missing the available memory call in NodeJS. Which is often way more useful.

    ...if you plan on using it as an input signal for e.g. "can I start this memory-consuming program?" then it's probably the wrong approach - it's a snapshot of a dynamic situation, one that may have changed dramatically in the time window between the call and the exec.

  3. melroy89 commented on Jan 7, 2020

    @melroy89
    Author

    OK, Yea let's see what's the best solution for fetching this number.

    It's not for determining for starting memory heavy apps. I actually noticed this usage of 'free memory' on the system information page of Wekan, admin panel.

    Wekan is an open source to-do manager, using nodejs. I was in panic when application was saying I only had about 100mb free of memory. But actually I think the available memory should be reported in these kind of instances.

  4. mhdawson commented on Jan 7, 2020

    @mhdawson
    Member

    +1 on discussing in a TSC meeting before landing.

  5. github-actions commented on Mar 4, 2022

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

  6. bnoordhuis commented on Mar 4, 2022

    @bnoordhuis
    Member

    The MemFree -> MemAvailable change was made in libuv/libuv#3351 and is available in v16.x+ so I think this issue is good to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.libuvIssues and PRs related to the libuv dependency or the uv binding.linuxIssues and PRs related to the Linux platform.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions