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

From: Gary Jennejohn <gljennjohn_at_gmail.com>
Date: Sat, 3 Jul 2021 08:54:20 +0200
On Sat, 3 Jul 2021 02:56:40 +0300
Vitaliy Gusev <gusev.vitaliy_at_gmail.com> wrote:

> Hi, 
> 
> I came across not expected behaviour with madvise() in FreeBSD.
> 
> Attached test program mmapfork does: mmap, fork, touch memory and then madvise(MADV_FREE).
> 
> Expected behaviour - one process can allocate memory (lazy allocation) while system is freeing previously allocated memory for a second process.
> 
> Current behaviour -  system kills one process with message in dmesg:
> 
> pid 31314 (mmapfork), jid 0, uid 1001, was killed: out of swap space
> 
> Running this test in Linux or illumos shows expected behaviour with a little difference in illumos - it frees memory almost immediately, w/o needs lack of memory in a system.
> 
> If use MADV_NOTNEED - no changes.
> 
> If modify program and do not do fork(), but run two instances  - that shows expected behaviour.
> 
> To reproduce just disable swap, and run program with argument as 1/2 RAM on a system. For instance, command below will try run and use ~ 2GB area twice.
> 
> [vetal_at_bsdev ~]$ ./mmapfork 2000
> 
> Testing program is attached.
> 
> Note, during testing I disabled swap on all systems: Linux, illumos and FreeBSD.
> 
> Does it mean madvise() doesn't work well in FreeBSD or test does something wrong?
> 

The FreeBSD mail server apparently removed the attachment.

So either provide it in-line or put it on some pubic file server and
add a link to it.

-- 
Gary Jennejohn
Received on Sat Jul 03 2021 - 06:54:20 UTC

Original text of this message