diff options
Diffstat (limited to 'vm/alloc')
-rw-r--r-- | vm/alloc/Alloc.h | 20 | ||||
-rw-r--r-- | vm/alloc/HeapSource.cpp | 71 |
2 files changed, 83 insertions, 8 deletions
diff --git a/vm/alloc/Alloc.h b/vm/alloc/Alloc.h index efee1bde3..4bcd45834 100644 --- a/vm/alloc/Alloc.h +++ b/vm/alloc/Alloc.h @@ -117,6 +117,26 @@ float dvmGetTargetHeapUtilization(void); void dvmSetTargetHeapUtilization(float newTarget); /* + * Sets HEAP_MIN_FREE + */ +void dvmSetTargetHeapMinFree(size_t size); + +/* + * Gets HEAP_MIN_FREE + */ +int dvmGetTargetHeapMinFree(); + +/* + * Sets CONCURRENT_START + */ +void dvmSetTargetHeapConcurrentStart(size_t size); + +/* + * Gets CONCURRENT_START + */ +int dvmGetTargetHeapConcurrentStart(); + +/* * Initiate garbage collection. * * This usually happens automatically, but can also be caused by diff --git a/vm/alloc/HeapSource.cpp b/vm/alloc/HeapSource.cpp index 93cdd2fd7..f6c2464bc 100644 --- a/vm/alloc/HeapSource.cpp +++ b/vm/alloc/HeapSource.cpp @@ -43,12 +43,14 @@ static void trimHeaps(); /* Start a concurrent collection when free memory falls under this * many bytes. */ -#define CONCURRENT_START (128 << 10) +#define CONCURRENT_START_DEFAULT (128 << 10) + +static unsigned int concurrentStart = CONCURRENT_START_DEFAULT; /* The next GC will not be concurrent when free memory after a GC is * under this many bytes. */ -#define CONCURRENT_MIN_FREE (CONCURRENT_START + (128 << 10)) +#define CONCURRENT_MIN_FREE (concurrentStart + (128 << 10)) #define HS_BOILERPLATE() \ do { \ @@ -408,9 +410,9 @@ static bool addNewHeap(HeapSource *hs) overhead, hs->maximumSize); return false; } - size_t morecoreStart = SYSTEM_PAGE_SIZE; + size_t morecoreStart = MAX(SYSTEM_PAGE_SIZE, gDvm.heapStartingSize); heap.maximumSize = hs->growthLimit - overhead; - heap.concurrentStartBytes = hs->minFree - CONCURRENT_START; + heap.concurrentStartBytes = hs->minFree - concurrentStart; heap.base = base; heap.limit = heap.base + heap.maximumSize; heap.brk = heap.base + morecoreStart; @@ -611,8 +613,8 @@ GcHeap* dvmHeapSourceStartup(size_t startSize, size_t maximumSize, if (hs->maxFree > hs->maximumSize) { hs->maxFree = hs->maximumSize; } - if (hs->minFree < CONCURRENT_START) { - hs->minFree = CONCURRENT_START; + if (hs->minFree < concurrentStart) { + hs->minFree = concurrentStart; } else if (hs->minFree > hs->maxFree) { hs->minFree = hs->maxFree; } @@ -649,6 +651,13 @@ fail: bool dvmHeapSourceStartupAfterZygote() { + //For each new application forked, we need to reset softLimit and + //concurrentStartBytes to be the correct expected value, not the one + //inherit from Zygote + HeapSource* hs = gHs; + + hs->softLimit=SIZE_MAX; + hs->heaps[0].concurrentStartBytes = mspace_footprint(hs->heaps[0].msp) - concurrentStart; return gDvm.concurrentMarkSweep ? gcDaemonStartup() : true; } @@ -1226,8 +1235,9 @@ static void setIdealFootprint(size_t max) static void snapIdealFootprint() { HS_BOILERPLATE(); + HeapSource *hs = gHs; - setIdealFootprint(getSoftFootprint(true)); + setIdealFootprint(getSoftFootprint(true) + hs->minFree); } /* @@ -1269,6 +1279,48 @@ void dvmSetTargetHeapUtilization(float newTarget) } /* + * Sets TargetHeapMinFree + */ +void dvmSetTargetHeapMinFree(size_t size) +{ + HS_BOILERPLATE(); + gHs->minFree = size; + LOGD_HEAP("dvmSetTargetHeapIdealFree %d", gHs->minFree ); +} + +/* + * Gets TargetHeapMinFree + */ +int dvmGetTargetHeapMinFree() +{ + HS_BOILERPLATE(); + LOGD_HEAP("dvmGetTargetHeapIdealFree %d", gHs->minFree ); + return gHs->minFree; +} + + +/* + * Sets concurrentStart + */ +void dvmSetTargetHeapConcurrentStart(size_t size) +{ + concurrentStart = size; + LOGD_HEAP("dvmSetTargetHeapConcurrentStart %d", size ); +} + +/* + * Gets concurrentStart + */ +int dvmGetTargetHeapConcurrentStart() +{ + HS_BOILERPLATE(); + LOGD_HEAP("dvmGetTargetHeapConcurrentStart %d", concurrentStart ); + return concurrentStart; +} + + + +/* * Given the size of a live set, returns the ideal heap size given * the current target utilization and MIN/MAX values. */ @@ -1327,7 +1379,10 @@ void dvmHeapSourceGrowForUtilization() /* Not enough free memory to allow a concurrent GC. */ heap->concurrentStartBytes = SIZE_MAX; } else { - heap->concurrentStartBytes = freeBytes - CONCURRENT_START; + //For small footprint, we keep the min percentage to start + //concurrent GC; for big footprint, we keep the absolute value + //of free to start concurrent GC + heap->concurrentStartBytes = freeBytes - MIN(freeBytes * (float)(0.2), concurrentStart); } } |