Commit ad832c41 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

[heap, api] Keep lower limit when adjusting external memory

Previously explicit calls to external memory adjustment could yield in lowering
the limit below the initial default limit. The consequence is repeated useless
garbage collections when e.g. passing around ArrayBuffers.

Bug: chromium:880036
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I429f5adcd9ae523e5ac7621cf7976686b0dec71b
Reviewed-on: https://chromium-review.googlesource.com/1209784Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55694}
parent 5f0e0f63
......@@ -9480,6 +9480,10 @@ class Internals {
static const uint32_t kNumIsolateDataSlots = 4;
// Soft limit for AdjustAmountofExternalAllocatedMemory. Trigger an
// incremental GC once the external memory reaches this limit.
static constexpr int kExternalAllocationSoftLimit = 64 * 1024 * 1024;
V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
#ifdef V8_ENABLE_CHECKS
......@@ -10734,10 +10738,10 @@ int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
}
if (change_in_bytes < 0) {
*external_memory_limit += change_in_bytes;
}
if (change_in_bytes > 0 && amount > *external_memory_limit) {
const int64_t lower_limit = *external_memory_limit + change_in_bytes;
if (lower_limit > I::kExternalAllocationSoftLimit)
*external_memory_limit = lower_limit;
} else if (change_in_bytes > 0 && amount > *external_memory_limit) {
ReportExternalAllocationLimitReached();
}
return *external_memory;
......
......@@ -213,8 +213,8 @@ constexpr size_t kCodeRangeAreaAlignment = 4 * KB; // OS page.
constexpr size_t kReservedCodeRangePages = 0;
#endif
// Trigger an incremental GCs once the external memory reaches this limit.
constexpr int kExternalAllocationSoftLimit = 64 * MB;
constexpr int kExternalAllocationSoftLimit =
internal::Internals::kExternalAllocationSoftLimit;
// Maximum object size that gets allocated into regular pages. Objects larger
// than that size are allocated in large object space and are never moved in
......
......@@ -2299,7 +2299,8 @@ class Heap {
friend class heap::HeapTester;
FRIEND_TEST(HeapControllerTest, OldGenerationAllocationLimit);
FRIEND_TEST(HeapTest, ExternalLimitDefault);
FRIEND_TEST(HeapTest, ExternalLimitStaysAboveDefaultForExplicitHandling);
DISALLOW_COPY_AND_ASSIGN(Heap);
};
......
......@@ -59,5 +59,17 @@ TEST_F(HeapTest, ASLR) {
#endif // V8_TARGET_ARCH_X64
}
TEST_F(HeapTest, ExternalLimitDefault) {
Heap* heap = i_isolate()->heap();
EXPECT_EQ(kExternalAllocationSoftLimit, heap->external_memory_limit_);
}
TEST_F(HeapTest, ExternalLimitStaysAboveDefaultForExplicitHandling) {
v8_isolate()->AdjustAmountOfExternalAllocatedMemory(+10 * MB);
v8_isolate()->AdjustAmountOfExternalAllocatedMemory(-10 * MB);
Heap* heap = i_isolate()->heap();
EXPECT_GE(heap->external_memory_limit_, kExternalAllocationSoftLimit);
}
} // namespace internal
} // namespace v8
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