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

From: Konstantin Belousov <>
Date: Mon, 12 Jul 2021 19:52:31 UTC
On Mon, Jul 12, 2021 at 02:55:37PM +0300, Vitaliy Gusev wrote:
> Thanks for response,
> > On 10 Jul 2021, at 16:54, Konstantin Belousov <> wrote:
> > 
> >> 
> >> After testing it looks that backing_object is not null here, memory is not freed and mmapfork test program is still killed. Any ideas?
> >> 
> > I finally looked at this thing again.  You do madvise(PAGE_SIZE).  With
> > my patch (updated version below) issue madvise() for the whole region
> > once.
> I guess madvise() should work well even with PAGE_SIZE granularity. Usually a caller doesn’t need to free the whole region. As I reported earlier madvise(PAGE_SIZE) works well in Linux and illumos. 
> Current behaviour in FreeBSD can confuse programmers and brings impossibility to effectively give back unused memory. Also I have another case with madvise() but with shared memory that also doesn’t work (but works in Linux and illumos), will report it in new thread.

I want the confirmation or report that it still did not worked, for the
case when my latest patch was applied and the test program switched to
the single call to madvise(2) for the whole region.

After that, I can claim that the problem is understood and might consider
some solutions.