Situatie
Every piece of code running inside your Linux computer needs RAM and CPU cycles. A process taking more than its fair share slows down other processes.
Solutie
RAM and CPU cycles are finite resources. When a program’s code is executed, a process is formed. Along with the processes of the operating system, there are the processes that run your desktop environment, and any commands or applications that you launch. They all require CPU time and RAM.
Linux and the CPU have to manage the allocation of RAM and balance and schedule the CPU workload across cores and threads, to make sure all processes get a share. Applications are supposed to be written to make sure they don’t monopolize your machine, but sometimes things go wrong, and processes can try to commandeer all your RAM and monopolize your CPU.
Linux uses free RAM as cache. Although it might look like all of your RAM is in use, that’s probably a false impression. If required, items are dropped from the cache to allocate RAM to regular processes.
The free Command
The free command gives you a snapshot overview of memory usage. The -h (human) option makes the output easier to read.
I ran the command three times in a terminal window. In another terminal window, I ran a program that requested large amounts of RAM.
free -h
free -h
free -h
The free RAM drops at an alarming rate. We need to identify the process or processes behind that.
Reading /proc/meminfo
Tools like top and htop pull their memory information from the /proc/meminfo pseudo file. Because /proc/meminfo behaves like a file, we can use common utilities like cat and less to look at its contents.
less /proc/meminfo
The output differs according to which kernel you’re running and the architecture of your CPU, but the standard fields are always there. This is a good way to see a more granular display of exactly what type of memory use is taking the biggest portion of your RAM, but it doesn’t identify individual processes.
The vmstat command can give us a view of the virtual memory usage over time.To see four sets of results, five seconds apart, with the values shown in MiB, we can use this command:
vmstat 5 4 -S M
Leave A Comment?