Re: madvise(MADV_FREE) doesn't work in some cases?

From: Vitaliy Gusev <gusev.vitaliy_at_gmail.com>
Date: Mon, 05 Jul 2021 19:47:41 UTC
> On 5 Jul 2021, at 21:54, Konstantin Belousov <kostikbel@gmail.com> wrote:
> 
> On Mon, Jul 05, 2021 at 07:32:00PM +0300, Vitaliy Gusev wrote:
> 
> DONTNEED does not allow system to free pages at all.  It means that pages
> are less useful and can be paged out with higher priority.
> 

That caused behaviour that memory is not freed! 

Is there a reason why FreeBSD behaviour for MADV_DONTNEED is different than in Linux and illumos ? Why it needs swap and cannot be easily dropped ?

As Mark wrote in another thread:

Indeed, in FreeBSD madvise() never reclaims pages.  I'm not sure which
hint is being provided here, but MADV_DONTNEED and MADV_FREE both
prioritize reclamation of the pages backing the specified virtual
address range.  The difference between the two is that MADV_FREE permits
dirty pages to be freed without paging out their contents first and so
is destructive.

That is why I expected the same behaviour for both.


>>> 
>>> You can read more details in the referenced commit, as well as some musings
>>> about way to make it somewhat better.
>>> 
>>> I must say, that trying to allocated 1/2 + 1/2 of RAM this way, on a system
>>> without swap, is the way to ask for troubles anyway.
>> I’ve just notify that other operation systems work well with that, whereas FreeBSD has troubles. Probably something in madvise() is not finished ?
> 
> Well, yes, as I said, non-trivial shadow chains for MADV_FREE are not
> handled due to the 'old content revival' bug.  For your specific case, the
> following patch might help (modulo bugs).

Thanks, I will try and report result.

——
Vitaliy Gusev