Fix high memory usage in Debian

Memory overload is among the main causes of device failures. Memory high usage may be caused by different reasons. This tutorial shows how to check for processes usage, used and free space and how to analyze your hardware to diagnose physical problems.

The first chapter is a fast view over commands free, top, ps and /proc/meminfo, following common troubleshooting commands including cleaning the cache, killing processes and ram memory tests for hardware issues which is the less probable scenario, each command is deeply explained with examples on additional articles numerated on the Related articles section at the bottom.

Monitoring memory usage in Debian

Below a list with examples of commands used to monitor the memory usage on Debian and other Linux distributions. The first command in the list is free, without parameters the default output unit is kb. To display it on the console run:

/# free

this row shows the physical ram memory
this row displays information on the virtual memory (swap)
this column shows the total capability
this column shows the amount of memory or swap being used

Free: the unused ram memory or swap
memory shared to be used by multiple processes
temporary store of pseudo files on memory to be used by processes
the available memory for processes

To print the output in MB units use the -m flag:

/# free -m

You can display the man page by running:

/# man free

Another way to check the memory usage is by reading the file /proc/meminfo, you can use the command less or open the location /proc/meminfo on a browser.
The file /proc/meminfo runs on memory and provides information on the memory use such as free, used, swap, buffers and shared memory.

/# less /proc/meminfo

The top command allows to monitor memory usage in real time through an interactive console interface. Through it you can kill and edit the view in real time. When displaying the top interactive console you can browse between processes and select them using the keyboard arrows or kill them using the k key. The following example shows the default output for the top command without flags:

/# top


PID: this column shows the process ID number.
USER: this column shows the user who runs the process.
PR: prioriory for running processes.
NI: nice value
VIRT: Virtual Memory (Swap) being used.
RES: Physical memory used.
SHR: Shared memory used.
S: Process status.
%CPU: amount of CPU used by the process.
%MEM: amount of RAM memory used by the process
TIME+: total time the process is running.
COMMAND: the program or command which executes the process.

The article How to Check Memory Usage Per Process on Linux shows an interesting use of the ps command to print processes and their memory usage:

/# ps -o pid,user,%mem,command ax | sort -b -k3 -r

Then you can kill the process eating your memory, make sure the process doesn’t launch automatically at the startup.

How to fix high memory usage in Debian

This chapter shows some commands to solve high memory usage problems.
Before running the following steps always monitor the process status if possible by using any of the command shown previously.

Fixing high memory usage problems on Linux depends on the program the process consuming memory belongs. Usually after identifying it you can kill it or fix the problem causing the high usage.

The first command shows how to release memory from the cache, you can see the comparison of the free -m output before and after running the command:

/# echo 3 > /proc/sys/vm/drop_caches

As you can see in the free -m executed before and after the command the buff/cache column shows a decrease from 996 to 603 and additional memory became available.

Testing Memory Hardware in Debian

This chapter shows how to analyze your ram memory for hardware issues.
The optimal way to test the ram memory is by booting the computer using the memtester feature instead of the OS granting Memtest greater access to the memory. When executed from the OS the effectivity decreases. To install memtester on the console run:

/# apt install memtester

To run memtest you should specify the memory size in kb and the number of times you want tests to run.

/# memtester 16384 5

The following tests are from the original version, updated simply for speed and rewritten to fit the new framework of the program.  These tests will mainly catch memory errors due to bad bits which are permanently stuck high or low:

Random Value

Compare XDR
Compare SUB
Comprate MUL
Compare DIV
Compare OR
Compare AND

The following tests were implemented by me, and will do a slightly better job of catching flaky bits, which may or may not hold a true value:

Sequential Increment
Solid bits
Block Sequential


I hope you found this tutorial on fixing high memory usage on Debian useful. Keep following LinuxHint for more tips and updates on Linux and networking.

Related articles:

About the author

David Adams

David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.