Skip to content

gSystem->GetMemInfo reports wrong used RAM memory #7196

Open
@ferdymercury

Description

@ferdymercury

Describe the bug

On Linux, ROOT reports most of the RAM is full, even if it is free. Probably because it reports:

used = total - free
instead of
used = total - free - cached = total - available

See:

meminfo->fMemUsed = meminfo->fMemTotal - meminfo->fMemFree;

/opt/root_bld/tutorials/gui $ root -l
root [0] MemInfo_t memInfo; gSystem->GetMemInfo(&memInfo);
root [1] cout << memInfo.fMemTotal << " " << memInfo.fMemUsed << " " << memInfo.fMemFree << endl;
15933 15381 552
root [2] .q
/opt/root_bld/tutorials/gui $ free -h
              total        used        free      shared  buff/cache   available
Mem:            15G        5.6G        658M        439M        9.3G        9.2G
Swap:          1.0G        135M        888M

Expected behavior

It should report the actual free memory, or add a new variable inside the MemInfo_t struct that specifies the 9.3 'cached' memory, which is actually free to use.

To Reproduce

MemInfo_t memInfo; gSystem->GetMemInfo(&memInfo);
cout << memInfo.fMemTotal << " " << memInfo.fMemUsed << " " << memInfo.fMemFree << endl;

or
/opt/root_bld/tutorials/gui $ root -l CPUMeter.C

Setup

  1. ROOT version: 6.23/01
  2. Operating system: Ubuntu 18
  3. Self-built

Additional context

https://www.thegeekdiary.com/understanding-proc-meminfo-file-analyzing-memory-utilization-in-linux/

My suggestion to solve this would be to do:

  if (s.BeginsWith("MemAvailable")) {
     TPRegexp("^.+: *([^ ]+).*").Substitute(s, "$1");
     meminfo->fMemAvailable = (s.Atoi() / 1024);
  }

meminfo->fMemUsed = meminfo->fMemTotal - meminfo->fMemAvailable;

and then in https://root.cern/doc/master/structMemInfo__t.html#a62b63e5e24efd2e2b5d0f60456e239d6:

Int_t fMemAvailable; // available RAM in MB

For the SWAP it's probably not necessary.

Not sure if the same issue happens for other OS.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Stuck - need help

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions