Skip to content

sys_mem: check /proc/meminfo to get available memory #598

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

evetsso
Copy link
Contributor

@evetsso evetsso commented Jun 13, 2025

sysinfo(2) is unaware of cache, but we can still fall back to it in case /proc/meminfo isn't available.

After testing some more on my integrated gfx1035 I realized #595 is too pessimistic. sysinfo(2) is unable to get the same information that free(1) gets, and we're really interested in the "available" number.

So for example, with 32 GiB system memory (16 GiB allocated to GPU) free says I have 12 GiB free and 11 GiB cached (23 GiB available). With the code that only looks at sysinfo none of the test cases will run - when we take away the 16 GiB for the GPU from 12 GIB free, there's nothing left.

free(1) ultimately looks at /proc/meminfo to know its numbers so just look there first.

sysinfo(2) is unaware of cache, but we can still fall back to it in case
/proc/meminfo isn't available.
{
std::ifstream proc_meminfo("/proc/meminfo");
std::string proc_line;
while(std::getline(proc_meminfo, proc_line))

Choose a reason for hiding this comment

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

Shall we check proc_meminfo.is_open() first, maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getline will fail if the file couldn't be opened, so I don't think it'll make a difference in behaviour?

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.

2 participants