[heap] Cache OS commit page size in MemoryAllocator
We can cache this in a static field during V8 initialization such that we don't need to cache this method's result for each use-case that might benefit. Bug: v8:12691 Change-Id: I4391a5e306646465ce96fb7e354be996d9fe8b44 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3506375 Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> Cr-Commit-Position: refs/heads/main@{#79406}
This commit is contained in:
parent
0215c53789
commit
bc0c89b4a2
@ -521,6 +521,8 @@ void Isolate::InitializeOncePerProcess() {
|
|||||||
CHECK(isolate_key_created_.compare_exchange_strong(
|
CHECK(isolate_key_created_.compare_exchange_strong(
|
||||||
expected, true, std::memory_order_relaxed));
|
expected, true, std::memory_order_relaxed));
|
||||||
per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey();
|
per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey();
|
||||||
|
|
||||||
|
Heap::InitializeOncePerProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Isolate::DisposeOncePerProcess() {
|
void Isolate::DisposeOncePerProcess() {
|
||||||
|
@ -5835,6 +5835,11 @@ void Heap::InitializeHashSeed() {
|
|||||||
0, reinterpret_cast<byte*>(&new_hash_seed), kInt64Size);
|
0, reinterpret_cast<byte*>(&new_hash_seed), kInt64Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void Heap::InitializeOncePerProcess() {
|
||||||
|
MemoryAllocator::InitializeOncePerProcess();
|
||||||
|
}
|
||||||
|
|
||||||
void Heap::PrintMaxMarkingLimitReached() {
|
void Heap::PrintMaxMarkingLimitReached() {
|
||||||
PrintF("\n### Maximum marking limit reached = %.02lf\n",
|
PrintF("\n### Maximum marking limit reached = %.02lf\n",
|
||||||
max_marking_limit_reached_);
|
max_marking_limit_reached_);
|
||||||
|
@ -808,6 +808,9 @@ class Heap {
|
|||||||
// (Re-)Initialize hash seed from flag or RNG.
|
// (Re-)Initialize hash seed from flag or RNG.
|
||||||
void InitializeHashSeed();
|
void InitializeHashSeed();
|
||||||
|
|
||||||
|
// Invoked once for the process from V8::Initialize.
|
||||||
|
static void InitializeOncePerProcess();
|
||||||
|
|
||||||
// Bootstraps the object heap with the core set of objects required to run.
|
// Bootstraps the object heap with the core set of objects required to run.
|
||||||
// Returns whether it succeeded.
|
// Returns whether it succeeded.
|
||||||
bool CreateHeapObjects();
|
bool CreateHeapObjects();
|
||||||
|
@ -24,6 +24,9 @@ namespace internal {
|
|||||||
// MemoryAllocator
|
// MemoryAllocator
|
||||||
//
|
//
|
||||||
|
|
||||||
|
size_t MemoryAllocator::commit_page_size_ = 0;
|
||||||
|
size_t MemoryAllocator::commit_page_size_bits_ = 0;
|
||||||
|
|
||||||
MemoryAllocator::MemoryAllocator(Isolate* isolate,
|
MemoryAllocator::MemoryAllocator(Isolate* isolate,
|
||||||
v8::PageAllocator* code_page_allocator,
|
v8::PageAllocator* code_page_allocator,
|
||||||
size_t capacity)
|
size_t capacity)
|
||||||
@ -619,18 +622,16 @@ void MemoryAllocator::ZapBlock(Address start, size_t size,
|
|||||||
size >> kTaggedSizeLog2);
|
size >> kTaggedSizeLog2);
|
||||||
}
|
}
|
||||||
|
|
||||||
intptr_t MemoryAllocator::GetCommitPageSize() {
|
void MemoryAllocator::InitializeOncePerProcess() {
|
||||||
if (FLAG_v8_os_page_size != 0) {
|
commit_page_size_ =
|
||||||
DCHECK(base::bits::IsPowerOfTwo(FLAG_v8_os_page_size));
|
FLAG_v8_os_page_size > 0 ? FLAG_v8_os_page_size * KB : CommitPageSize();
|
||||||
return FLAG_v8_os_page_size * KB;
|
CHECK(base::bits::IsPowerOfTwo(commit_page_size_));
|
||||||
} else {
|
commit_page_size_bits_ = base::bits::WhichPowerOfTwo(commit_page_size_);
|
||||||
return CommitPageSize();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
base::AddressRegion MemoryAllocator::ComputeDiscardMemoryArea(Address addr,
|
base::AddressRegion MemoryAllocator::ComputeDiscardMemoryArea(Address addr,
|
||||||
size_t size) {
|
size_t size) {
|
||||||
size_t page_size = MemoryAllocator::GetCommitPageSize();
|
size_t page_size = GetCommitPageSize();
|
||||||
if (size < page_size + FreeSpace::kSize) {
|
if (size < page_size + FreeSpace::kSize) {
|
||||||
return base::AddressRegion(0, 0);
|
return base::AddressRegion(0, 0);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,18 @@ class MemoryAllocator {
|
|||||||
kConcurrentlyAndPool,
|
kConcurrentlyAndPool,
|
||||||
};
|
};
|
||||||
|
|
||||||
V8_EXPORT_PRIVATE static intptr_t GetCommitPageSize();
|
// Initialize page sizes field in V8::Initialize.
|
||||||
|
static void InitializeOncePerProcess();
|
||||||
|
|
||||||
|
V8_INLINE static intptr_t GetCommitPageSize() {
|
||||||
|
DCHECK_LT(0, commit_page_size_);
|
||||||
|
return commit_page_size_;
|
||||||
|
}
|
||||||
|
|
||||||
|
V8_INLINE static intptr_t GetCommitPageSizeBits() {
|
||||||
|
DCHECK_LT(0, commit_page_size_bits_);
|
||||||
|
return commit_page_size_bits_;
|
||||||
|
}
|
||||||
|
|
||||||
// Computes the memory area of discardable memory within a given memory area
|
// Computes the memory area of discardable memory within a given memory area
|
||||||
// [addr, addr+size) and returns the result as base::AddressRegion. If the
|
// [addr, addr+size) and returns the result as base::AddressRegion. If the
|
||||||
@ -383,6 +394,9 @@ class MemoryAllocator {
|
|||||||
base::Mutex executable_memory_mutex_;
|
base::Mutex executable_memory_mutex_;
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
|
V8_EXPORT_PRIVATE static size_t commit_page_size_;
|
||||||
|
V8_EXPORT_PRIVATE static size_t commit_page_size_bits_;
|
||||||
|
|
||||||
friend class heap::TestCodePageAllocatorScope;
|
friend class heap::TestCodePageAllocatorScope;
|
||||||
friend class heap::TestMemoryAllocatorScope;
|
friend class heap::TestMemoryAllocatorScope;
|
||||||
|
|
||||||
|
@ -857,14 +857,12 @@ TEST(ReadOnlySpaceMetrics_OnePage) {
|
|||||||
faked_space->ShrinkPages();
|
faked_space->ShrinkPages();
|
||||||
faked_space->Seal(ReadOnlySpace::SealMode::kDoNotDetachFromHeap);
|
faked_space->Seal(ReadOnlySpace::SealMode::kDoNotDetachFromHeap);
|
||||||
|
|
||||||
MemoryAllocator* allocator = heap->memory_allocator();
|
|
||||||
|
|
||||||
// Allocated objects size.
|
// Allocated objects size.
|
||||||
CHECK_EQ(faked_space->Size(), 16);
|
CHECK_EQ(faked_space->Size(), 16);
|
||||||
|
|
||||||
size_t committed_memory = RoundUp(
|
size_t committed_memory = RoundUp(
|
||||||
MemoryChunkLayout::ObjectStartOffsetInDataPage() + faked_space->Size(),
|
MemoryChunkLayout::ObjectStartOffsetInDataPage() + faked_space->Size(),
|
||||||
allocator->GetCommitPageSize());
|
MemoryAllocator::GetCommitPageSize());
|
||||||
|
|
||||||
// Amount of OS allocated memory.
|
// Amount of OS allocated memory.
|
||||||
CHECK_EQ(faked_space->CommittedMemory(), committed_memory);
|
CHECK_EQ(faked_space->CommittedMemory(), committed_memory);
|
||||||
@ -891,10 +889,9 @@ TEST(ReadOnlySpaceMetrics_AlignedAllocations) {
|
|||||||
CHECK_EQ(faked_space->CommittedMemory(), 0);
|
CHECK_EQ(faked_space->CommittedMemory(), 0);
|
||||||
CHECK_EQ(faked_space->CommittedPhysicalMemory(), 0);
|
CHECK_EQ(faked_space->CommittedPhysicalMemory(), 0);
|
||||||
|
|
||||||
MemoryAllocator* allocator = heap->memory_allocator();
|
|
||||||
// Allocate an object just under an OS page in size.
|
// Allocate an object just under an OS page in size.
|
||||||
int object_size =
|
int object_size =
|
||||||
static_cast<int>(allocator->GetCommitPageSize() - kApiTaggedSize);
|
static_cast<int>(MemoryAllocator::GetCommitPageSize() - kApiTaggedSize);
|
||||||
|
|
||||||
// TODO(v8:8875): Pointer compression does not enable aligned memory allocation
|
// TODO(v8:8875): Pointer compression does not enable aligned memory allocation
|
||||||
// yet.
|
// yet.
|
||||||
@ -926,7 +923,7 @@ TEST(ReadOnlySpaceMetrics_AlignedAllocations) {
|
|||||||
|
|
||||||
size_t committed_memory = RoundUp(
|
size_t committed_memory = RoundUp(
|
||||||
MemoryChunkLayout::ObjectStartOffsetInDataPage() + faked_space->Size(),
|
MemoryChunkLayout::ObjectStartOffsetInDataPage() + faked_space->Size(),
|
||||||
allocator->GetCommitPageSize());
|
MemoryAllocator::GetCommitPageSize());
|
||||||
|
|
||||||
CHECK_EQ(faked_space->CommittedMemory(), committed_memory);
|
CHECK_EQ(faked_space->CommittedMemory(), committed_memory);
|
||||||
CHECK_EQ(faked_space->CommittedPhysicalMemory(), committed_memory);
|
CHECK_EQ(faked_space->CommittedPhysicalMemory(), committed_memory);
|
||||||
@ -952,8 +949,6 @@ TEST(ReadOnlySpaceMetrics_TwoPages) {
|
|||||||
CHECK_EQ(faked_space->CommittedMemory(), 0);
|
CHECK_EQ(faked_space->CommittedMemory(), 0);
|
||||||
CHECK_EQ(faked_space->CommittedPhysicalMemory(), 0);
|
CHECK_EQ(faked_space->CommittedPhysicalMemory(), 0);
|
||||||
|
|
||||||
MemoryAllocator* allocator = heap->memory_allocator();
|
|
||||||
|
|
||||||
// Allocate an object that's too big to have more than one on a page.
|
// Allocate an object that's too big to have more than one on a page.
|
||||||
|
|
||||||
int object_size = RoundUp(
|
int object_size = RoundUp(
|
||||||
@ -976,7 +971,7 @@ TEST(ReadOnlySpaceMetrics_TwoPages) {
|
|||||||
// Amount of OS allocated memory.
|
// Amount of OS allocated memory.
|
||||||
size_t committed_memory_per_page =
|
size_t committed_memory_per_page =
|
||||||
RoundUp(MemoryChunkLayout::ObjectStartOffsetInDataPage() + object_size,
|
RoundUp(MemoryChunkLayout::ObjectStartOffsetInDataPage() + object_size,
|
||||||
allocator->GetCommitPageSize());
|
MemoryAllocator::GetCommitPageSize());
|
||||||
CHECK_EQ(faked_space->CommittedMemory(), 2 * committed_memory_per_page);
|
CHECK_EQ(faked_space->CommittedMemory(), 2 * committed_memory_per_page);
|
||||||
CHECK_EQ(faked_space->CommittedPhysicalMemory(),
|
CHECK_EQ(faked_space->CommittedPhysicalMemory(),
|
||||||
2 * committed_memory_per_page);
|
2 * committed_memory_per_page);
|
||||||
@ -985,7 +980,7 @@ TEST(ReadOnlySpaceMetrics_TwoPages) {
|
|||||||
// page headers.
|
// page headers.
|
||||||
size_t capacity_per_page =
|
size_t capacity_per_page =
|
||||||
RoundUp(MemoryChunkLayout::ObjectStartOffsetInDataPage() + object_size,
|
RoundUp(MemoryChunkLayout::ObjectStartOffsetInDataPage() + object_size,
|
||||||
allocator->GetCommitPageSize()) -
|
MemoryAllocator::GetCommitPageSize()) -
|
||||||
MemoryChunkLayout::ObjectStartOffsetInDataPage();
|
MemoryChunkLayout::ObjectStartOffsetInDataPage();
|
||||||
CHECK_EQ(faked_space->Capacity(), 2 * capacity_per_page);
|
CHECK_EQ(faked_space->Capacity(), 2 * capacity_per_page);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user