Commit 502c6ae6 authored by hpayer's avatar hpayer Committed by Commit Bot

[heap] Activate memory reducer on external memory activity.

BUG=chromium:728228,chromium:626082
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_chromium_rel_ng

Review-Url: https://codereview.chromium.org/2917853004
Cr-Commit-Position: refs/heads/master@{#45671}
parent d1a9603e
......@@ -7589,6 +7589,7 @@ class V8_EXPORT Isolate {
friend class PersistentValueMapBase;
void ReportExternalAllocationLimitReached();
void CheckMemoryPressure();
};
class V8_EXPORT StartupData {
......@@ -8816,6 +8817,8 @@ class Internals {
static const int kExternalMemoryOffset = 4 * kApiPointerSize;
static const int kExternalMemoryLimitOffset =
kExternalMemoryOffset + kApiInt64Size;
static const int kExternalMemoryAtLastMarkCompactOffset =
kExternalMemoryLimitOffset + kApiInt64Size;
static const int kIsolateRootsOffset = kExternalMemoryLimitOffset +
kApiInt64Size + kApiInt64Size +
kApiPointerSize + kApiPointerSize;
......@@ -10033,13 +10036,28 @@ uint32_t Isolate::GetNumberOfDataSlots() {
int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
int64_t change_in_bytes) {
const int64_t kMemoryReducerActivationLimit = 1024 * 1024;
typedef internal::Internals I;
int64_t* external_memory = reinterpret_cast<int64_t*>(
reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryOffset);
const int64_t external_memory_limit = *reinterpret_cast<int64_t*>(
reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryLimitOffset);
int64_t* external_memory_at_last_mc =
reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
I::kExternalMemoryAtLastMarkCompactOffset);
const int64_t amount = *external_memory + change_in_bytes;
*external_memory = amount;
int64_t allocation_diff_since_last_mc =
*external_memory_at_last_mc - *external_memory;
allocation_diff_since_last_mc = allocation_diff_since_last_mc < 0
? -allocation_diff_since_last_mc
: allocation_diff_since_last_mc;
if (allocation_diff_since_last_mc > kMemoryReducerActivationLimit) {
CheckMemoryPressure();
}
if (change_in_bytes > 0 && amount > external_memory_limit) {
ReportExternalAllocationLimitReached();
}
......
......@@ -8142,6 +8142,10 @@ void Isolate::ReportExternalAllocationLimitReached() {
heap->ReportExternalMemoryPressure();
}
void Isolate::CheckMemoryPressure() {
i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap();
heap->CheckMemoryPressure();
}
HeapProfiler* Isolate::GetHeapProfiler() {
i::HeapProfiler* heap_profiler =
......
......@@ -4516,10 +4516,12 @@ void Heap::CheckMemoryPressure() {
GarbageCollectionReason::kMemoryPressure);
}
}
MemoryReducer::Event event;
event.type = MemoryReducer::kPossibleGarbage;
event.time_ms = MonotonicallyIncreasingTimeInMs();
memory_reducer_->NotifyPossibleGarbage(event);
if (memory_reducer_) {
MemoryReducer::Event event;
event.type = MemoryReducer::kPossibleGarbage;
event.time_ms = MonotonicallyIncreasingTimeInMs();
memory_reducer_->NotifyPossibleGarbage(event);
}
}
void Heap::CollectGarbageOnMemoryPressure() {
......
......@@ -2831,6 +2831,9 @@ bool Isolate::Init(Deserializer* des) {
Internals::kExternalMemoryOffset);
CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, heap_.external_memory_limit_)),
Internals::kExternalMemoryLimitOffset);
CHECK_EQ(static_cast<int>(
OFFSET_OF(Isolate, heap_.external_memory_at_last_mark_compact_)),
Internals::kExternalMemoryAtLastMarkCompactOffset);
time_millis_at_init_ = heap_.MonotonicallyIncreasingTimeInMs();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment