Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only call mmap() on first allocation in an arena #1192

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions include/runtime/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ size_t const HYPERBLOCK_SIZE = (size_t)BLOCK_SIZE * 1024 * 1024;
class arena {
public:
arena(char id)
: allocation_semispace_id(id) {
initialize_semispace();
}
: allocation_semispace_id(id) { }

~arena() {
munmap(current_addr_ptr, HYPERBLOCK_SIZE);
if (current_addr_ptr)
munmap(current_addr_ptr, HYPERBLOCK_SIZE);
if (collection_addr_ptr)
munmap(collection_addr_ptr, HYPERBLOCK_SIZE);
}
Expand Down Expand Up @@ -111,11 +110,12 @@ class arena {
//
// Current semispace where allocations are being made.
//
char *current_addr_ptr; // pointer to start of current address space
char *allocation_ptr; // next available location in current semispace
char *tripwire; // allocating past this triggers slow allocation
mutable size_t
num_blocks; // notional number of BLOCK_SIZE blocks in current semispace
char *current_addr_ptr = nullptr; // pointer to start of current address space
char *allocation_ptr
= nullptr; // next available location in current semispace
char *tripwire = nullptr; // allocating past this triggers slow allocation
mutable size_t num_blocks
= 0; // notional number of BLOCK_SIZE blocks in current semispace
char allocation_semispace_id; // id of current semispace
//
// Semispace where allocations will be made during and after garbage collect.
Expand Down Expand Up @@ -155,18 +155,25 @@ extern thread_local bool time_for_collection;
size_t get_gc_threshold();

inline void *arena::kore_arena_alloc(size_t requested) {
if (allocation_ptr + requested >= tripwire) {
//
// We got close to or past the last location accessed in this address range so far,
// depending on the requested size and tripwire setting. This triggers a garbage
// collect when allowed.
if (tripwire == nullptr) {
//
time_for_collection = true;
// Semispace not yet initialized.
//
// We move the tripwire to 1 past the end of our hyperblock so that we have
// a well defined comparison that will always be false until the next arena swap.
//
tripwire = current_addr_ptr + HYPERBLOCK_SIZE;
initialize_semispace();
} else if (allocation_ptr + requested >= tripwire) {
{
//
// We got close to or past the last location accessed in this address range so far,
// depending on the requested size and tripwire setting. This triggers a garbage
// collect when allowed.
//
time_for_collection = true;
//
// We move the tripwire to 1 past the end of our hyperblock so that we have
// a well defined comparison that will always be false until the next arena swap.
//
tripwire = current_addr_ptr + HYPERBLOCK_SIZE;
}
}
void *result = allocation_ptr;
allocation_ptr += requested;
Expand Down
Loading