madvise() vs posix_fadvise()
John Baldwin
jhb at freebsd.org
Thu Mar 27 18:00:16 UTC 2014
On Monday, March 24, 2014 8:03:04 am 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)?
Right now FADV_WILLNEED is a nop. (I have some patches to implement it for
UFS.) I can't recall off the top of my head if MADV_WILLNEED is also a nop.
However, if both are fully implemented they should be similar in terms of
requesting async read-ahead. MADV_WILLNEED might also conceivably
pre-create PTEs while FADV_WILLNEED can be used on a file that isn't
mapped but is accessed via read(2).
--
John Baldwin
More information about the freebsd-hackers
mailing list