I often hear suggestion to use
|
1 |
fadvise |
system call to avoid caching in OS cache.
We recently made patch for
|
1 |
tar |
, which supposes to create archive without polluting OS cache, as like in case with backup, you do not really expect any benefits from caching.
However working on the patch, I noticed, that
|
1 |
fadvise |
with
|
1 |
FADV_DONTNEED |
, does not really do what I expected (I used this call as it is often suggested for this purpose). In fact it does not prevent caching, it only releases already cached data.
And if we do
|
1 |
man fadvise |
, it says exactly:
|
1 2 3 4 |
FADV_DONTNEED Do not expect access in the near future. Subsequent access of pages in this range will succeed, but will result either in reloading of the memory contents from the underlying mapped file or zero-fill-in-demand pages for mappings without an underlying file. |
So it is totally fair. What we may really want is
|
1 |
FADV_NOREUSE |
call.
|
1 2 |
FADV_NOREUSE Access data only once. |
But… But, there is surprise. It does not work. And no wonder, there is Linux kernel source code:
|
1 2 3 4 5 6 7 |
SYSCALL_DEFINE(fadvise64_64)(int fd, loff_t offset, loff_t len, int advice) { ... case POSIX_FADV_NOREUSE: break; ... } |
which means that Linux kernel does nothing on fadvise call with FADV_NOREUSE.
Digging a little more on this topic, I found
http://kerneltrap.org/node/7563, where Linus Torvalds, about 3 years ago, confirms that FADV_NOREUSE is no-op operation.
Quite hopeless that it is not fixed for many years.
As for the patch for tar, I ended up with FADV_DONTNEED call after each copy of each block. Dirty, but it works, it only uses OS cache with one block size.
You can get patch there
|
1 |
lp:~percona-dev/perconatools/tar-patch |
, it adds parameter
|
1 |
--no-oscache |
, along with our old patch
|
1 |
--read-rate |
to throttle read IO.