I had troubles with one of Directadmin servers which was constantly loading because clamd process. When executing top command, clamd was always top on the list. As I researched, there is no way you can limit ClamAV’s memory and CPU consumption via its configuration itself. This is how you do it.
What you have to do is limit clamd within startup script, so that clamd will start with some limitations.
Just open ClamAV startup script. I this case CentOS 7:
vi /etc/systemd/system/clamd.service
Then add this lines. Of course change according to your needs.
IOSchedulingPriority = 7 CPUSchedulingPolicy = 5 MemoryLimit=256M CPUQuota=30% Nice = 19
Your startup script should now look something like this:
[Unit] Description = Generic clamav scanner daemon After = syslog.target nss-lookup.target network.target [Service] Type = simple ExecStartPre=-/bin/mkdir -p /var/run/clamd ExecStartPre=-/bin/chown -R clamav:clamav /var/run/clamd ExecStart = /usr/local/sbin/clamd --foreground=yes Restart = on-failure PrivateTmp = true IOSchedulingPriority = 7 CPUSchedulingPolicy = 5 MemoryLimit=256M CPUQuota=30% Nice = 19 [Install] WantedBy = multi-user.target
I will try 10 days for the test.
Thanks for your great share.
This is good, but in terms of memory, clamav-daemon will then grow to whatever it needs (1.2GB in my case) in virtual memory usage from swap partition.
also, CPUSchedulingPolicy is set to some weird value