Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(994)

Side by Side Diff: base/metrics/persistent_memory_allocator.cc

Issue 2970883002: Reduce memory usage in DelayedPersistentAllocation. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/metrics/persistent_memory_allocator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/metrics/persistent_memory_allocator.h" 5 #include "base/metrics/persistent_memory_allocator.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
11 #include "winbase.h" 11 #include "winbase.h"
12 #elif defined(OS_POSIX) 12 #elif defined(OS_POSIX)
13 #include <sys/mman.h> 13 #include <sys/mman.h>
14 #endif 14 #endif
15 15
16 #include "base/files/memory_mapped_file.h" 16 #include "base/files/memory_mapped_file.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/memory/shared_memory.h" 18 #include "base/memory/shared_memory.h"
19 #include "base/metrics/histogram_macros.h" 19 #include "base/metrics/histogram_macros.h"
20 #include "base/metrics/sparse_histogram.h" 20 #include "base/metrics/sparse_histogram.h"
21 #include "base/numerics/safe_conversions.h"
21 #include "base/threading/thread_restrictions.h" 22 #include "base/threading/thread_restrictions.h"
22 23
23 namespace { 24 namespace {
24 25
25 // Limit of memory segment size. It has to fit in an unsigned 32-bit number 26 // Limit of memory segment size. It has to fit in an unsigned 32-bit number
26 // and should be a power of 2 in order to accomodate almost any page size. 27 // and should be a power of 2 in order to accomodate almost any page size.
27 const uint32_t kSegmentMaxSize = 1 << 30; // 1 GiB 28 const uint32_t kSegmentMaxSize = 1 << 30; // 1 GiB
28 29
29 // A constant (random) value placed in the shared metadata to identify 30 // A constant (random) value placed in the shared metadata to identify
30 // an already initialized memory segment. 31 // an already initialized memory segment.
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 // Real constructor. 1117 // Real constructor.
1117 DelayedPersistentAllocation::DelayedPersistentAllocation( 1118 DelayedPersistentAllocation::DelayedPersistentAllocation(
1118 PersistentMemoryAllocator* allocator, 1119 PersistentMemoryAllocator* allocator,
1119 std::atomic<Reference>* ref, 1120 std::atomic<Reference>* ref,
1120 uint32_t type, 1121 uint32_t type,
1121 size_t size, 1122 size_t size,
1122 size_t offset, 1123 size_t offset,
1123 bool make_iterable) 1124 bool make_iterable)
1124 : allocator_(allocator), 1125 : allocator_(allocator),
1125 type_(type), 1126 type_(type),
1126 size_(size), 1127 size_(checked_cast<uint32_t>(size)),
1127 offset_(offset), 1128 offset_(checked_cast<uint32_t>(offset)),
1128 make_iterable_(make_iterable), 1129 make_iterable_(make_iterable),
1129 reference_(ref) { 1130 reference_(ref) {
1130 DCHECK(allocator_); 1131 DCHECK(allocator_);
1131 DCHECK_NE(0U, type_); 1132 DCHECK_NE(0U, type_);
1132 DCHECK_LT(0U, size_); 1133 DCHECK_LT(0U, size_);
1133 DCHECK(reference_); 1134 DCHECK(reference_);
1134 } 1135 }
1135 1136
1136 DelayedPersistentAllocation::~DelayedPersistentAllocation() {} 1137 DelayedPersistentAllocation::~DelayedPersistentAllocation() {}
1137 1138
(...skipping 30 matching lines...) Expand all
1168 if (!mem) { 1169 if (!mem) {
1169 // This should never happen but be tolerant if it does as corruption from 1170 // This should never happen but be tolerant if it does as corruption from
1170 // the outside is something to guard against. 1171 // the outside is something to guard against.
1171 NOTREACHED(); 1172 NOTREACHED();
1172 return nullptr; 1173 return nullptr;
1173 } 1174 }
1174 return mem + offset_; 1175 return mem + offset_;
1175 } 1176 }
1176 1177
1177 } // namespace base 1178 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/persistent_memory_allocator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698