Skip to content

Commit 0e87827

Browse files
rmacnak-googledart-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[vm, gc] Increase page size to 2 MB.
This is usually the superpage size. Now that TLABs are decoupled from pages, this won't reduce the mutator limit. Now that major GCs include incremental compaction, this shouldn't have a large effect on fragmentation. TEST=ci Change-Id: Ib21603687e24ceee2fb863d3490490dd4f9a784f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/563360 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent fb9f224 commit 0e87827

10 files changed

Lines changed: 71 additions & 59 deletions

File tree

‎pkg/native_compiler/lib/runtime/vm_offsets.g.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ final class Arm64VMOffsets extends VMOffsets {
747747
@override
748748
int get Page_kBytesPerCardLog2 => 0x8;
749749
@override
750-
int get Page_kPageMask => -0x80000;
750+
int get Page_kPageMask => -0x200000;
751751
@override
752752
int get Record_kMaxElements => 0xffff;
753753
@override
@@ -1824,7 +1824,7 @@ final class Arm64ProductVMOffsets extends VMOffsets {
18241824
@override
18251825
int get Page_kBytesPerCardLog2 => 0x8;
18261826
@override
1827-
int get Page_kPageMask => -0x80000;
1827+
int get Page_kPageMask => -0x200000;
18281828
@override
18291829
int get Record_kMaxElements => 0xffff;
18301830
@override

‎runtime/tests/vm/dart/language/regress_16873_test.dart‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
4-
// VMOptions=--new_gen_semi_max_size=1 --no_inline_alloc
4+
5+
// VMOptions=--new_gen_semi_max_size=2 --no_inline_alloc
56

67
// Regression test for slow-path allocation in the allocation stub.
78

‎runtime/tests/vm/dart/reachability_test.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
4-
//
5-
// VMOptions=--new_gen_semi_max_size=1
4+
5+
// VMOptions=--new_gen_semi_max_size=2
66

77
import 'dart:_internal' show VMInternalsForTesting;
88
import 'dart:developer';

‎runtime/vm/compiler/runtime_offsets_extracted.h‎

Lines changed: 30 additions & 30 deletions
Large diffs are not rendered by default.

‎runtime/vm/flag_list.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ constexpr bool FLAG_support_il_printer = false;
155155
P(modular_aot_mode, bool, false, "Modular AOT compiler mode") \
156156
P(new_gen_semi_max_size, int, kDefaultNewGenSemiMaxSize, \
157157
"Max size of new gen semi space in MB") \
158-
P(new_gen_semi_initial_size, int, (kWordSize <= 4) ? 1 : 2, \
158+
P(new_gen_semi_initial_size, int, (kWordSize <= 4) ? 2 : 4, \
159159
"Initial size of new gen semi space in MB") \
160160
P(optimization_counter_threshold, int, kDefaultOptimizationCounterThreshold, \
161161
"Function's usage-counter value before it is optimized, -1 means never") \

‎runtime/vm/flags.cc‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "vm/flags.h"
66

77
#include "platform/assert.h"
8+
#include "vm/heap/page.h"
89
#include "vm/isolate.h"
910
#include "vm/json_stream.h"
1011
#include "vm/os.h"
@@ -559,6 +560,13 @@ char* Flags::CheckFlags() {
559560
return Utils::StrDup("Invalid compactor_tasks");
560561
}
561562

563+
if (FLAG_new_gen_semi_initial_size * MB < Page::kPageSize) {
564+
return Utils::StrDup("Invalid new_gen_semi_initial_size");
565+
}
566+
if (FLAG_new_gen_semi_max_size * MB < Page::kPageSize) {
567+
return Utils::StrDup("Invalid new_gen_semi_max_size");
568+
}
569+
562570
return nullptr;
563571
}
564572

‎runtime/vm/heap/page.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Page {
4444
// object can be computed by masking the object with kPageMask.
4545
// This does not apply to image pages, whose address is chosen by the system
4646
// loader rather than the Dart VM.
47-
static constexpr intptr_t kPageSize = 512 * KB;
47+
static constexpr intptr_t kPageSize = 2 * MB;
4848
static constexpr intptr_t kPageSizeInWords = kPageSize / kWordSize;
4949
static constexpr intptr_t kPageMask = ~(kPageSize - 1);
5050

@@ -342,7 +342,7 @@ class PageCache {
342342
// to fit a complete from-space into this cache. The standalone embedder sets
343343
// the semispace size to 16/32MB. This cache is in units of regular heap
344344
// pages, which are 512kB (Page::kPageSize).
345-
static constexpr intptr_t kCapacity = 128 * kWordSize;
345+
static constexpr intptr_t kCapacity = (4 * kWordSize * MB) / Page::kPageSize;
346346
Mutex mutex_;
347347
VirtualMemory* cache_[2][kCapacity] = {{nullptr}, {nullptr}};
348348
intptr_t size_[2] = {0, 0};

‎runtime/vm/heap/pages.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ DEFINE_FLAG(int,
3535
"The desired maximum percentage of time spent in old gen GC");
3636
DEFINE_FLAG(int,
3737
old_gen_growth_rate,
38-
280,
38+
70,
3939
"The max number of pages the old generation can grow at a time");
4040
DEFINE_FLAG(bool, log_growth, false, "Log PageSpace growth policy decisions.");
4141

‎runtime/vm/heap/scavenger.cc‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1975,7 +1975,12 @@ void Scavenger::Scavenge(Thread* thread, GCType type, GCReason reason) {
19751975
}
19761976
SemiSpace* from = Prologue(reason);
19771977

1978-
const intptr_t num_tasks = NumScavengeWorkers();
1978+
intptr_t num_tasks = NumScavengeWorkers();
1979+
intptr_t max_pages = to_->gc_threshold_in_words() / Page::kPageSizeInWords;
1980+
ASSERT(max_pages >= 1);
1981+
if (num_tasks > max_pages) {
1982+
num_tasks = max_pages;
1983+
}
19791984

19801985
ThreadBarrier* barrier = new ThreadBarrier(num_tasks, /*initial=*/1);
19811986
RelaxedAtomic<uintptr_t> num_busy = 0;

‎runtime/vm/virtual_memory_posix.cc‎

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,23 @@ static void* GenericMapAligned(void* hint,
131131
return reinterpret_cast<void*>(address);
132132
}
133133
#endif
134+
135+
#if (defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)) && \
136+
defined(ARCH_IS_64_BIT)
137+
// Usually. Might be larger on some arm64 configurations.
138+
constexpr intptr_t kSuperPageSize = 2 * MB;
139+
if (alignment == kSuperPageSize) {
140+
void* address = Map(nullptr, size, prot, map_flags, -1, 0);
141+
if (address != MAP_FAILED) {
142+
if (Utils::IsAligned(address, alignment)) [[likely]] {
143+
madvise(address, size, MADV_HUGEPAGE);
144+
return address;
145+
}
146+
munmap(address, size);
147+
}
148+
}
149+
#endif
150+
134151
void* address = Map(hint, allocated_size, prot, map_flags, -1, 0);
135152
if (address == MAP_FAILED) {
136153
return nullptr;
@@ -573,25 +590,6 @@ void VirtualMemory::Init() {
573590
}
574591
#endif
575592
#endif
576-
577-
#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
578-
FILE* fp = fopen("/proc/sys/vm/max_map_count", "r");
579-
if (fp != nullptr) {
580-
size_t max_map_count = 0;
581-
int count = fscanf(fp, "%zu", &max_map_count);
582-
fclose(fp);
583-
if (count == 1) {
584-
size_t max_heap_pages = FLAG_old_gen_heap_size * MB / Page::kPageSize;
585-
if (max_map_count < max_heap_pages) {
586-
OS::PrintErr(
587-
"warning: vm.max_map_count (%zu) is not large enough to support "
588-
"--old_gen_heap_size=%d. Consider increasing it with `sysctl -w "
589-
"vm.max_map_count=%zu`\n",
590-
max_map_count, FLAG_old_gen_heap_size, max_heap_pages);
591-
}
592-
}
593-
}
594-
#endif
595593
}
596594

597595
void VirtualMemory::Cleanup() {

0 commit comments

Comments
 (0)