Understanding CPU Utilization stats

harishreejoshi

New Member
Credits
19
I'm seeing the following data on running the free -h command:
$ free -h

total used free shared buff/cache available

Mem: 46G 39G 495M 67M 7.3G 23G

Swap: 15G 524M 15G

How is this available (23G) calculated?
If the used space is 39G, how is the free space calculated as 495M?

Thanks.
 


jglen490

Well-Known Member
Credits
1,981
man is your friend. From
Code:
man free
DESCRIPTION
free displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the ker‐
nel. The information is gathered by parsing /proc/meminfo. The displayed columns are:

total Total installed memory (MemTotal and SwapTotal in /proc/meminfo)

used Used memory (calculated as total - free - buffers - cache)

free Unused memory (MemFree and SwapFree in /proc/meminfo)

shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo)

buffers
Memory used by kernel buffers (Buffers in /proc/meminfo)

cache Memory used by the page cache and slabs (Cached and SReclaimable in /proc/meminfo)

buff/cache
Sum of buffers and cache

available
Estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the cache
or free fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to
items being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as
free)
Never underestimate the power of curiosity.
 

dos2unix

Well-Known Member
Credits
1,193
You named this thread "CPU stats" but you are really looking at Memory stats.

total used free shared buff/cache available

Mem: 46G 39G 495M 67M 7.3G 23G

Swap: 15G 524M 15G

How is this available (23G) calculated?
If the used space is 39G, how is the free space calculated as 495M?
Total and Used are two different columns. It's not "total used", it's "total" and "used".

You have 46G total. You have 39G used (that is a little misleading, I'm coming to that part)
You have 495M shared memory between two or more applications, but that doesn't really
affect anything. You have 7.3G as buffer/cache. You have 23G available.

So then...
43
- 39
------
4

How can you have 23G available if you only have 4G left?
The kernel takes up almost all the memory you have and reserves it.
It doesn't really need it, it just grabs it if it is available. As a rule, most Linux kernels
run fine in 2G of RAM (without other applications).
So your kernel is holding onto (reserving) an extra 23G of memory it doesn't need.
When you launch other applications, the kernel will release as much as is necessary.
(It won't release all of it). If you run 2, 3 or 4 applications, it will just continue to release
as much as is needed for each application.
Of course it is possible to run so much stuff that you really do run out of available memory.
That's when swap kicks in. The only time you really use, is when real memory runs out.
Your swap shows 15G total, and 15G available.

However with 46G, it will take a LOT to run out of memory. It's not impossible, but it's difficult.

It you want to know how much memory and CPU a specific application uses, there are other tools.
"top" is probably the most common.

top - 07:44:39 up 1 day, 1:51, 2 users, load average: 0.02, 0.05, 0.00
Tasks: 413 total, 1 running, 412 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.1 us, 0.1 sy, 0.0 ni, 99.6 id, 0.1 wa, 0.1 hi, 0.0 si, 0.0 st
MiB Mem : 32032.0 total, 24828.6 free, 5083.9 used, 2119.6 buff/cache
MiB Swap: 16084.0 total, 16084.0 free, 0.0 used. 26344.8 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2823 rmccaff+ 20 0 6167460 2.1g 1.9g S 2.7 6.6 50:32.93 VirtualBoxVM
2636 rmccaff+ 20 0 40352 11716 9424 S 0.7 0.0 2:54.41 VBoxXPCOMIPCD
1236 root 20 0 402440 14056 11528 S 0.3 0.0 3:04.97 udisksd
2191 rmccaff+ 9 -11 1095684 14728 10724 S 0.3 0.0 8:23.98 pulseaudio
2642 rmccaff+ 20 0 859260 29784 19140 S 0.3 0.1 3:56.19 VBoxSVC
3904 rmccaff+ 20 0 2103888 25100 8340 S 0.3 0.1 2:36.68 winedevice.exe
1 root 20 0 170860 13452 9504 S 0.0 0.0 0:05.30 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.06 kthreadd
3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp
6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H-kblockd
9 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq
10 root 20 0 0 0 0 S 0.0 0.0 0:00.16 ksoftirqd/0
 


Members online


Top