Add clamp growth limit
Clamp growth limit shrinks the space memmaps to the current growth
limit. This reduces virtual memory usage for apps with small heaps.
Bug: 18387825
Bug: 17131630
Change-Id: I4a8fdc335d2c40492e991708adabcc46299efb7d
diff --git a/runtime/mem_map.cc b/runtime/mem_map.cc
index 8303f84..a722813 100644
--- a/runtime/mem_map.cc
+++ b/runtime/mem_map.cc
@@ -665,6 +665,19 @@
maps_ = nullptr;
}
+void MemMap::SetSize(size_t new_size) {
+ if (new_size == base_size_) {
+ return;
+ }
+ CHECK_ALIGNED(new_size, kPageSize);
+ CHECK_EQ(base_size_, size_) << "Unsupported";
+ CHECK_LE(new_size, base_size_);
+ CHECK_EQ(munmap(reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(BaseBegin()) + new_size),
+ base_size_ - new_size), 0) << new_size << " " << base_size_;
+ base_size_ = new_size;
+ size_ = new_size;
+}
+
std::ostream& operator<<(std::ostream& os, const MemMap& mem_map) {
os << StringPrintf("[MemMap: %p-%p prot=0x%x %s]",
mem_map.BaseBegin(), mem_map.BaseEnd(), mem_map.GetProtect(),