Linux Server

[Solved]: ClamAV Memory Consuming (Out of Memory)

ご注意下さい

この記事は3年以上前に書かれた記事ですので、内容が古い可能性があります。

0
(0)

ClamAV consumes a lot of memory and sometimes stops with OOM (Out of Memory). Actually it was caused because I started both clamd@scan and clamd@amavisd.

I saw a lots of 'Out of memory' errors in syslog.

...
Feb 8 03:21:44 kamatans kernel: Out of memory: Killed process 13651 (clamd) total-vm:1213536kB, anon-rss:764028kB, file-rss:332kB, shmem-rss:0kB, UID:985
Feb 8 03:21:50 kamatans kernel: Out of memory: Killed process 13654 (clamd) total-vm:1226848kB, anon-rss:752248kB, file-rss:424kB, shmem-rss:0kB, UID:983
Feb 8 03:21:56 kamatans kernel: Out of memory: Killed process 13650 (clamd) total-vm:1234768kB, anon-rss:811444kB, file-rss:180kB, shmem-rss:0kB, UID:985
Feb 8 03:22:03 kamatans kernel: Out of memory: Killed process 13660 (clamd) total-vm:1230936kB, anon-rss:784388kB, file-rss:0kB, shmem-rss:0kB, UID:983
Feb 8 03:25:04 kamatans kernel: Out of memory: Killed process 13709 (clamd) total-vm:1288308kB, anon-rss:826084kB, file-rss:0kB, shmem-rss:0kB, UID:985
Feb 8 03:25:15 kamatans kernel: Out of memory: Killed process 13719 (clamd) total-vm:1235556kB, anon-rss:795912kB, file-rss:0kB, shmem-rss:0kB, UID:983
Feb 8 03:25:22 kamatans kernel: Out of memory: Killed process 13725 (clamd) total-vm:1200988kB, anon-rss:722460kB, file-rss:4kB, shmem-rss:0kB, UID:985
Feb 8 03:25:28 kamatans kernel: Out of memory: Killed process 13731 (clamd) total-vm:1282956kB, anon-rss:846612kB, file-rss:0kB, shmem-rss:0kB, UID:983
Feb 8 03:25:35 kamatans kernel: Out of memory: Killed process 13724 (clamd) total-vm:1232200kB, anon-rss:757008kB, file-rss:0kB, shmem-rss:0kB, UID:985
Feb 8 03:25:41 kamatans kernel: Out of memory: Killed process 13736 (clamd) total-vm:1275276kB, anon-rss:797432kB, file-rss:0kB, shmem-rss:0kB, UID:983
Feb 8 03:25:51 kamatans kernel: Out of memory: Killed process 13739 (clamd) total-vm:1266056kB, anon-rss:783968kB, file-rss:0kB, shmem-rss:0kB, UID:985
Feb 8 03:26:18 kamatans kernel: Out of memory: Killed process 13742 (clamd) total-vm:1232216kB, anon-rss:801528kB, file-rss:0kB, shmem-rss:0kB, UID:983
Feb 8 03:26:37 kamatans kernel: Out of memory: Killed process 13738 (clamd) total-vm:1162832kB, anon-rss:675960kB, file-rss:0kB, shmem-rss:0kB, UID:985
Feb 8 03:26:45 kamatans kernel: Out of memory: Killed process 13747 (clamd) total-vm:1290888kB, anon-rss:877156kB, file-rss:0kB, shmem-rss:0kB, UID:983
Feb 8 03:26:52 kamatans kernel: Out of memory: Killed process 13750 (clamd) total-vm:1181284kB, anon-rss:720740kB, file-rss:0kB, shmem-rss:0kB, UID:985
Feb 8 03:26:58 kamatans kernel: Out of memory: Killed process 13753 (clamd) total-vm:1250680kB, anon-rss:763016kB, file-rss:0kB, shmem-rss:0kB, UID:983
Feb 8 03:29:57 kamatans kernel: Out of memory: Killed process 13749 (clamd) total-vm:1292668kB, anon-rss:854828kB, file-rss:0kB, shmem-rss:0kB, UID:985
Feb 8 03:30:55 kamatans kernel: Out of memory: Killed process 13773 (clamd) total-vm:1071400kB, anon-rss:828420kB, file-rss:0kB, shmem-rss:0kB, UID:985
Feb 8 03:31:13 kamatans kernel: Out of memory: Killed process 13758 (clamd) total-vm:1298316kB, anon-rss:686208kB, file-rss:28kB, shmem-rss:0kB, UID:983
Feb 8 03:31:20 kamatans kernel: Out of memory: Killed process 13771 (clamd) total-vm:1256576kB, anon-rss:815760kB, file-rss:280kB, shmem-rss:0kB, UID:985
...

Even so, 1.1GB/process memory consuming is too big. I initially built a VM with 2GB RAM, so I'm already running out of memory. Even if it can be expanded to 4GB RAM and started, the following is processed.

Consuming 1.1GB RAM x 2 memory

I stopped clamd@scan and ran clamd@amavisd only, but it still consumes as much as 2.2GB of memory.

top - 15:21:36 up 14:08, 2 users, load average: 0.00, 0.00, 0.00
Tasks: 276 total, 1 running, 275 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni, 99.9 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st
MiB Mem : [|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||                                 ]66.4/3735.1   
MiB Swa[                                                                                                    ]p: 0.0/4152.0   

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND                                                                                                              
   1363 amavis 20 0 1477208 1.1g 9020 S 0.0 31.2 0:14.56 clamd                                                                                                                
   1337 named 20 0 733060 295784 7324 S 0.0 7.7 0:30.82 named                                                                                                                
   6159 amavis 20 0 343784 172620 12004 S 0.0 4.5 0:00.25 /usr/sbin/amavi                                                                                                      
   6160 amavis 20 0 343308 171936 12360 S 0.0 4.5 0:00.16 /usr/sbin/amavi                                                                                                      
   6158 amavis 20 0 340212 168784 10192 S 0.0 4.4 0:05.09 /usr/sbin/amavi                                                                                                      
   6576 root 20 0 252492 129100 11112 S 0.0 3.4 0:05.49 spamd                                                                                                                
   6582 root 20 0 252492 119916 1928 S 0.0 3.1 0:00.00 spamd child                                                                                                          
   6583 root 20 0 252492 119916 1928 S 0.0 3.1 0:00.00 spamd child                                                                                                          
   1273 root 20 0 223168 41044 39272 S 0.0 1.1 0:00.60 sssd_nss          
#
# free -m
              total used free shared buff/cache available
Mem: 3735 2208 707 32 819 1270
Swap: 4151 0 4151
#
# systemctl stop clamd@amavisd
# free -m
              total used free shared buff/cache available
Mem: 3735 805 2110 32 819 2673
Swap: 4151 0 4151
# 

As you can calculate, the memory consumption of clamd@amavdisd is still 1.4GB.

You can limit the amount of memory and CPU occupancy by editing /usr/lib/systemd/system/clamd@.service.

[Unit]
Description = clamd scanner (%i) daemon
Documentation=man:clamd(8) man:clamd.conf(5) https://www.clamav.net/documents/
After = syslog.target nss-lookup.target network.target
[Service]
Type = forking
ExecStart = /usr/sbin/clamd -c /etc/clamd.d/%i.conf
# Reload the database
ExecReload=/bin/kill -USR2 $MAINPID
Restart = on-failure
TimeoutStartSec=420
#IOSchedulingPriority = 7
#CPUSchedulingPolicy = other
#CPUSchedulingPriority = 5
MemoryLimit=512M
CPUQuota=30%
#Nice = 19
[Install]
WantedBy = multi-user.target

IOSchedulingPriority Specify the priority for disk IO (0 high priority ⇔7 low priority)
CPUSchedulingPolicy

other: Normal time-division schedule. Priority can only be specified as 0

batch: Similar to Other, but assumes that the scheduler is CPU-heavy. Priority can only be specified as 0

idle: A very low priority job. Priority can only be specified as 0

fifo: First in first out. Priority can be greater than 0

rr: Round robin. Fifo extensions

CPUSchedulingPriority (99 High Priority ⇔ 0 Low Priority)
MemoryLimit Memory allocation limit. Sizes larger than the specified memory size are not available for the process. The shortfall will take advantage of the Sap area
CPUQuota Set CPU usage limits
Nice Nice level designation (0 normal ⇔ 19 low priority)
# systemctl daemon-reload
# systemctl restart clamd@amavisd

You can see that memory usage has been reduced to 512MB. In addition, the amount of memory that does not fit in 512MB is swapped out.

top - 15:40:10 up 14:26, 3 users, load average: 0.18, 0.11, 0.04
Tasks: 269 total, 1 running, 268 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.1 us, 0.1 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 [|||||||||||||||||||||||||||||||||||||||                                                      ]st
MiB Mem : 42.7/373[||||||||||||||||                                                                             ]5.1   
MiB Swap: 16.8/4152.0   

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND                                         
   6803 amavis 39 19 1403476 528040 8724 S 0.0 13.8 0:16.92 clamd                                           
   1337 named 20 0 733320 296048 7324 S 0.3 7.7 0:31.87 named                                           
   6576 root 20 0 252492 129100 11112 S 0.0 3.4 0:05.57 spamd                                           
   6582 root 20 0 252492 119916 1928 S 0.0 3.1 0:00.00 spamd child                                     
   6583 root 20 0 252492 119916 1928 S 0.0 3.1 0:00.00 spamd child                                     
   1273 root 20 0 223168 41044 39272 S 0.0 1.1 0:00.61 sssd_nss                 
#
# free -m
              total used free shared buff/cache available
Mem: 3735 1335 1576 32 822 2140
Swap: 4151 696 3455
#

Once, I would like to see how it works in this setting.

That's all! Enjoy!

この記事は役に立ちましたか? | Is this article useful for you?

評価をお願いします | Please leave your rating.

平均 | Av.: 0 / 5. 投票数 | Votes: 0

最初の評価を下さい | Please vote for the first rating.

-Linux Server
-, , ,

© 1999 - 2021 蒲田ネット