How Do I Handle OOM Issues in a Linux ECS?
Background
Out of Memory (OOM) occurs when all available memory is exhausted and the system is unable to allocate memory for processes, which will trigger a kernel panic or OOM killer. On Linux, OOM killer is a process that prevents other processes from collectively exhausting the host's memory. When the system is critically low on memory, the processes that use more memory than available will be killed to ensure the overall availability of the system.
Symptom
When an ECS is running, information similar to the following is recorded in the log:
[ 327.199955] 5202 total pagecache pages [ 327.200965] 0 pages in swap cache [ 327.201950] Swap cache stats: add 0, delete 0, find 0/0 [ 327.203656] Free swap = 0kB [ 327.204580] Total swap = 0kB [ 327.205491] 2096926 pages RAM [ 327.206375] 0 pages HighMem/MovableOnly [ 327.207509] 94837 pages reserved [ 327.208746] [ pid ] uid tgid total_vm rss nr_ptes swapents oom_score_adj name [ 327.210727] [ 352] 0 352 9764 616 22 0 0 systemd-journal [ 327.212897] [ 372] 0 372 11370 150 23 0 -1000 systemd-udevd [ 327.214662] [ 410] 0 410 13883 102 27 0 -1000 auditd [ 327.216276] [ 498] 81 498 14558 164 33 0 -900 dbus-daemon [ 327.217880] [ 499] 0 499 5385 62 16 0 0 irqbalance [ 327.219369] [ 500] 999 500 153060 1350 63 0 0 polkitd [ 327.221158] [ 502] 0 502 243884 3537 36 0 0 uniagent [ 327.222916] [ 503] 0 503 137033 1033 84 0 0 NetworkManager [ 327.225002] [ 505] 0 505 6596 77 19 0 0 systemd-logind [ 327.226841] [ 508] 998 508 29452 105 30 0 0 chronyd [ 327.228427] [ 529] 0 529 26123 488 21 0 0 uniagentd [ 327.230120] [ 532] 0 532 143572 2883 96 0 0 tuned [ 327.231779] [ 563] 0 563 25753 514 51 0 0 dhclient [ 327.233396] [ 608] 0 608 54632 688 42 0 0 rsyslogd [ 327.235004] [ 839] 0 839 39781 400 42 0 0 hostwatch [ 327.236505] [ 904] 0 904 335577 1654 112 0 0 [kworker/0:0H] [ 327.237967] [ 1059] 0 1059 22452 253 45 0 0 master [ 327.239371] [ 1074] 89 1074 22478 250 44 0 0 pickup [ 327.240758] [ 1075] 89 1075 22495 252 45 0 0 qmgr [ 327.242087] [ 1416] 0 1416 28251 259 57 0 -1000 sshd [ 327.243474] [ 1418] 0 1418 6477 51 18 0 0 atd [ 327.244773] [ 1420] 0 1420 31597 152 18 0 0 crond [ 327.246133] [ 1422] 0 1422 24842 166 51 0 0 login [ 327.247893] [ 1423] 0 1423 27552 32 10 0 0 agetty [ 327.249319] [ 2359] 0 2359 197550 4903 48 0 0 containerserver [ 327.250828] [ 7726] 0 7726 63736 535 22 0 0 uniagentd [ 327.252278] [ 7727] 0 7727 98075 305 26 0 0 uniagentd [ 327.253688] [ 7773] 0 7773 28886 101 13 0 0 bash [ 327.254906] [ 7840] 0 7840 225333 3183 34 0 0 telescope [ 327.256240] [ 7922] 0 7922 39390 374 83 0 0 sshd [ 327.257496] [ 7924] 0 7924 28887 102 13 0 0 bash [ 327.258769] [ 7943] 0 7943 18088 190 39 0 0 sftp-server [ 327.260041] [ 8076] 0 8076 1958387 1904796 3739 0 0 python3 [ 327.261301] Out of memory: Kill process 8076 (python3) score 924 or sacrifice child [ 327.262504] Killed process 8076 (python3), UID 0, total-vm:7833548kB, anon-rss:7619112kB, file-rss:72kB, shmem-rss:0kB
Possible Causes
If OOM frequently occurs when you run programs on a Linux instance, the possible causes are as follows:
- The configuration of the Linux instance is too low to meet the memory required for program running, causing OOM.
- The application code uses the memory improperly, causing OOM.
Solution
To handle OOM issues, perform the following steps:
- Run the following commands to view OOM-related logs:
sudo less /var/log/messages # CentOS sudo less /var/log/syslog # Ubuntu
Search for the keyword oom or kill in the log to view the log information related to OOM issues.
The log contains the standard output header line generated when the OOM Killer evaluates processes. You can sort the processes by the rss column (unit: 4 KB) to view the process that consumes the most memory.

If the memory OOM is caused by high memory usage of service processes, you are advised to further locate the cause of high memory usage based on service application logs.
- You can select a solution based on the check result.
Possible Cause
Solution
The configuration of the Linux instance is too low to meet the memory required for program running.
Upgrade the instance memory configuration by referring to Modifying ECS Specifications (vCPUs and Memory).
CAUTION:During the modification, you need to stop and restart the ECS. You are advised to perform this operation during off-peak hours to reduce the impact on your services.
The application code uses the memory improperly.
Optimize the application code, for example, paginating batch query requests.
Related Information
- Table 1 describes the standard output header line generated when the OOM Killer evaluates processes.
Table 1 Standard output header line generated when the OOM Killer evaluates processes Column Name
Full Name
Description
pid
Process ID
The ID that the operating system assigns internally to each process.
uid
User ID
The ID of the user who started the process. The value 0 indicates the root user.
tgid
Thread Group ID
The thread group ID.
- For a single-threaded process, this is the same as pid.
- For a multi-thread program, all threads share the same tgid.
total_vm
Total Virtual Memory
The total size of the virtual memory occupied by the process (measured in 4 KB pages). This value is large because it includes shared libraries, mapped files, and more. It is not the best metric for measuring memory pressure.
rss
Resident Set Size
The size of the resident set (measured in 4 KB pages). This is the total non-swap memory currently occupied by the process in the physical memory. This is one of the most important factors considered by the OOM Killer, as it directly reflects the physical memory consumption of processes.
nr_ptes
Number of Page Table Entries
The number of page table entries. The more virtual memory a process uses, the more page table entries it requires. A page table entry itself consumes the memory, so it is also a factor for OOM scoring.
swapents
Swap Entries
The size of the memory swapped out to the swap partition (measured in 4 KB pages). A higher value indicates that some memory of the process is not currently in the physical RAM.
oom_score_adj
OOM Score Adjust
OOM adjustment value (value ranges: –1000 to 1000). This is the most important parameter that can be set in user mode to actively influence the OOM Killer's decision-making.
name
Process Name
The name of the executable file of a process.
- Table 2 lists the OOM-related parameters.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot