Using madvise for ld.so

Michael Matz matz at kde.org
Wed Mar 17 16:31:06 CET 2004


Hi Andrew,

On Tue, 16 Mar 2004, Andrew Morton wrote:

> > On Tue, 16 Mar 2004 21:00:26 +0100, Dirk Mueller <mueller at kde.org> wrote:
> > > might be a stupid question, but how did you "clear the cache" ?
> > 
> > the usual "use memory till oom" thing (included in an earlier email iirc)
> > i wish the kernel guys would sort this out which a proper solution.
> 
> In 2.6 you can run posix_fadvise(fd, start, length, POSIX_FADV_DONTNEED).
> 
> I've attached a little proggy which uses fadvise to shoot down some or all
> of a file's pagecache.

This is only for one file, though.  I.e. one would need to do /proc 
parsing magic to really clean the whole file cache (for all files not open 
anymore).  I think the "alloc all mem, touch all pages" approach is 
easier ;)

Which reminds me of a question I asked myself: If I open the file, fadvise 
a WILLNEED on it, all its pages are scheduled for IO.  Completion is not 
waited for.  So, if the program then exits, the file gets closed, and 
assuming that was the last ref to that inode: will the not yet completed 
IO be canceled or will it still be completed?


Ciao,
Michael.


More information about the Kde-optimize mailing list