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

Unified Diff: base/memory/discardable_shared_memory.cc

Issue 1427163003: [Discardable Shared Memory] Adding Windows support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review fixes part 1. Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..dc5b114bdd0ca46d29e7d3cfa6c105c8f66c19a2 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) {
+ 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) {
+ 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
+}
size_t start = offset / base::GetPageSize();
size_t end = start + length / base::GetPageSize();
@@ -340,6 +362,16 @@ 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.
+ // NOTE: this is the best that can be done from the browser, until the
+ // child/renderer notices the purge and releases its own handles.
reveman 2015/11/03 01:42:31 nit: concepts such as browser and renderer process
penny 2015/11/03 02:17:08 Done.
+ if (!VirtualFree(reinterpret_cast<char*>(shared_memory_.memory()) +
+ AlignToPageSize(sizeof(SharedState)),
+ AlignToPageSize(mapped_size_), MEM_DECOMMIT)) {
+ DPLOG(ERROR) << "VirtualFree() MEM_DECOMMIT failed in Purge()";
+ }
#endif
last_known_usage_ = Time();
« 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