Linux disable disk cache for a single command

Our server is performing decently, but when backups or other scan processes run it will tank the entire server. Something like clamd will run and scan many files. While we expect slow performance, it's killing our cache and the end result is we don't get a system that can do anything.

Is there a way to disable disc/disk caching for a single command? The idea would be to run it like this:

# ./nocache clamd

Then while running clamd it would not thrash the primed cache while reading all the files on the system.


Solution 1:

It has to be implemented in the program itself. If clamd doesn't already do it, you can modify clamd to avoid an unnecessarily large cache footprint by adding calls to functions like posix_fadvise(... POSIX_FADV_NOREUSE) or madvise(... MADV_DONTNEED) (if it memory maps the files). It will still push filesystem metadata out of the cache though. There's not much you can do about that.

Solution 2:

Its not really the answer you are looking for but we just use ionice for backups and scans so they don't affect the other programs on the server.

ionice -c3 clamd