I am using Arch Linux (5.1.8-arch1-1-ARCH) with the XFCE DE and XFWM4 WM. Things are pretty elegant and low on RAM and CPU usage.
After the boot, and when the DE is loaded completely, I see 665 MiB of RAM usage.
But after opening applications like Atom, Code, Firefox, Chromium, or after working in GIMP, Blender etc. the RAM usage increases, which is obvious. But after closing all the applications and left with nothing but a gnome-system-monitor, I can see that the RAM usage is 1.2 – 1.4 GiB. /proc/meminfo agrees with gnome-system-monitor, but htop gives different results all the time.
The worse thing is that when I open a RAM hogging application later on, it again consumes needed memory on top of that 1.4 GiB. This is always the case. No files that could add up to megabytes are stored in the /tmp/ directory.
Also, if I look for the process that's using that much RAM (from 700 MiB at start to 1.4 GiB after closing the browser!!), I see nothing. In fact I faced the same issue even on my raspberry pi running Arch ARM.
The Ruby code:
#!/usr/bin/ruby -w
STDOUT.sync = true
loop do
IO.readlines(File.join(%w(/ proc meminfo))).then { |x| [x[0], x[2]] }.map { |x| x.split[1].to_i }.reduce(:-)
.tap { |x| print "\e[2K\rRAM Usage:".ljust(20), "#{x / 1024.0} MiB".ljust(24), "#{(x / 1000.0)} MB" }
Kernel.sleep(0.1)
end
The cat /proc/meminfo
command has the following output:
MemTotal: 3851796 kB
MemFree: 1135680 kB
MemAvailable: 2055708 kB
Buffers: 1048 kB
Cached: 1463960 kB
SwapCached: 284 kB
Active: 1622148 kB
Inactive: 660952 kB
Active(anon): 923580 kB
Inactive(anon): 269360 kB
Active(file): 698568 kB
Inactive(file): 391592 kB
Unevictable: 107012 kB
Mlocked: 32 kB
SwapTotal: 3978216 kB
SwapFree: 3966696 kB
Dirty: 280 kB
Writeback: 0 kB
AnonPages: 924844 kB
Mapped: 563732 kB
Shmem: 374848 kB
KReclaimable: 74972 kB
Slab: 130016 kB
SReclaimable: 74972 kB
SUnreclaim: 55044 kB
KernelStack: 8000 kB
PageTables: 14700 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 5904112 kB
Committed_AS: 3320548 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
Percpu: 1456 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
DirectMap4k: 226736 kB
DirectMap2M: 3778560 kB
DirectMap1G: 0 kB
Firstly you noticed htop never agrees. I don't know much about that.
And secondly you can see the xfdesktop uses 44 MiB, and some other processes uses some of the memory, the kernel uses ~150 MiB, and apart from that, why am I seeing 1.5 GiB RAM is being used? Does this really affect the performance of the system?
Best Answer
Unused RAM is wasted RAM. The Linux kernel has advanced memory management features and tries to avoid putting a burden on the bottleneck in your system, your hard drive/SSD. It tries to cache files in memory.
The memory management system works in complex ways, better performance is the goal.
You can see what it is doing by inspecting
/proc/meminfo
.cat /proc/meminfo
You can reclaim this cached memory, using "drop_caches". However, note the documentation says "use outside of a testing or debugging environment is not recommended", simply because "it may cost a significant amount of I/O and CPU to recreate the dropped objects" when they are needed again :-).
Clear PageCache only:
Clear dentries and inodes:
Clear PageCache, dentries and inodes:
Note that
sync
will flush the file system buffer to ensure all data has been written.From the kernel docs:
Memory Leaks
Now, some programs can have "memory leaks", that is, they "forget" to free up memory they no longer use. You can see this if you leave a program running for some time, its memory usage constantly increases, when you close it, the memory is never freed. Now, programmers try to avoid memory leaks, of course, but programs can have some. The way to reclaim this memory is a reboot.