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

Unified Diff: third_party/WebKit/Source/wtf/PageAllocator.cpp

Issue 1390963003: Implement discardSystemPages on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 5 years, 2 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 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: third_party/WebKit/Source/wtf/PageAllocator.cpp
diff --git a/third_party/WebKit/Source/wtf/PageAllocator.cpp b/third_party/WebKit/Source/wtf/PageAllocator.cpp
index ece956f58c099c1c0d8d205b19493abfe1a595c3..20dfeeff5b20c8fdd5daeaba607eace2691e98bd 100644
--- a/third_party/WebKit/Source/wtf/PageAllocator.cpp
+++ b/third_party/WebKit/Source/wtf/PageAllocator.cpp
@@ -244,10 +244,21 @@ void discardSystemPages(void* addr, size_t len)
// decommitSystemPages() here to avoid code duplication.
decommitSystemPages(addr, len);
#else
- (void) addr;
- (void) len;
- // TODO(cevans): implement this using MEM_RESET for Windows, once we've
- // decided that the semantics are a match.
+ // On Windows discarded pages are not returned to the system immediately and
+ // not guaranteed to be zeroed when returned to the application.
+ using DiscardVirtualMemoryFunction = DWORD(WINAPI*)(PVOID virtualAddress, SIZE_T size);
+ static DiscardVirtualMemoryFunction discardVirtualMemory = reinterpret_cast<DiscardVirtualMemoryFunction>(-1);
+ if (discardVirtualMemory == reinterpret_cast<DiscardVirtualMemoryFunction>(-1))
+ discardVirtualMemory = reinterpret_cast<DiscardVirtualMemoryFunction>(GetProcAddress(GetModuleHandle(L"Kernel32.dll"), "DiscardVirtualMemory"));
+ // Use DiscardVirtualMemory when available because it releases faster than MEM_RESET.
+ DWORD ret = 1;
+ if (discardVirtualMemory)
+ ret = discardVirtualMemory(addr, len);
+ // DiscardVirtualMemory is buggy in Win10 SP0, so fall back to MEM_RESET on failure.
+ if (ret) {
+ void* ret = VirtualAlloc(addr, len, MEM_RESET, PAGE_READWRITE);
+ RELEASE_ASSERT(ret);
+ }
#endif
}
« 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