mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-18 01:54:47 +02:00
8253638: Cleanup os::reserve_memory and remove MAP_FIXED
Reviewed-by: stuefe, iklam
This commit is contained in:
parent
f014854ac7
commit
625a9352bf
17 changed files with 90 additions and 118 deletions
|
@ -3638,27 +3638,17 @@ bool os::remove_stack_guard_pages(char* addr, size_t size) {
|
|||
return os::uncommit_memory(addr, size);
|
||||
}
|
||||
|
||||
// If 'fixed' is true, anon_mmap() will attempt to reserve anonymous memory
|
||||
// at 'requested_addr'. If there are existing memory mappings at the same
|
||||
// location, however, they will be overwritten. If 'fixed' is false,
|
||||
// 'requested_addr' is only treated as a hint, the return value may or
|
||||
// may not start from the requested address. Unlike Linux mmap(), this
|
||||
// function returns NULL to indicate failure.
|
||||
static char* anon_mmap(char* requested_addr, size_t bytes, bool fixed) {
|
||||
char * addr;
|
||||
int flags;
|
||||
|
||||
flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS;
|
||||
if (fixed) {
|
||||
assert((uintptr_t)requested_addr % os::Linux::page_size() == 0, "unaligned address");
|
||||
flags |= MAP_FIXED;
|
||||
}
|
||||
static char* anon_mmap(char* requested_addr, size_t bytes) {
|
||||
// MAP_FIXED is intentionally left out, to leave existing mappings intact.
|
||||
const int flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS;
|
||||
|
||||
// Map reserved/uncommitted pages PROT_NONE so we fail early if we
|
||||
// touch an uncommitted page. Otherwise, the read/write might
|
||||
// succeed if we have enough swap space to back the physical page.
|
||||
addr = (char*)::mmap(requested_addr, bytes, PROT_NONE,
|
||||
flags, -1, 0);
|
||||
char* addr = (char*)::mmap(requested_addr, bytes, PROT_NONE, flags, -1, 0);
|
||||
|
||||
return addr == MAP_FAILED ? NULL : addr;
|
||||
}
|
||||
|
@ -3671,19 +3661,14 @@ static char* anon_mmap(char* requested_addr, size_t bytes, bool fixed) {
|
|||
// It must be a multiple of allocation granularity.
|
||||
// Returns address of memory or NULL. If req_addr was not NULL, will only return
|
||||
// req_addr or NULL.
|
||||
static char* anon_mmap_aligned(size_t bytes, size_t alignment, char* req_addr) {
|
||||
|
||||
static char* anon_mmap_aligned(char* req_addr, size_t bytes, size_t alignment) {
|
||||
size_t extra_size = bytes;
|
||||
if (req_addr == NULL && alignment > 0) {
|
||||
extra_size += alignment;
|
||||
}
|
||||
|
||||
char* start = (char*) ::mmap(req_addr, extra_size, PROT_NONE,
|
||||
MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE,
|
||||
-1, 0);
|
||||
if (start == MAP_FAILED) {
|
||||
start = NULL;
|
||||
} else {
|
||||
char* start = anon_mmap(req_addr, bytes);
|
||||
if (start != NULL) {
|
||||
if (req_addr != NULL) {
|
||||
if (start != req_addr) {
|
||||
::munmap(start, extra_size);
|
||||
|
@ -3709,9 +3694,9 @@ static int anon_munmap(char * addr, size_t size) {
|
|||
return ::munmap(addr, size) == 0;
|
||||
}
|
||||
|
||||
char* os::pd_reserve_memory(size_t bytes, char* requested_addr,
|
||||
size_t alignment_hint) {
|
||||
return anon_mmap(requested_addr, bytes, (requested_addr != NULL));
|
||||
char* os::pd_reserve_memory(size_t bytes, size_t alignment_hint) {
|
||||
// Ignores alignment hint
|
||||
return anon_mmap(NULL, bytes);
|
||||
}
|
||||
|
||||
bool os::pd_release_memory(char* addr, size_t size) {
|
||||
|
@ -4069,7 +4054,7 @@ static char* shmat_with_alignment(int shmid, size_t bytes, size_t alignment) {
|
|||
// To ensure that we get 'alignment' aligned memory from shmat,
|
||||
// we pre-reserve aligned virtual memory and then attach to that.
|
||||
|
||||
char* pre_reserved_addr = anon_mmap_aligned(bytes, alignment, NULL);
|
||||
char* pre_reserved_addr = anon_mmap_aligned(NULL /* req_addr */, bytes, alignment);
|
||||
if (pre_reserved_addr == NULL) {
|
||||
// Couldn't pre-reserve aligned memory.
|
||||
shm_warning("Failed to pre-reserve aligned memory for shmat.");
|
||||
|
@ -4238,7 +4223,7 @@ char* os::Linux::reserve_memory_special_huge_tlbfs_mixed(size_t bytes,
|
|||
assert(is_aligned(bytes, alignment), "Must be");
|
||||
|
||||
// First reserve - but not commit - the address range in small pages.
|
||||
char* const start = anon_mmap_aligned(bytes, alignment, req_addr);
|
||||
char* const start = anon_mmap_aligned(req_addr, bytes, alignment);
|
||||
|
||||
if (start == NULL) {
|
||||
return NULL;
|
||||
|
@ -4418,7 +4403,7 @@ char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) {
|
|||
|
||||
// Linux mmap allows caller to pass an address as hint; give it a try first,
|
||||
// if kernel honors the hint then we can return immediately.
|
||||
char * addr = anon_mmap(requested_addr, bytes, false);
|
||||
char * addr = anon_mmap(requested_addr, bytes);
|
||||
if (addr == requested_addr) {
|
||||
return requested_addr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue