When archiving big files (for example a big database) rsync feeds uselessly the disk cache. Thanks to the posix_fadvise linux system call we can tell the operating system that keeping archived data in cache is useless, leaving the disk cache for other applications (ie: the database).
Tobi Oetiker explains this on his blog and made a patch for rsync. The patch does not work out of the box and needed little modifications.
This patch uses two systems calls posix_fadvise
and mincore
.
- posix_fadvise:
#include <fcntl.h>
int posix_fadvise(int fd, off_t offset, off_t len, int advice);
- mincore:
#include <unistd.h>
#include <sys/mman.h>
int mincore(void *addr, size_t length, unsigned char *vec);