Chromium Code Reviews| Index: base/memory/discardable_shared_memory.cc |
| diff --git a/base/memory/discardable_shared_memory.cc b/base/memory/discardable_shared_memory.cc |
| index 1b50da260e09b566807fb40e72a1ab0638db11d3..3d03bf375586e0cdaec2d161446839b08c9f0f8e 100644 |
| --- a/base/memory/discardable_shared_memory.cc |
| +++ b/base/memory/discardable_shared_memory.cc |
| @@ -21,6 +21,10 @@ |
| #include "third_party/ashmem/ashmem.h" |
| #endif |
| +#if defined(OS_WIN) |
| +#include "base/win/windows_version.h" |
| +#endif |
| + |
| namespace base { |
| namespace { |
| @@ -214,6 +218,7 @@ DiscardableSharedMemory::LockResult DiscardableSharedMemory::Lock( |
| DCHECK_EQ(locked_pages_.size(), locked_page_count_); |
| #endif |
| +// Pin pages if supported. |
| #if defined(OS_ANDROID) |
| SharedMemoryHandle handle = shared_memory_.handle(); |
| if (SharedMemory::IsHandleValid(handle)) { |
| @@ -222,6 +227,14 @@ DiscardableSharedMemory::LockResult DiscardableSharedMemory::Lock( |
| return PURGED; |
| } |
| } |
| +#elif defined(OS_WIN) |
| + if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
|
jschuh
2015/11/03 05:11:24
Save the version off into a static, otherwise you'
penny
2015/11/03 18:25:44
In upload #1 I was doing a lazy init of a static v
brucedawson
2015/11/04 21:51:27
Both options are quite cheap, with the exact cost
jschuh
2015/11/04 21:52:43
Honestly, I prefer the other but I don't feel stro
penny
2015/11/05 18:45:19
Thanks Bruce and Justin for input here. I don't f
|
| + if (!VirtualAlloc(reinterpret_cast<char*>(shared_memory_.memory()) + |
| + AlignToPageSize(sizeof(SharedState)) + offset, |
| + length, MEM_RESET_UNDO, PAGE_READWRITE)) { |
| + return PURGED; |
| + } |
| + } |
| #endif |
| return SUCCESS; |
| @@ -240,6 +253,7 @@ void DiscardableSharedMemory::Unlock(size_t offset, size_t length) { |
| DCHECK(shared_memory_.memory()); |
| +// Unpin pages if supported. |
| #if defined(OS_ANDROID) |
| SharedMemoryHandle handle = shared_memory_.handle(); |
| if (SharedMemory::IsHandleValid(handle)) { |
| @@ -248,7 +262,15 @@ void DiscardableSharedMemory::Unlock(size_t offset, size_t length) { |
| DPLOG(ERROR) << "ashmem_unpin_region() failed"; |
| } |
| } |
| +#elif defined(OS_WIN) |
| + if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
|
jschuh
2015/11/03 05:11:24
This shouldn't be version gated. It's supported on
penny
2015/11/03 18:25:44
So this is in the Unlock function, and needs to ma
jschuh
2015/11/04 21:52:43
Fair enough, this should be biased to preserving t
penny
2015/11/05 18:45:20
I've updated the comments to try to provide clarit
|
| + if (!VirtualAlloc(reinterpret_cast<char*>(shared_memory_.memory()) + |
| + AlignToPageSize(sizeof(SharedState)) + offset, |
| + length, MEM_RESET, PAGE_READWRITE)) { |
| + DPLOG(ERROR) << "VirtualAlloc() MEM_RESET failed in Unlock()"; |
| + } |
| #endif |
| +} |
|
jschuh
2015/11/03 05:11:24
Looks like the indentation is wrong and it should
penny
2015/11/03 18:25:44
Done.
|
| size_t start = offset / base::GetPageSize(); |
| size_t end = start + length / base::GetPageSize(); |
| @@ -340,6 +362,14 @@ bool DiscardableSharedMemory::Purge(Time current_time) { |
| AlignToPageSize(mapped_size_), MADV_PURGE_ARGUMENT)) { |
| DPLOG(ERROR) << "madvise() failed"; |
| } |
| +#elif defined(OS_WIN) |
| + // MEM_DECOMMIT the purged pages to release the physical storage, |
| + // either in memory or in the paging file on disk. Pages remain RESERVED. |
| + if (!VirtualFree(reinterpret_cast<char*>(shared_memory_.memory()) + |
|
jschuh
2015/11/03 05:11:24
This doesn't look like what you want -- it's basic
penny
2015/11/03 18:25:44
So a few notes:
- We don't need to guarantee any s
brucedawson
2015/11/04 21:51:27
MEM_DECOMMIT will indeed free up the pages, making
jschuh
2015/11/04 21:52:43
Okay, please tweak the comment above on the OS_POS
penny
2015/11/05 18:45:20
I've added comments for this section, providing mo
|
| + AlignToPageSize(sizeof(SharedState)), |
| + AlignToPageSize(mapped_size_), MEM_DECOMMIT)) { |
| + DPLOG(ERROR) << "VirtualFree() MEM_DECOMMIT failed in Purge()"; |
| + } |
| #endif |
| last_known_usage_ = Time(); |