Skip to content

Commit c59e3c4

Browse files
Adding munmap_arena_and_reset and calling it to all semispaces when free_all_kore_mem (#1201)
This is needed as in Pi2 we discovered that our GEth client, switches threads and not reuses the arena's mapped size in by other thread, instead, allocate the same amount at every switching making it pretty easy to overflow the memory usage.
1 parent 4277487 commit c59e3c4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

include/runtime/arena.h

+14
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ class arena {
111111
// allocated within an arena.
112112
static char get_arena_semispace_id_of_object(void *ptr);
113113

114+
// Unmaps the current and collection address spaces and resets them and the tripwire.
115+
// This is needed when the client switches thread contexts without properly deallocating
116+
// them. This is not a common use case and shoul be used carefully.
117+
void munmap_arena_and_reset() {
118+
if (current_addr_ptr)
119+
munmap(current_addr_ptr, HYPERBLOCK_SIZE);
120+
if (collection_addr_ptr)
121+
munmap(collection_addr_ptr, HYPERBLOCK_SIZE);
122+
123+
current_addr_ptr = nullptr;
124+
collection_addr_ptr = nullptr;
125+
tripwire = nullptr;
126+
}
127+
114128
private:
115129
void initialize_semispace();
116130
//

runtime/collect/collect.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
extern "C" {
1313
extern thread_local arena youngspace;
1414
extern thread_local arena oldspace;
15+
extern thread_local arena alwaysgcspace;
1516

1617
char *youngspace_ptr(void);
1718
char *oldspace_ptr(void);
@@ -345,5 +346,8 @@ void kore_collect(
345346
void free_all_kore_mem() {
346347
kore_collect(nullptr, 0, nullptr, true);
347348
kore_clear();
349+
youngspace.munmap_arena_and_reset();
350+
oldspace.munmap_arena_and_reset();
351+
alwaysgcspace.munmap_arena_and_reset();
348352
}
349353
}

0 commit comments

Comments
 (0)