Purge linker block allocators before leaving linker
This is the second attempt to purge linker block allocators. Unlike the
previously reverted change which purge allocators whenever all objects
are freed, we only purge right before control leaves the linker. This
limits the performance impact to one munmap() call per dlopen(), in
most cases.
Bug: 112073665
Test: Boot and check memory usage with 'showmap'.
Test: Run camear cold start performance test.
Change-Id: I02c7c44935f768e065fbe7ff0389a84bd44713f0
diff --git a/linker/linker_block_allocator.h b/linker/linker_block_allocator.h
index 0c54b93..8ae4094 100644
--- a/linker/linker_block_allocator.h
+++ b/linker/linker_block_allocator.h
@@ -50,6 +50,9 @@
void free(void* block);
void protect_all(int prot);
+ // Purge all pages if all previously allocated blocks have been freed.
+ void purge();
+
private:
void create_new_page();
LinkerBlockAllocatorPage* find_page(void* block);
@@ -57,6 +60,7 @@
size_t block_size_;
LinkerBlockAllocatorPage* page_list_;
void* free_block_list_;
+ size_t allocated_;
DISALLOW_COPY_AND_ASSIGN(LinkerBlockAllocator);
};