madvise() vs posix_fadvise()

Trond Endrestøl Trond.Endrestol at fagskolen.gjovik.no
Fri Mar 21 16:27:19 UTC 2014


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.

> Some parts of this mmap()ed data is frequently accessed, some is 
> not, and I see that rarely accessed regions are purged from RAM.  I 
> want disk cache (program writes large log files) to have lower 
> priority, so disk cache does not purge mmaped regions from memory.
> 
> Thanks.

-- 
+-------------------------------+------------------------------------+
| Vennlig hilsen,               | Best regards,                      |
| Trond Endrestøl,              | Trond Endrestøl,                   |
| IT-ansvarlig,                 | System administrator,              |
| Fagskolen Innlandet,          | Gjøvik Technical College, Norway,  |
| tlf. mob.   952 62 567,       | Cellular...: +47 952 62 567,       |
| sentralbord 61 14 54 00.      | Switchboard: +47 61 14 54 00.      |
+-------------------------------+------------------------------------+


More information about the freebsd-hackers mailing list