| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/memory/discardable_shared_memory.h" | 5 #include "base/memory/discardable_shared_memory.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 // purge and releases its own references. | 337 // purge and releases its own references. |
| 338 // Note: this memory will not be accessed again. The segment will be | 338 // Note: this memory will not be accessed again. The segment will be |
| 339 // freed asynchronously at a later time, so just do the best | 339 // freed asynchronously at a later time, so just do the best |
| 340 // immediately. | 340 // immediately. |
| 341 #if defined(OS_POSIX) && !defined(OS_NACL) | 341 #if defined(OS_POSIX) && !defined(OS_NACL) |
| 342 // Linux and Android provide MADV_REMOVE which is preferred as it has a | 342 // Linux and Android provide MADV_REMOVE which is preferred as it has a |
| 343 // behavior that can be verified in tests. Other POSIX flavors (MacOSX, BSDs), | 343 // behavior that can be verified in tests. Other POSIX flavors (MacOSX, BSDs), |
| 344 // provide MADV_FREE which has the same result but memory is purged lazily. | 344 // provide MADV_FREE which has the same result but memory is purged lazily. |
| 345 #if defined(OS_LINUX) || defined(OS_ANDROID) | 345 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 346 #define MADV_PURGE_ARGUMENT MADV_REMOVE | 346 #define MADV_PURGE_ARGUMENT MADV_REMOVE |
| 347 #elif defined(OS_MACOSX) |
| 348 // MADV_FREE_REUSABLE is similar to MADV_FREE, but also marks the pages with the |
| 349 // reusable bit, which allows both Activity Monitor and memory-infra to |
| 350 // correctly track the pages. |
| 351 #define MADV_PURGE_ARGUMENT MADV_FREE_REUSABLE |
| 347 #else | 352 #else |
| 348 #define MADV_PURGE_ARGUMENT MADV_FREE | 353 #define MADV_PURGE_ARGUMENT MADV_FREE |
| 349 #endif | 354 #endif |
| 350 // Advise the kernel to remove resources associated with purged pages. | 355 // Advise the kernel to remove resources associated with purged pages. |
| 351 // Subsequent accesses of memory pages will succeed, but might result in | 356 // Subsequent accesses of memory pages will succeed, but might result in |
| 352 // zero-fill-on-demand pages. | 357 // zero-fill-on-demand pages. |
| 353 if (madvise(reinterpret_cast<char*>(shared_memory_.memory()) + | 358 if (madvise(reinterpret_cast<char*>(shared_memory_.memory()) + |
| 354 AlignToPageSize(sizeof(SharedState)), | 359 AlignToPageSize(sizeof(SharedState)), |
| 355 AlignToPageSize(mapped_size_), MADV_PURGE_ARGUMENT)) { | 360 AlignToPageSize(mapped_size_), MADV_PURGE_ARGUMENT)) { |
| 356 DPLOG(ERROR) << "madvise() failed"; | 361 DPLOG(ERROR) << "madvise() failed"; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 395 |
| 391 void DiscardableSharedMemory::Close() { | 396 void DiscardableSharedMemory::Close() { |
| 392 shared_memory_.Close(); | 397 shared_memory_.Close(); |
| 393 } | 398 } |
| 394 | 399 |
| 395 Time DiscardableSharedMemory::Now() const { | 400 Time DiscardableSharedMemory::Now() const { |
| 396 return Time::Now(); | 401 return Time::Now(); |
| 397 } | 402 } |
| 398 | 403 |
| 399 } // namespace base | 404 } // namespace base |
| OLD | NEW |