Fix high memory usage in Debian

29/12/2020
Chưa phân loại
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

Where:
Mem:
this row shows the physical ram memory
Swap:
this row displays information on the virtual memory (swap)
Total:
this column shows the total capability
Used:
this column shows the amount of memory or swap being used

Free: the unused ram memory or swap
Shared:
memory shared to be used by multiple processes
Buff/Cache:
temporary store of pseudo files on memory to be used by processes
Available:
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

Where:

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

(source https://github.com/jnavila/memtester/blob/master/README.tests)

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:

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to Make a CentOS 7 Router

CentOS 7 has firewalld installed as a default firewall program. But firewalld can be used to configure CentOS 7 as a router...
29/12/2020

[Zabbix] Cài đặt Zabbix Server phiên bản 4.4 trên CentOS7

Zabbix là phần mềm nguồn mở sử dụng để giám sát hệ thống với nhiều công cụ hỗ...
30/12/2020

How to Install TeamViewer on Arch Linuxm

Team Viewer is an awesome application for remotely accessing a computer or letting someone remotely access your computer....
28/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Lý do tại sao bạn nên sử dụng proxy khi truy cập web đen
27/02/2023

Các lỗi thường gặp khi sử dụng proxy và cách khắc phục chúng.
27/02/2023

Tác động của việc sử dụng proxy đến tốc độ kết nối internet của bạn.
27/02/2023

Các tiện ích và công cụ để quản lý proxy.
27/02/2023

Các cách để kiểm tra tốc độ và độ ổn định của proxy.
27/02/2023