1 // Copyright (c) 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_PAGE_ALLOCATOR_CONSTANTS_H_
6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PAGE_ALLOCATOR_CONSTANTS_H_
7 
8 #include <stddef.h>
9 
10 #include "build/build_config.h"
11 
12 namespace base {
13 #if defined(OS_WIN) || defined(ARCH_CPU_PPC64)
14 static constexpr size_t kPageAllocationGranularityShift = 16;  // 64KB
15 #elif defined(_MIPS_ARCH_LOONGSON)
16 static constexpr size_t kPageAllocationGranularityShift = 14;  // 16KB
17 #else
18 static constexpr size_t kPageAllocationGranularityShift = 12;  // 4KB
19 #endif
20 static constexpr size_t kPageAllocationGranularity =
21     1 << kPageAllocationGranularityShift;
22 static constexpr size_t kPageAllocationGranularityOffsetMask =
23     kPageAllocationGranularity - 1;
24 static constexpr size_t kPageAllocationGranularityBaseMask =
25     ~kPageAllocationGranularityOffsetMask;
26 
27 #if defined(_MIPS_ARCH_LOONGSON)
28 static constexpr size_t kSystemPageSize = 16384;
29 #elif defined(ARCH_CPU_PPC64)
30 // Modern ppc64 systems support 4KB and 64KB page sizes.
31 // Since 64KB is the de-facto standard on the platform
32 // and binaries compiled for 64KB are likely to work on 4KB systems,
33 // 64KB is a good choice here.
34 static constexpr size_t kSystemPageSize = 65536;
35 #else
36 static constexpr size_t kSystemPageSize = 4096;
37 #endif
38 static constexpr size_t kSystemPageOffsetMask = kSystemPageSize - 1;
39 static_assert((kSystemPageSize & (kSystemPageSize - 1)) == 0,
40               "kSystemPageSize must be power of 2");
41 static constexpr size_t kSystemPageBaseMask = ~kSystemPageOffsetMask;
42 
43 static constexpr size_t kPageMetadataShift = 5;  // 32 bytes per partition page.
44 static constexpr size_t kPageMetadataSize = 1 << kPageMetadataShift;
45 
46 }  // namespace base
47 
48 #endif  // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PAGE_ALLOCATOR_CONSTANTS_H_
49