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

Include available memory #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dustin-decker
Copy link

@dustin-decker dustin-decker commented Mar 11, 2022

From the discussion in #9, this is the AvailableMemory() function addition.

It intends to return free+freeable memory.

I think Windows is ready to go as-is, and this adds the change for Linux. Darwin and BSDs remain and I could use some help there.

  • Linux
  • Windows - I think it's using available memory already
  • Darwin
  • BSD

@dustin-decker dustin-decker force-pushed the include-available-memory branch from 1106214 to 0df3723 Compare March 11, 2022 05:15
@waybackarchiver
Copy link

Any news here?

// The total available memory is the free memory + freeable memory
// such as buffer and cache.
//
// If available memory size could not be determined, then 0 is returned.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"If freeable memory size could not be determined, then freeable memory is assumed to be 0"

Seems to fit the semantics of the windows/bsd/darwin stubs a bit better.

@pbnjay
Copy link
Owner

pbnjay commented May 16, 2022

Any news here?

I haven't had time to look into Darwin/BSD implementations. Should be straightforward just need to find/confirm which names to use in the syscalls

// Buffer/cache ram is included on linux since the kernel
// will free this memory for applications if needed, and tends
// to use almost all free memory for itself when it can.
return (uint64(in.Freeram) + uint64(in.Bufferram)) * uint64(in.Unit)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux it's generally better to use MemAvailable from /proc/meminfo. There is a good justification for this in the Linux kernel git commit.

The hard part is there's no simple stdlib syscall that I am aware of that can read this. 🙁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants