How to check how free RAM is available?

How to check how free RAM is available ? Is any call in Julia ? Paul

1 Like

You can use your system routines.
If you are at unix-like:

run(`egrep --color 'Mem|Cache|Swap' /proc/meminfo`)
3 Likes

From Julia, you can use Sys.free_memory() which returns an unsigned integer with number of bytes that are free. If you want it in e.g. MiB do Sys.free_memory()/2^20. You can also get it by calling versioninfo(verbose=true) although that prints a lot of other info as well.

Note: versioninfo() is a part of InteractiveUtils in the Standard Library which is loaded automatically in the REPL. If you want to run it from a script you need to include using InteractiveUtils before calling it.

8 Likes

THX, is not easy to find it
Search · The Julia Language :slight_smile:
Paul
W dniu 2018-09-21 o 17:57, Kevin McReynolds pisze:

Total RAM memory:
Sys.total_memory()/2^20

Free RAM memory:
Sys.free_memory()/2^20

@ksmcreynolds How can we get available RAM memory?

I have the same question. Is it possible to check system available memory but not free memory? On Linux most people suggest look at /proc/meminfo. Since free RAM is treated as “wasted” RAM, why is there a built-in method for free memory but not available memory?

1 Like

The question is pretty hard. I’ve run Julia on my mac that took 50GB RAM, and my mac has 16GB. How much was free? -30GB?

MacOS has ’memory pressure’ on the monitor app. I don’t really know what it does.

Indeed, this seems strange. Didn’t the developer forgot to implement available memory Sys.available_memory() when he implemented total & free memory?

I made a very ugly workaround solution:
available_memory() = parse(Int, String(read(grep MemAvailable /proc/meminfo))[14:end-3])