On Wed, 18 Mar 2026 16:03:13 GMT, Thomas Stuefe <[email protected]> wrote:

>> We'll get to those a bit later, but if you want to have a look they're here:
>> 
>> `os::pd_commit_memory`:
>> https://github.com/battleblow/jdk/blob/bsd-port/src/hotspot/os/bsd/os_bsd.cpp#L1881
>> 
>> `os::pd::uncommit_memory`:
>> https://github.com/battleblow/jdk/blob/bsd-port/src/hotspot/os/bsd/os_bsd.cpp#L1980
>> 
>> The only difference is that uncommit uses `madvice()` to mark the pages as 
>> freeable, but only if the `exec` flag is set. That looks wrong to me.
>
> Ah okay. Thanks!
> 
> Yes, looks like you want to discard the memory regardless of exec flag.

@tstuefe 
> Do you know, by chance, if this also includes "uncommitted" mmapped memory 
> (as in, allocated with MAP_NORESERVE)? Since we over-allocate quite 
> drastically with uncommitted memory.

I briefly reviewed this today. @snake66 pointed out `MAP_NORESERVE` is defined 
to 0 if not already defined which applies to OpenBSD and FreeBSD. So 
`os::pd_reserve_memory` effectively calls mmap with `PROT_NONE` and 
`MAP_PRIVATE|MAP_ANONYMOUS`. Historically this was counted against rlimit data 
on OpenBSD, but some years ago the accounting changed. On more recent OpenBSD 
releases, `PROT_NONE` anonymous mmap memory does not count towards rlimit data. 
When `os::pd_commit_memory` is called with `MAP_FIXED` and the desired 
permissions (other then `PROT_NONE`), it is immediately counted towards rlimit 
data and will fail w/`ENOMEM` if the limit is exceeded.

> Wait, I see that neither BSD nor MacOS manpages even mention MAP_NORESERVE. 
> But we use it. Now I am confused :-)

I just checked NetBSD and while it is listed in the man page it says it is 
unimplemented there. I think ifndef approch:


#ifndef MAP_NORESERVE
  #define MAP_NORESERVE 0
#endif
``` 

makes sense should one of the BSD's implement it in the future.

-------------

PR Review Comment: 
https://git.openjdk.org/bsd-port/pull/4#discussion_r2956018628

Reply via email to