Skip to content

Commit 72420c0

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents b65b7b4 + 3c2819a commit 72420c0

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

runtime/alloc/arena.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,31 @@ void arena::initialize_semispace() {
4141
abort();
4242
}
4343
//
44+
// std::align() may modify addr and request.
45+
//
46+
auto *start_block = reinterpret_cast<char *>(addr);
47+
auto *end_block = start_block + request;
48+
//
4449
// We allocated 2 * HYPERBLOCK_SIZE worth of address space but we're only going to use 1, aligned on a
4550
// HYPERBLOCK_SIZE boundry. This is so we can get end of the hyperblock by setting the low bits of any
4651
// address within the space to 1.
47-
// We don't worry about unused address space either side of our aligned address space because there will be no
48-
// memory mapped to it.
4952
//
5053
current_addr_ptr = reinterpret_cast<char *>(
5154
std::align(HYPERBLOCK_SIZE, HYPERBLOCK_SIZE, addr, request));
5255
//
56+
// Release any unused address space at the start of the mmap()ed block.
57+
//
58+
if (size_t front_slop = current_addr_ptr - start_block) {
59+
munmap(start_block, front_slop);
60+
}
61+
//
62+
// Release any unused address space at the end of the mmap()ed block.
63+
//
64+
auto *end_aligned = current_addr_ptr + HYPERBLOCK_SIZE;
65+
if (size_t back_slop = end_block - end_aligned) {
66+
munmap(end_aligned, back_slop);
67+
}
68+
//
5369
// We put a semispace id in the last byte of the hyperblock so we can identify which semispace an address
5470
// belongs to by setting the low bits to 1 to access this id.
5571
//

0 commit comments

Comments
 (0)