madvise() vs posix_fadvise()

Konstantin Belousov kostikbel at gmail.com
Mon Mar 24 12:12:24 UTC 2014


On Mon, Mar 24, 2014 at 04:03:04PM +0400, Dmitry Sivachenko wrote:
> 
> On 21 марта 2014 г., at 20:27, Trond Endrest??l <Trond.Endrestol at fagskolen.gjovik.no> wrote:
> 
> > On Fri, 21 Mar 2014 18:56+0400, Dmitry Sivachenko wrote:
> > 
> >> Hello!
> >> 
> >> I have a program which uses large data files (read-only, via mmap()).
> >> 
> >> These machines have a bit more RAM that these files occupy, so it is 
> >> possible to have all these data in memory.
> >> 
> >> What techniques should I use to promote this data not to be purged 
> >> from RAM:
> >> 
> >> -- madvise(MADV_WILLNEED)
> >> -- posix_fadvise(POSIX_FADV_WILLNEED)
> >> -- both?
> > 
> > Although a bit dangerous, mlock(2) might be your ticket. That system 
> > call prevents your memory region from being swapped/paged away from 
> > physical memory.
> > 
> 
> 
> I know about mlock(2), it is a bit overkill.
> Can someone please explain the difference between madvise(MADV_WILLNEED) and posix_fadvise(POSIX_FADV_WILLNEED)?
> 

The difference is only in the way the errors are reported; madvise(2)
is the 'classic' syscall which sets errno, while posix_madvise(3) is a
trivial wrapper which returns error. You would get the answer yourself
in approx. 1 minute if you looked at the man page or code.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20140324/e7e5c2f2/attachment.sig>


More information about the freebsd-hackers mailing list