b5bbc97566
This reverts commit 48e93d3d3b.
Reason for revert: ~10% regression on Isolate.SendReceiveBytes benchmarks, likely heavy allocation and freeing of large heap pages
Original change's description:
> [vm, linux] Try to attach names to all VirtualMemory allocations using memfd.
>
> For example,
>
> $ cat /proc/<pid>/smaps
> ...
> 7fe527158000-7fe527be0000 rw-s 00000000 00:05 35765318 /memfd:dart-profiler (deleted)
> 7fe527be0000-7fe527ea5000 rw-s 00000000 00:05 35765317 /memfd:dart-timeline (deleted)
> 7fe528a40000-7fe528a51000 rw-s 00000000 00:05 35762832 /memfd:dart-heap (deleted)
> ...
>
> Change-Id: I10452a1261cec26719ceadf569aadd864be5378e
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/120981
> Commit-Queue: Ryan Macnak <rmacnak@google.com>
> Reviewed-by: Régis Crelier <regis@google.com>
TBR=rmacnak@google.com,zra@google.com,regis@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: Ic839bd0ce67d8ac438916d6b4c626f0f7d6991d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121412
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
92 lines
2.8 KiB
C++
92 lines
2.8 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "vm/virtual_memory.h"
|
|
#include "platform/assert.h"
|
|
#include "vm/heap/heap.h"
|
|
#include "vm/unit_test.h"
|
|
|
|
namespace dart {
|
|
|
|
bool IsZero(char* begin, char* end) {
|
|
for (char* current = begin; current < end; ++current) {
|
|
if (*current != 0) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
VM_UNIT_TEST_CASE(AllocateVirtualMemory) {
|
|
const intptr_t kVirtualMemoryBlockSize = 64 * KB;
|
|
VirtualMemory* vm =
|
|
VirtualMemory::Allocate(kVirtualMemoryBlockSize, false, NULL);
|
|
EXPECT(vm != NULL);
|
|
EXPECT(vm->address() != NULL);
|
|
EXPECT_EQ(kVirtualMemoryBlockSize, vm->size());
|
|
EXPECT_EQ(vm->start(), reinterpret_cast<uword>(vm->address()));
|
|
EXPECT_EQ(vm->start() + kVirtualMemoryBlockSize, vm->end());
|
|
EXPECT(vm->Contains(vm->start()));
|
|
EXPECT(vm->Contains(vm->start() + 1));
|
|
EXPECT(vm->Contains(vm->start() + kVirtualMemoryBlockSize - 1));
|
|
EXPECT(vm->Contains(vm->start() + (kVirtualMemoryBlockSize / 2)));
|
|
EXPECT(!vm->Contains(vm->start() - 1));
|
|
EXPECT(!vm->Contains(vm->end()));
|
|
EXPECT(!vm->Contains(vm->end() + 1));
|
|
EXPECT(!vm->Contains(0));
|
|
EXPECT(!vm->Contains(static_cast<uword>(-1)));
|
|
|
|
char* buf = reinterpret_cast<char*>(vm->address());
|
|
EXPECT(IsZero(buf, buf + vm->size()));
|
|
buf[0] = 'a';
|
|
buf[1] = 'c';
|
|
buf[2] = '/';
|
|
buf[3] = 'd';
|
|
buf[4] = 'c';
|
|
buf[5] = 0;
|
|
EXPECT_STREQ("ac/dc", buf);
|
|
|
|
delete vm;
|
|
}
|
|
|
|
VM_UNIT_TEST_CASE(AllocateAlignedVirtualMemory) {
|
|
intptr_t kHeapPageSize = kPageSize;
|
|
intptr_t kVirtualPageSize = 4096;
|
|
|
|
intptr_t kIterations = kHeapPageSize / kVirtualPageSize;
|
|
for (intptr_t i = 0; i < kIterations; i++) {
|
|
VirtualMemory* vm = VirtualMemory::AllocateAligned(
|
|
kHeapPageSize, kHeapPageSize, false, NULL);
|
|
EXPECT(Utils::IsAligned(vm->start(), kHeapPageSize));
|
|
EXPECT_EQ(kHeapPageSize, vm->size());
|
|
delete vm;
|
|
}
|
|
}
|
|
|
|
VM_UNIT_TEST_CASE(FreeVirtualMemory) {
|
|
// Reservations should always be handed back to OS upon destruction.
|
|
const intptr_t kVirtualMemoryBlockSize = 10 * MB;
|
|
const intptr_t kIterations = 900; // Enough to exhaust 32-bit address space.
|
|
for (intptr_t i = 0; i < kIterations; ++i) {
|
|
VirtualMemory* vm =
|
|
VirtualMemory::Allocate(kVirtualMemoryBlockSize, false, NULL);
|
|
delete vm;
|
|
}
|
|
// Check that truncation does not introduce leaks.
|
|
for (intptr_t i = 0; i < kIterations; ++i) {
|
|
VirtualMemory* vm =
|
|
VirtualMemory::Allocate(kVirtualMemoryBlockSize, false, NULL);
|
|
vm->Truncate(kVirtualMemoryBlockSize / 2);
|
|
delete vm;
|
|
}
|
|
for (intptr_t i = 0; i < kIterations; ++i) {
|
|
VirtualMemory* vm =
|
|
VirtualMemory::Allocate(kVirtualMemoryBlockSize, true, NULL);
|
|
vm->Truncate(0);
|
|
delete vm;
|
|
}
|
|
}
|
|
|
|
} // namespace dart
|