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

Unified Diff: third_party/tcmalloc/port.cc

Issue 222028: Rounds up VirtualAlloc calls on windows to dwAllocationGranularity to prevent fragmentation (Closed)
Patch Set: Created 11 years, 3 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/tcmalloc/port.cc
diff --git a/third_party/tcmalloc/port.cc b/third_party/tcmalloc/port.cc
index 578c8bac4eb63e3306379eb7e83cc20de34730cd..5c9cad5f3354356632fecc4a3bab7e1d488b65ca 100644
--- a/third_party/tcmalloc/port.cc
+++ b/third_party/tcmalloc/port.cc
@@ -71,7 +71,8 @@ int getpagesize() {
if (pagesize == 0) {
SYSTEM_INFO system_info;
GetSystemInfo(&system_info);
- pagesize = system_info.dwPageSize;
+ pagesize = std::max(system_info.dwPageSize,
+ system_info.dwAllocationGranularity);
}
return pagesize;
}
@@ -188,37 +189,35 @@ static SpinLock alloc_lock(SpinLock::LINKER_INITIALIZED);
// munmap's in the middle of the page, which is forbidden in windows.
extern void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size,
size_t alignment) {
- // Safest is to make actual_size same as input-size.
- if (actual_size) {
- *actual_size = size;
- }
-
SpinLockHolder sh(&alloc_lock);
// Align on the pagesize boundary
const int pagesize = getpagesize();
if (alignment < pagesize) alignment = pagesize;
size = ((size + alignment - 1) / alignment) * alignment;
- // Ask for extra memory if alignment > pagesize
- size_t extra = 0;
- if (alignment > pagesize) {
- extra = alignment - pagesize;
+ // Safest is to make actual_size same as input-size.
jar (doing other things) 2009/09/24 23:24:34 The unexplained "safest" comment could be elaborat
+ // TODO(antonm): proper processing of alignments
+ // in actual_size and decommitting.
jar (doing other things) 2009/09/24 23:24:34 I don't understand this TODO comment. Can you cla
+ if (actual_size) {
+ *actual_size = size;
}
- void* result = VirtualAlloc(0, size + extra,
+ // We currently do not support alignments larger than the pagesize or
+ // alignments that are not multiples of the pagesize after being floored.
+ // If this ability is needed it can be done by the caller (assuming it knows
+ // the page size).
+ assert(alignment <= pagesize);
+
+ void* result = VirtualAlloc(0, size,
MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
if (result == NULL)
return NULL;
- // Adjust the return memory so it is aligned
- uintptr_t ptr = reinterpret_cast<uintptr_t>(result);
- size_t adjust = 0;
- if ((ptr & (alignment - 1)) != 0) {
- adjust = alignment - (ptr & (alignment - 1));
- }
+ // If the result is not aligned memory fragmentation will result which can
+ // lead to pathological memory use.
+ assert((reinterpret_cast<uintptr_t>(result) & (alignment - 1)) == 0);
- ptr += adjust;
- return reinterpret_cast<void*>(ptr);
+ return result;
}
void TCMalloc_SystemRelease(void* start, size_t length) {
« 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