madvise() vs posix_fadvise()

Dmitry Sivachenko trtrmitya at gmail.com
Sat Apr 5 20:11:57 UTC 2014


On 05 апр. 2014 г., at 1:02, Dmitry Sivachenko <trtrmitya at gmail.com> wrote:

> On 05 апр. 2014 г., at 0:12, John Baldwin <jhb at FreeBSD.org> wrote:
> 
>> 
>> MADV_WILLNEED is not going to give you what you want.  OTOH, if you haven't
>> tried FreeBSD 10 yet, I would suggest trying that.  There have been changes
>> to pagedaemon that might make it do a better job of kicking out the pages
>> of the log files automatically.
>> 
> 
> 
> I did. My situation became worse after I moved from stable/9 to stable/10.
> My feeling is that stable/10 pushes rarely used mmaped pages out of RAM more aggressively than stable/9 did.
> 
> For now, the only solution I found is doing msync(MS_INVALIDATE) on log files after gzipping and after backup via rsync.
> This moves corresponding memory pages from Inactive to Free and prevents system to occupy all free memory with cached log files and to purge mmaped data out of RAM to accomodate more disk cache.
> 
> What I would love to see is an ability to tell OS not to release mmaped data unless "really needed" (disk cache is not an excuse).


One more observation as it seems to be related.
If my program allocates RAM via malloc() rather than mmap(), I see that VM swaps rarely used parts of malloced data out as disk is being used
(more and more memory goes to Inactive with cached files content).

This is also different from stable/9 and seems not good.  Why to keep cached content of files forever? (seems there is no timeout for keeping cached files content in Inactive state).  So after few days of uptime all available RAM is either in Active state with frequently used pages of running processes or in Inactive state with cached files data.  Rarely used parts of processes memory goes to swap.




More information about the freebsd-hackers mailing list