Commit 132c7dc3 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Fix nits in PartitionAlloc code.

- Fix #includes / remove unused ones.
- Fix some lint errors.
- Fix nits and use more constexpr.

Change-Id: I73af034b6855b4b7e4456aee6c1ae544cc7216b0
Reviewed-on: https://chromium-review.googlesource.com/1250641
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarChris Palmer <palmer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595296}
parent 8fca5bbd
......@@ -4,10 +4,10 @@
#include "base/allocator/partition_allocator/address_space_randomization.h"
#include <vector>
#include "base/allocator/partition_allocator/page_allocator.h"
#include "base/bit_cast.h"
#include "base/bits.h"
#include "base/sys_info.h"
#include "base/logging.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
......
......@@ -6,18 +6,16 @@
#include <limits.h>
#include <atomic>
#include "base/allocator/partition_allocator/address_space_randomization.h"
#include "base/allocator/partition_allocator/page_allocator_internal.h"
#include "base/allocator/partition_allocator/spin_lock.h"
#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/numerics/checked_math.h"
#include "build/build_config.h"
#include <atomic>
#if defined(OS_WIN)
#include <windows.h>
#endif
......
......@@ -8,14 +8,16 @@
#include <errno.h>
#include <sys/mman.h>
#include "build/build_config.h"
#if defined(OS_MACOSX)
#include <mach/mach.h>
#endif
#if defined(OS_LINUX)
#include <sys/resource.h>
#endif
#include "build/build_config.h"
#include <algorithm>
#endif
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
......@@ -24,7 +26,7 @@
namespace base {
// |mmap| uses a nearby address if the hint address is blocked.
const bool kHintIsAdvisory = true;
constexpr bool kHintIsAdvisory = true;
std::atomic<int32_t> s_allocPageErrorCode{0};
int GetAccessFlags(PageAccessibilityConfiguration accessibility) {
......
......@@ -10,7 +10,7 @@
namespace base {
// |VirtualAlloc| will fail if allocation at the hint address is blocked.
const bool kHintIsAdvisory = false;
constexpr bool kHintIsAdvisory = false;
std::atomic<int32_t> s_allocPageErrorCode{ERROR_SUCCESS};
int GetAccessFlags(PageAccessibilityConfiguration accessibility) {
......
......@@ -5,50 +5,48 @@
#include "base/allocator/partition_allocator/partition_alloc.h"
#include <string.h>
#include <memory>
#include <type_traits>
#include "base/allocator/partition_allocator/partition_direct_map_extent.h"
#include "base/allocator/partition_allocator/partition_oom.h"
#include "base/allocator/partition_allocator/partition_page.h"
#include "base/allocator/partition_allocator/spin_lock.h"
#include "base/compiler_specific.h"
#include "base/lazy_instance.h"
namespace base {
// Two partition pages are used as guard / metadata page so make sure the super
// page size is bigger.
static_assert(base::kPartitionPageSize * 4 <= base::kSuperPageSize,
"ok super page size");
static_assert(!(base::kSuperPageSize % base::kPartitionPageSize),
"ok super page multiple");
static_assert(kPartitionPageSize * 4 <= kSuperPageSize, "ok super page size");
static_assert(!(kSuperPageSize % kPartitionPageSize), "ok super page multiple");
// Four system pages gives us room to hack out a still-guard-paged piece
// of metadata in the middle of a guard partition page.
static_assert(base::kSystemPageSize * 4 <= base::kPartitionPageSize,
static_assert(kSystemPageSize * 4 <= kPartitionPageSize,
"ok partition page size");
static_assert(!(base::kPartitionPageSize % base::kSystemPageSize),
static_assert(!(kPartitionPageSize % kSystemPageSize),
"ok partition page multiple");
static_assert(sizeof(base::internal::PartitionPage) <= base::kPageMetadataSize,
static_assert(sizeof(internal::PartitionPage) <= kPageMetadataSize,
"PartitionPage should not be too big");
static_assert(sizeof(base::internal::PartitionBucket) <=
base::kPageMetadataSize,
static_assert(sizeof(internal::PartitionBucket) <= kPageMetadataSize,
"PartitionBucket should not be too big");
static_assert(sizeof(base::internal::PartitionSuperPageExtentEntry) <=
base::kPageMetadataSize,
static_assert(sizeof(internal::PartitionSuperPageExtentEntry) <=
kPageMetadataSize,
"PartitionSuperPageExtentEntry should not be too big");
static_assert(base::kPageMetadataSize * base::kNumPartitionPagesPerSuperPage <=
base::kSystemPageSize,
static_assert(kPageMetadataSize * kNumPartitionPagesPerSuperPage <=
kSystemPageSize,
"page metadata fits in hole");
// Limit to prevent callers accidentally overflowing an int size.
static_assert(base::kGenericMaxDirectMapped <=
(1UL << 31) + base::kPageAllocationGranularity,
static_assert(kGenericMaxDirectMapped <=
(1UL << 31) + kPageAllocationGranularity,
"maximum direct mapped allocation");
// Check that some of our zanier calculations worked out as expected.
static_assert(base::kGenericSmallestBucket == 8, "generic smallest bucket");
static_assert(base::kGenericMaxBucketed == 983040, "generic max bucketed");
static_assert(base::kMaxSystemPagesPerSlotSpan < (1 << 8),
static_assert(kGenericSmallestBucket == 8, "generic smallest bucket");
static_assert(kGenericMaxBucketed == 983040, "generic max bucketed");
static_assert(kMaxSystemPagesPerSlotSpan < (1 << 8),
"System pages per slot span must be less than 128.");
namespace base {
internal::PartitionRootBase::PartitionRootBase() = default;
internal::PartitionRootBase::~PartitionRootBase() = default;
PartitionRoot::PartitionRoot() = default;
......@@ -689,11 +687,12 @@ void PartitionRoot::DumpStats(const char* partition_name,
stats.total_committed_bytes = this->total_size_of_committed_pages;
DCHECK(!this->total_size_of_direct_mapped_pages);
static const size_t kMaxReportableBuckets = 4096 / sizeof(void*);
static constexpr size_t kMaxReportableBuckets = 4096 / sizeof(void*);
std::unique_ptr<PartitionBucketMemoryStats[]> memory_stats;
if (!is_light_dump)
if (!is_light_dump) {
memory_stats = std::unique_ptr<PartitionBucketMemoryStats[]>(
new PartitionBucketMemoryStats[kMaxReportableBuckets]);
}
const size_t partition_num_buckets = this->num_buckets;
DCHECK(partition_num_buckets <= kMaxReportableBuckets);
......
......@@ -74,7 +74,7 @@
#include "base/bits.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "base/sys_byteorder.h"
#include "build/build_config.h"
......@@ -431,7 +431,7 @@ class SizeSpecificPartitionAllocator {
public:
SizeSpecificPartitionAllocator() {
memset(actual_buckets_, 0,
sizeof(internal::PartitionBucket) * arraysize(actual_buckets_));
sizeof(internal::PartitionBucket) * base::size(actual_buckets_));
}
~SizeSpecificPartitionAllocator() = default;
static const size_t kMaxAllocation = N - kAllocationGranularity;
......
......@@ -8,7 +8,6 @@
#include <limits.h>
#include "base/allocator/partition_allocator/page_allocator_constants.h"
#include "base/bits.h"
#include "base/logging.h"
namespace base {
......
......@@ -7,13 +7,12 @@
#include <stdlib.h>
#include <string.h>
#include <limits>
#include <memory>
#include <vector>
#include "base/allocator/partition_allocator/address_space_randomization.h"
#include "base/allocator/partition_allocator/partition_alloc.h"
#include "base/bit_cast.h"
#include "base/bits.h"
#include "base/rand_util.h"
#include "base/stl_util.h"
#include "base/sys_info.h"
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/allocator/partition_allocator/partition_bucket.h"
#include "base/allocator/partition_allocator/oom.h"
#include "base/allocator/partition_allocator/page_allocator.h"
#include "base/allocator/partition_allocator/partition_alloc_constants.h"
......@@ -160,7 +161,8 @@ uint8_t PartitionBucket::get_system_pages_per_slot_span() {
? (kNumSystemPagesPerPartitionPage - num_remainder_pages)
: 0;
waste += sizeof(void*) * num_unfaulted_pages;
double waste_ratio = (double)waste / (double)page_size;
double waste_ratio =
static_cast<double>(waste) / static_cast<double>(page_size);
if (waste_ratio < best_waste_ratio) {
best_waste_ratio = waste_ratio;
best_pages = i;
......
......@@ -13,9 +13,9 @@ namespace internal {
#if DCHECK_IS_ON()
// Handles alignment up to XMM instructions on Intel.
static const size_t kCookieSize = 16;
static constexpr size_t kCookieSize = 16;
static const unsigned char kCookieValue[kCookieSize] = {
static constexpr unsigned char kCookieValue[kCookieSize] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xD0, 0x0D,
0x13, 0x37, 0xF0, 0x05, 0xBA, 0x11, 0xAB, 0x1E};
#endif
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/allocator/partition_allocator/spin_lock.h"
#include "base/threading/platform_thread.h"
#include "build/build_config.h"
#if defined(OS_WIN)
......@@ -11,8 +12,6 @@
#include <sched.h>
#endif
#include "base/threading/platform_thread.h"
// The YIELD_PROCESSOR macro wraps an architecture specific-instruction that
// informs the processor we're in a busy wait, so it can handle the branch more
// intelligently and e.g. reduce power to our core or give more resources to the
......@@ -94,7 +93,7 @@ void SpinLock::LockSlow() {
// thread that is unavailable to finish its work because of higher
// priority threads spinning here. Sleeping should ensure that they make
// progress.
PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
PlatformThread::Sleep(TimeDelta::FromMilliseconds(1));
}
} while (lock_.load(std::memory_order_relaxed));
} while (UNLIKELY(lock_.exchange(true, std::memory_order_acquire)));
......
......@@ -5,6 +5,7 @@
#include "base/allocator/partition_allocator/spin_lock.h"
#include <memory>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/threading/thread.h"
......@@ -12,7 +13,7 @@
namespace base {
static const size_t kBufferSize = 16;
static constexpr size_t kBufferSize = 16;
static subtle::SpinLock g_lock;
......
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