Clamd consuming 1434 mb of RAM and the usage increasing.

Clamd service has been consuming 1000 mb of RAM and has been consuming more every hour. It was stable initially - below 1000 mb.


From what I read on ApisCP resources, it seems, Clamd only scans new files or changes to existing files. If so, why would the memory consumption increase all of a sudden.

Or does it do scheduled scans? If so, can we configure the scan to happen at later hours when the load on the server is low?

Any help would be appreciated.

New release of signatures increases the total count of signatures loaded into memory. You can have ClamAV run on demand, which greatly increases scan times from a few hundred milliseconds to several seconds - so at risk of creating a DoS as HTTP requests pile up - this is ill-advised:

# clamscan /bin/bash
/usr/bin/bash: OK

----------- SCAN SUMMARY -----------
Known viruses: 8878529
Engine version: 0.103.11
Scanned directories: 0
Scanned files: 1
Infected files: 0
Data scanned: 0.97 MB
Data read: 0.92 MB (ratio 1.06:1)
Time: 44.231 sec (0 m 44 s)
Start Date: 2023:12:04 08:21:10
End Date:   2023:12:04 08:21:54


# clamdscan /bin/bash
/usr/bin/bash: OK

----------- SCAN SUMMARY -----------
Infected files: 0
Time: 0.771 sec (0 m 0 s)
Start Date: 2023:12:04 08:22:17
End Date:   2023:12:04 08:22:18

If you’d like to disable supplementary signatures, OfficialDatabaseOnly can be set following customization procedure:

cpcmd scope:set cp.bootstrapper clamav_clamd_config__custom "OfficialDatabaseOnly yes"
upcp -sb clamav/setup

Note too, database reloads are concurrent to avoid processing delays. When new signatures are loaded, ClamAV spawns a copy of itself so you may be closer to ~3 GB temporarily. You can see the maximal memory for the process lifetime by looking at memory.max_usage_in_bytes:

 cat /sys/fs/cgroup/memory/system.slice/system-clamd.slice/memory.max_usage_in_bytes

To clear the counter, echo 0 > /sys/fs/cgroup/memory/system.slice/system-clamd.slice/memory.max_usage_in_bytes.

Thank you for the reply.

If I leave Clamd as it is - as recommended by you, what happens when my systems RAM usage peaks to its max?
Is such a case handled by ApisCP? How does it work, if it does get handled?

My system has 4000 mb of memory. Currently it runs around 2560 mb usage.
I do understand from another post on the forums, that linux reserves some for cache, which it can release as per need.

OOM killer is invoked only when available memory reaches zero. Kernel is quite judicious on how it spends memory, which is a fairly elastic resource. Free memory is tied up in filesystem caches either on file metadata or data itself to speed up access. Don’t worry about the value of free as reported by free -m. See also

In the event it does happen, then “OOM killer” is invoked. It follows a predictable scoring algorithm in which case clamd will almost certainly be terminated first. If killed, you’ll get an alert through Argos and OOM event logged to dmesg.