usage of os.posix_fadvise

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Tue May 28 13:27:04 EDT 2013


Dear all,
I was just experimenting for the first time with os.posix_fadvise(), which
is new in Python3.3 . I'm reading from a really huge file (several GB) and I
want to use the data only once, so I don't want OS-level page caching. I
tried os.posix_fadvise with the os.POSIX_FADV_NOREUSE and with the
os.POSIX_FADV_DONTNEED flags, but neither seemed to have any effect on the
caching behaviour of Ubuntu (still uses all available memory to page cache
my I/O).
Specifically, I was trying this:

import os
fd = os.open('myfile', os.O_RDONLY)
# wasn't sure about the len parameter in fadvise,
# so thought I just use it on the first 4GB
os.posix_fadvise(fd, 0, 4000000000, os.POSIX_FADV_NOREUSE) # or DONTNEED

then reading from the file with os.read() .

By its very nature, I suppose posix_fadvise's effects will be OS-dependent,
so my question is whether the lack of effect I'm observing is something
Ubuntu-specific, or if I'm just using it in a wrong way.

Any help is greatly appreciated!
Best,
Wolfgang 




More information about the Python-list mailing list