RFR: JDK-8313319: [linux] mmap should use MAP_FIXED_NOREPLACE if available [v2]
David Holmes
dholmes at openjdk.org
Wed Aug 23 09:14:05 UTC 2023
On Wed, 16 Aug 2023 14:24:44 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
>> os::attempt_reserve_memory_at() is used to map memory at a specific address that we fancy. It is not used to replace an existing mapping (hence we omit MAP_FIXED).
>>
>> But it may result in the kernel creating a mapping at a different address if our wish address is blocked; we then have to unmap again. That mmap-munmap cycle is unnecessary.
>>
>> MAP_FIXED_NOREPLACE exists since Linux 4.17 and prevents that unnecessary cycle . We should use that if available. We need to tiptoe around a bit to deal with building on old machines/running on old kernels, though.
>
> Thomas Stuefe has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:
>
> - Merge branch 'openjdk:master' into JDK-8313319-MAP_FIXED_NOREPLACE
> - DK-8313319-MAP_FIXED_NOREPLACE
This seems reasonable. I'd like to take it for a spin through our CI though. Thanks.
src/hotspot/os/linux/os_linux.cpp line 3485:
> 3483: // If a requested address was given:
> 3484: //
> 3485: // The POSIX-conform way is to *omit* MAP_FIXED. This will leave existing mappings intact.
s/conform/conforming/
src/hotspot/os/linux/os_linux.cpp line 3489:
> 3487: // somewhere else. On Linux, that alternative address appears to have no relation to the
> 3488: // requested address.
> 3489: // Unfortunately, this is not what we need - if we specified a request address, we'd want
s/request/requested/
src/hotspot/os/linux/os_linux.cpp line 3494:
> 3492: // Since Linux 4.17, the kernel offers MAP_FIXED_NOREPLACE. With this flag, if a pre-
> 3493: // existing mapping exists, the kernel will not map at an alternative point but instead
> 3494: // return an error. We can therefore save that unnessassary mmap-munmap cycle.
typo: unnecessary
test/hotspot/gtest/runtime/test_os.cpp line 930:
> 928: TEST_VM(os, reserve_at_wish_address_shall_not_replace_mappings_smallpages) {
> 929: char* p1 = os::reserve_memory(M, false, mtTest);
> 930: ASSERT_NE(p1, (char*)nullptr);
Do you need casts on nullptr?
-------------
PR Review: https://git.openjdk.org/jdk/pull/15170#pullrequestreview-1590816377
PR Review Comment: https://git.openjdk.org/jdk/pull/15170#discussion_r1302523819
PR Review Comment: https://git.openjdk.org/jdk/pull/15170#discussion_r1302524294
PR Review Comment: https://git.openjdk.org/jdk/pull/15170#discussion_r1302524875
PR Review Comment: https://git.openjdk.org/jdk/pull/15170#discussion_r1302526703
More information about the hotspot-runtime-dev
mailing list