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

From: Vitaliy Gusev <gusev.vitaliy_at_gmail.com>
Date: Tue, 13 Jul 2021 21:19:56 UTC
> On 13 Jul 2021, at 14:03, Ka Ho Ng <khng300@gmail.com> wrote:
> 
> On 2021/7/6 3:47 AM, Vitaliy Gusev wrote:
>>> 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 ?
>> 
> Illumos has a similar behavior as FreeBSD in the way that it does not
> destroy content of the underlying object. The operation you described in
> Illumos is MAP_PURGE which is intended to be a bug-to-bug compatible
> interface. See:
> https://github.com/illumos/illumos-gate/commit/8905f42caceb9f470ffaa19e5f6c9fb6184d12c0
> for full context.
> 

Right, I was confused by RSS value of test processes in illumos, it was shrunk to hundreds of KB:

  2337 vvv       1  59    0 1002M  980K sleep    0:01  0.00% mmapforkdontnee
  2338 vvv       1  59    0 1002M  720K sleep    0:01  0.00% mmapforkdontnee


whereas free memory didn’t increased, so system kept memory reserved.

MADV_FREE increases "free mem" after madvise(), i.e. frees used memory, that is expected.

Thanks,
Vitaliy Gusev