Comments (14)
@mwmahlberg i think is will be like
MemUsed := v.Used - v.Buffers - v.Cached
from gopsutil.
@upccup Which still would be misleading. The notion of used should be what actually is used at a given point in time. Reducing by buffers and cached actually shows how much would be available, right?
Available := Total - Used + Buffers + Cached
Unless I am getting something wrong, in which case I'd love to be enlightened. ;)
from gopsutil.
@mwmahlberg You are right. But this is a UNIX system's memory management policies. Only when in use will be released before the memory program. I do not know if I say that will not make you more confused
from gopsutil.
@upccup I investigated this a bit further. The thing is that "available" is just an estimate wether enough memory is available for starting an application, taking into account potentially freeable memory.
So, as a value, there is nothing wrong with Available
. As a base value for RAM utilization, this still seems wrong to me. At least it should be noted.
from gopsutil.
@mwmahlberg, whether to count caches as used or not depends on the use case. What does the requester want to know?
If they want to know how much memory is left before the system starts swapping, caches should be counted as free / available.
If they want to know what percentage of their RAM chips are actually used for storing bits, caches should be counted as used.
I'd argue most people want the former.
Either way, I agree that having documentation for what Used
and UsedPercent
actually means would be good:
https://github.com/shirou/gopsutil/blob/master/mem/mem.go#L10
from gopsutil.
I've started work to clarify this in a branch:
https://github.com/shirou/gopsutil/compare/master...walles:walles/vmtest?expand=1
At the time of writing this comment, the struct has been updated with documentation and I've written tests for the (now) documented behavior.
I haven't updated the implementations on any platform though, so it's not ready to be a PR yet.
from gopsutil.
I don't agree with changing the current implementation. Used memory is a documented linux kernel term: https://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-proc-meminfo.html in that it is the opposite of MemFree, which is exactly how gopsutil calculates it:
MemFree — The amount of physical RAM, in kilobytes, left unused by the system.
from gopsutil.
@sparrc, do you have a reference for where Used
is documented as a linux kernel term?
from gopsutil.
Used is not explicitly documented but MemFree is the "unused" space, which to me means that the used space should just be the opposite of that.
from gopsutil.
which at least for Linux, is how it is currently calculated: https://github.com/shirou/gopsutil/blob/master/mem/mem_linux.go#L54
from gopsutil.
Would be interesting to dig how free
et al calulcate free vs used RAM. I am bound to at least three projects atm, but can investigate after that. @walles As per available RAM, I agree with you. That's what one wants to know: "Can I run something that needs X bytes?" As per RAM utilization however, for example for warning levels, the physical memory utilized seems a lot more reasonable.
from gopsutil.
@mwmahlberg, free
on Linux does used = total - free - buffers - cache
.
I suggest we:
- use kernel specific terms (
Buffers
,Cached
,Wired
etc) for kernel specific values. - use other terminology for human consumable values (
Total
,Available
,Used
)
Can you describe a scenario where you have actually wanted to warn on how the kernel decided to use Available memory? This sounds like an edge case to me, how would you feel about doing Total - Free
(both well documented and available on all platforms) to get this value on any platform?
from gopsutil.
Old issue but I was doing some tests on the used
value and I not am sure if its formula is the most suitable, or if it should be relied when setting memory alerts.
Small function:
func gops(memory mem.VirtualMemoryStat) {
fmt.Println(memory.Total, " Total memory bytes")
fmt.Println(memory.Available, " Available memory bytes")
fmt.Println(memory.Used, " Used memory bytes")
fmt.Println(memory.Total-memory.Available, " Total - Available memory bytes (used v2)")
}
//Output (Rocky linux)
8346812416 Total memory bytes
7641399296 Available memory bytes
323620864 Used memory bytes
705413120 Total - Available memory bytes (not available memory)
I was expecting the latest two values to be very similar, but instead one is less than half the other. The not available memory
is much higher than the used
one. If some alerting systems relies on used
to trigger high usages of memory, its alerts might never trigger.
Would it make sense to move the Used
calculation to a more "sensitive" one?
I made some memory load testing, this are the results (~8% of difference):
from gopsutil.
@rogercoll As said, cached memory needs to be taken into consideration. However, utilization should denote the percentage of physical memory used, imho.
from gopsutil.
Related Issues (20)
- Report a bare-meteral machine as KVM at host.Info HOT 1
- The host.Info() function is unable to correctly identify CentOS Stream 8. HOT 1
- Missing FQDN/hostname option for windows HOT 2
- stat.Rdev (variable of type uint32) as uint64 HOT 4
- Adopt a hierarchy for getting distro name/version on Linux
- Mac OS Apple M1 get cpu info failed "no such file or directory" HOT 3
- Using the gopsutil package causes the goland debugger to not work properly (random jumps)
- ProcTotal Inaccurate in `MiscStats` HOT 4
- : Optimization Request: Reducing the Number of windows.OpenProcess Calls When Gathering Name, CreateTime, and PPID HOT 1
- docker container monitor host resource and usage
- [invoker] set the `WaitDelay` to avoid getting indefinitely blocking wait() HOT 1
- Calling disk.Partitions(false) produces different list on Linux to "df" HOT 1
- `ExeWithContext` returns an error with a Go binary on newer versions of macOS HOT 6
- Inaccurate readings of cpu.Percent
- Allow path to net/dev to not be under HOST_PROC
- Windows interrupt signal errror HOT 1
- Crash in createTimeWithContext when run on FreeBSD arm64 HOT 18
- runtime: program exceeds 10000-thread limit HOT 1
- Builds for netbsd arm fail with `undefined: cpuTimes` HOT 4
- Get current working directory on openbsd HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gopsutil.