Masi - 4 months ago 6

Linux Question

Situation: estimate if you can compute big matrix with your Ram and Swap in Linux Matlab

I need the sum of

`Mem`

`Swap`

`free -m`

`total used free shared buff/cache available`

Mem: 7925 3114 3646 308 1164 4220

Swap: 28610 32 28578

Free Ram memory in Matlab by

`% http://stackoverflow.com/a/12350678/54964`

[r,w] = unix('free | grep Mem');

stats = str2double(regexp(w, '[0-9]*', 'match'));

memsize = stats(1)/1e6;

freeRamMem = (stats(3)+stats(end))/1e6;

Free Swap memory in Matlab: ...

Relation between Memory requirement and Matrix size of Matlab: ...

Suever's command gives me 29.2 GB that is corresponding to

`free`

`$ free`

total used free shared buff/cache available

Mem: 8115460 4445520 1956672 350692 1713268 3024604

Swap: 29297656 33028 29264628

System: Linux Ubuntu 16.04 64 bit

Linux kernel: 4.6

Linux kernel options: wl, zswap

Matlab: 2016a

Hardware: Macbook Air 2013-mid

Ram: 8 GB

Swap: 28 Gb on SSD (set up like in the thread How to Allocate More Space to Swap and Increase its Size Greater than Ram?)

SSD: 128 GB

Answer

You can just make a slight modification to the code that you've posted to get the swap amount.

```
function freeMem = freeMemory(type)
[r, w] = unix(['free | grep ', type]);
stats = str2double(regexp(w, '[0-9]*', 'match'));
memsize = stats(1)/1e6;
if numel(stats) > 3
freeMem = (stats(3)+stats(end))/1e6;
else
freeMem = stats(3)/1e6;
end
end
totalFree = freeMemory('Mem') + freeMemory('Swap')
```

To figure out how much memory a matrix takes up, use the size of the datatype and multiply by the number of elements as a first approximation.

Source (Stackoverflow)

Comments