RFR: JDK-8313319: [linux] mmap should use MAP_FIXED_NOREPLACE if available

Thomas Stuefe stuefe at openjdk.org
Tue Aug 8 09:16:34 UTC 2023


On Tue, 8 Aug 2023 08:47:44 GMT, Johan Sjölen <jsjolen at openjdk.org> wrote:

> Hi,
> 
> Thanks for this and looks good to me. Two small nits.

Thanks Johan!

> src/hotspot/os/linux/os_linux.cpp line 3497:
> 
>> 3495:   //
>> 3496:   // Backward compatibility: Older kernels will ignore the unknown flag; so mmap will behave
>> 3497:   // as in mode (a).
> 
> Is this in case of a libc that's more up to date than the kernel?

The libc has little to do with it. mmap is a system call, and the flags should come from mman.h, which should be a kernel header. 

But I am not sure whether the flags we use when including mman.h are actually directly from the kernel, because the glibc contains the same flags and talks about "kernel header is not namespace clean", whatever that means.

Bottomline, on the build machine we either have the flag - from libc or kernel - or we don't, in which case we define it ourselves. At runtime, the kernel either understands the flag or it don't, in the latter case it shears the flag off and then behaves as if the flag had not been given.

See also man 2 mmap:

*Note  that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address.  Therefore, backward-compatible software should check the returned address against the requested address.*

> test/hotspot/gtest/runtime/test_os.cpp line 945:
> 
>> 943:     os::release_memory(p1, M);
>> 944:   } else {
>> 945:     tty->print_cr("Skipped.");
> 
> Have you succesfully seen this printed? AFAIK Gtest only prints stderr by default

Yes, it gets printed.

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

PR Comment: https://git.openjdk.org/jdk/pull/15170#issuecomment-1669232535
PR Review Comment: https://git.openjdk.org/jdk/pull/15170#discussion_r1286839802
PR Review Comment: https://git.openjdk.org/jdk/pull/15170#discussion_r1286841950


More information about the hotspot-runtime-dev mailing list