Skip to content
Permalink
Browse files
8266222: [aix] In mmap-mode, partial releases with os::release_memory…
… may trash internal bookkeeping

Reviewed-by: mdoerr
  • Loading branch information
tstuefe committed May 5, 2021
1 parent 65ce4d2 commit 250b45a510114d00059199701e626e3a63fc1fe7
Showing with 24 additions and 6 deletions.
  1. +24 −6 src/hotspot/os/aix/os_aix.cpp
@@ -1989,6 +1989,7 @@ bool os::pd_release_memory(char* addr, size_t size) {
// Dynamically do different things for mmap/shmat.
vmembk_t* const vmi = vmembk_find(addr);
guarantee0(vmi);
vmi->assert_is_valid_subrange(addr, size);

// Always round to os::vm_page_size(), which may be larger than 4K.
size = align_up(size, os::vm_page_size());
@@ -2002,20 +2003,37 @@ bool os::pd_release_memory(char* addr, size_t size) {
// - If user only wants to release a partial range, uncommit (disclaim) that
// range. That way, at least, we do not use memory anymore (bust still page
// table space).
vmi->assert_is_valid_subrange(addr, size);
if (addr == vmi->addr && size == vmi->size) {
rc = release_shmated_memory(addr, size);
remove_bookkeeping = true;
} else {
rc = uncommit_shmated_memory(addr, size);
}
} else {
// User may unmap partial regions but region has to be fully contained.
#ifdef ASSERT
vmi->assert_is_valid_subrange(addr, size);
#endif
// In mmap-mode:
// - If the user wants to release the full range, we do that and remove the mapping.
// - If the user wants to release part of the range, we release that part, but need
// to adjust bookkeeping.
assert(is_aligned(size, 4 * K), "Sanity");
rc = release_mmaped_memory(addr, size);
remove_bookkeeping = true;
if (addr == vmi->addr && size == vmi->size) {
remove_bookkeeping = true;
} else {
if (addr == vmi->addr && size < vmi->size) {
// Chopped from head
vmi->addr += size;
vmi->size -= size;
} else if (addr + size == vmi->addr + vmi->size) {
// Chopped from tail
vmi->size -= size;
} else {
// releasing a mapping in the middle of the original mapping:
// For now we forbid this, since this is an invalid scenario
// (the bookkeeping is easy enough to fix if needed but there
// is no use case for it; any occurrence is likely an error.
ShouldNotReachHere();
}
}
}

// update bookkeeping

3 comments on commit 250b45a

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot replied May 5, 2021

@tstuefe

This comment has been minimized.

Copy link
Member Author

@tstuefe tstuefe replied Jun 30, 2021

/backport jdk11u-dev

@openjdk

This comment has been minimized.

Copy link

@openjdk openjdk bot replied Jun 30, 2021

@tstuefe the backport was successfully created on the branch tstuefe-backport-250b45a5 in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

this pull request contains a backport of commit 250b45a5 from the openjdk/jdk repository.

The commit being backported was authored by Thomas Stuefe on 5 May 2021 and was reviewed by Martin Doerr.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev tstuefe-backport-250b45a5:tstuefe-backport-250b45a5
$ git checkout tstuefe-backport-250b45a5
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev tstuefe-backport-250b45a5
Please sign in to comment.