-
Notifications
You must be signed in to change notification settings - Fork 225
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
Correct macOS Free and Available Memory #906
base: master
Are you sure you want to change the base?
Conversation
Code used is taken right out of Apple's official [top(1)](https://github.com/apple-opensource/top/blob/e7979606cf63270663a62cfe69f82d35cef9ba58/globalstats.c#L433) utility for macOS. Observing Apple's code at a first glance, it makes no sense why `vmstat.free_count * pagesize` would not be correct as that appears to be exactly what they are using to calculate free memory. However, I must be missing something, because `vmstat.free_count * pagesize` does not match the "unused memory" value shown when running [top(1)](https://github.com/apple-opensource/top/blob/e7979606cf63270663a62cfe69f82d35cef9ba58/globalstats.c#L433). It shows *way* less than that... Instead, the correct value shown in [top(1)](https://github.com/apple-opensource/top/blob/e7979606cf63270663a62cfe69f82d35cef9ba58/globalstats.c#L433) corresponds to the value provided from how [top(1)](https://github.com/apple-opensource/top/blob/e7979606cf63270663a62cfe69f82d35cef9ba58/globalstats.c#L433) calculates used memory, while subtracting that from total memory. Makes no sense, I know. But this code is correct now and actually matches what is shown in [top(1)](https://github.com/apple-opensource/top/blob/e7979606cf63270663a62cfe69f82d35cef9ba58/globalstats.c#L433), which can be verified easily from testing if you like. Edit: I forgot how to squash commits, so please be patient with me while I try to figure that one out. Edit 2: I also have a system information utility I wrote which uses the same code underneath for RAM usage stats, as the code used in this pull request, in case you wanted something quick and easy to test and compare with [top(1)](https://github.com/apple-opensource/top/blob/e7979606cf63270663a62cfe69f82d35cef9ba58/globalstats.c#L433): ``` git clone https://github.com/time-killer-games/sysinfo $HOME/sysinfo && $HOME/sysinfo/build.sh ``` In this outdated screenshot you can see what free RAM used to look like back when I based it on `vmstat.free_count * pagesize` like you guys currently do: ![macos](https://github.com/user-attachments/assets/a3dc259a-c01c-4dd0-b38a-c0211a4f0be8) As you can see `vmstat.free_count * pagesize` is a lot smaller than what the actual free memory should reasonably be with only one app opened in the entire desktop. I highly doubt 260.39 MB free out of 8 GB of memory total is accurate given how little resources it takes to run that app.
Some interesting points were brought up in my pull request on fastfetch we might want to consider: fastfetch-cli/fastfetch#1463 (comment)
Also wanted you to consider my response to them: fastfetch-cli/fastfetch#1463 (comment)
I'll leave it up to you all if this approach is correct or not. |
Everyone is on a bit of a holiday break, but I'll make sure to get some eyes on this once it's over. Feel free to ping me (andevrs) on discord. |
Code used is taken right out of Apple's official top(1) utility for macOS. Observing Apple's code at a first glance, it makes no sense why
vmstat.free_count * pagesize
would not be correct as that appears to be exactly what they are using to calculate free memory. However, I must be missing something, becausevmstat.free_count * pagesize
does not match the "unused memory" value shown when running top(1). It shows way less than that...Instead, the correct value shown in top(1) corresponds to the value provided from how top(1) calculates used memory, while subtracting that from total memory. Makes no sense, I know. But this code is correct now and actually matches what is shown in top(1), which can be verified easily from testing if you like.
Edit:
I forgot how to squash commits, so please be patient with me while I try to figure that one out.
Edit 2:
I also have a system information utility I wrote which uses the same code underneath for RAM usage stats, as the code used in this pull request, in case you wanted something quick and easy to test and compare with top(1):
In this outdated screenshot you can see what free RAM used to look like back when I based it on
vmstat.free_count * pagesize
like you guys currently do:As you can see
vmstat.free_count * pagesize
is a lot smaller than what the actual free memory should reasonably be with only one app opened in the entire desktop. I highly doubt 260.39 MB free out of 8 GB of memory total is accurate given how little resources it takes to run that app.