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

Side by Side Diff: base/allocator/partition_allocator/page_allocator.cc

Issue 2818623004: Use MADV_FREE_REUSABLE instead of MADV_FREE in partition alloc for macOS. (Closed)
Patch Set: Add comments Created 3 years, 8 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 | « no previous file | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/allocator/partition_allocator/page_allocator.h" 5 #include "base/allocator/partition_allocator/page_allocator.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <atomic> 9 #include <atomic>
10 10
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 #if defined(OS_POSIX) 209 #if defined(OS_POSIX)
210 return !mprotect(address, length, PROT_READ | PROT_WRITE); 210 return !mprotect(address, length, PROT_READ | PROT_WRITE);
211 #else 211 #else
212 return !!VirtualAlloc(address, length, MEM_COMMIT, PAGE_READWRITE); 212 return !!VirtualAlloc(address, length, MEM_COMMIT, PAGE_READWRITE);
213 #endif 213 #endif
214 } 214 }
215 215
216 void DecommitSystemPages(void* address, size_t length) { 216 void DecommitSystemPages(void* address, size_t length) {
217 DCHECK(!(length & kSystemPageOffsetMask)); 217 DCHECK(!(length & kSystemPageOffsetMask));
218 #if defined(OS_POSIX) 218 #if defined(OS_POSIX)
219 #if defined(OS_MACOSX)
220 // On macOS, MADV_FREE_REUSABLE has comparable behavior to MADV_FREE, but also
221 // marks the pages with the reusable bit, which allows both Activity Monitor
222 // and memory-infra to correctly track the pages.
223 int ret = madvise(address, length, MADV_FREE_REUSABLE);
224 #else
219 int ret = madvise(address, length, MADV_FREE); 225 int ret = madvise(address, length, MADV_FREE);
226 #endif
220 if (ret != 0 && errno == EINVAL) { 227 if (ret != 0 && errno == EINVAL) {
221 // MADV_FREE only works on Linux 4.5+ . If request failed, 228 // MADV_FREE only works on Linux 4.5+ . If request failed,
222 // retry with older MADV_DONTNEED . Note that MADV_FREE 229 // retry with older MADV_DONTNEED . Note that MADV_FREE
223 // being defined at compile time doesn't imply runtime support. 230 // being defined at compile time doesn't imply runtime support.
224 ret = madvise(address, length, MADV_DONTNEED); 231 ret = madvise(address, length, MADV_DONTNEED);
225 } 232 }
226 CHECK(!ret); 233 CHECK(!ret);
227 #else 234 #else
228 SetSystemPagesInaccessible(address, length); 235 SetSystemPagesInaccessible(address, length);
229 #endif 236 #endif
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 CHECK(ret); 277 CHECK(ret);
271 } 278 }
272 #endif 279 #endif
273 } 280 }
274 281
275 uint32_t GetAllocPageErrorCode() { 282 uint32_t GetAllocPageErrorCode() {
276 return s_allocPageErrorCode; 283 return s_allocPageErrorCode;
277 } 284 }
278 285
279 } // namespace base 286 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698