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

From: Vitaliy Gusev <>
Date: Mon, 12 Jul 2021 22:51:00 UTC
> On 12 Jul 2021, at 22:52, Konstantin Belousov <> wrote:
> On Mon, Jul 12, 2021 at 02:55:37PM +0300, Vitaliy Gusev wrote:
>> 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.

Understood,  checked.

Patched kernel with single call of madvise(len, MADV_FREE) from userspace still doesn’t work. The same condition if (obj->backing_object != NULL) is met, but once.

Vitaliy Gusev

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