EmergencyEMERGENCY? Get 24/7 Help Now!

fadvise – may be not what you expect

 | April 2, 2010 |  Posted In: Hardware and Storage, MySQL


I often hear suggestion to use

system call to avoid caching in OS cache.
We recently made patch for

, 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


, 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

, it says exactly:

So it is totally fair. What we may really want is


But… But, there is surprise. It does not work. And no wonder, there is Linux kernel source code:

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

, it adds parameter

, along with our old patch

to throttle read IO.

Vadim Tkachenko

Vadim Tkachenko co-founded Percona in 2006 and serves as its Chief Technology Officer. Vadim leads Percona Labs, which focuses on technology research and performance evaluations of Percona’s and third-party products. Percona Labs designs no-gimmick tests of hardware, filesystems, storage engines, and databases that surpass the standard performance and functionality scenario benchmarks.

Vadim’s expertise in LAMP performance and multi-threaded programming help optimize MySQL and InnoDB internals to take full advantage of modern hardware. Oracle Corporation and its predecessors have incorporated Vadim’s source code patches into the mainstream MySQL and InnoDB products.

He also co-authored the book High Performance MySQL: Optimization, Backups, and Replication 3rd Edition.


  • I recall something “recent” about this being fixed… but not in any kernel that would have made it through enough “enterprise” releases to be found anywhere in production….

    (i could of course be wrong too 🙂

  • I did something similar in the past where I patched tar to use O_DIRECT. It seemed to help quite a bit at the time.

  • What’s really needed is a way to say:

    from here on forward, I don’t want you to cache anything.

    Maybe an LD_PRELOAD that intercepts read() so that all pages are immediately fadvised away.

    The reason this is important is that we don’t have time to patch EVERY binary in the world.

    tar is only one of many IO heavy programs that needs patching.

    What about cat, dd, rsync, scp, etc.


  • I just ran across this:


    A LD_PRELOAD tool that appears to do exactly what you’re looking for.

    Also http://code.google.com/p/pagecache-mangagement/

Leave a Reply