GithubHelp home page GithubHelp logo

Comments (14)

upccup avatar upccup commented on June 9, 2024

@mwmahlberg i think is will be like

MemUsed := v.Used - v.Buffers - v.Cached

from gopsutil.

mwmahlberg avatar mwmahlberg commented on June 9, 2024

@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.

upccup avatar upccup commented on June 9, 2024

@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.

mwmahlberg avatar mwmahlberg commented on June 9, 2024

@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.

walles avatar walles commented on June 9, 2024

@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.

walles avatar walles commented on June 9, 2024

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.

sparrc avatar sparrc commented on June 9, 2024

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.

walles avatar walles commented on June 9, 2024

@sparrc, do you have a reference for where Used is documented as a linux kernel term?

from gopsutil.

sparrc avatar sparrc commented on June 9, 2024

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.

sparrc avatar sparrc commented on June 9, 2024

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.

mwmahlberg avatar mwmahlberg commented on June 9, 2024

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.

walles avatar walles commented on June 9, 2024

@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.

rogercoll avatar rogercoll commented on June 9, 2024

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):

image

cc @walles @mwmahlberg

from gopsutil.

mwmahlberg avatar mwmahlberg commented on June 9, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.