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

Side by Side Diff: base/allocator/partition_allocator/partition_alloc.cc

Issue 2799323003: Fix PartitionAlloc cookies for large in-place reallocs (Closed)
Patch Set: Fix issue Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/allocator/partition_allocator/partition_alloc_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/allocator/partition_allocator/partition_alloc.h" 5 #include "base/allocator/partition_allocator/partition_alloc.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/allocator/partition_allocator/oom.h" 9 #include "base/allocator/partition_allocator/oom.h"
10 #include "base/allocator/partition_allocator/spin_lock.h" 10 #include "base/allocator/partition_allocator/spin_lock.h"
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 } 1044 }
1045 1045
1046 size_t actual_new_size = PartitionAllocActualSize(root, new_size); 1046 size_t actual_new_size = PartitionAllocActualSize(root, new_size);
1047 size_t actual_old_size = PartitionAllocGetSize(ptr); 1047 size_t actual_old_size = PartitionAllocGetSize(ptr);
1048 1048
1049 // TODO: note that tcmalloc will "ignore" a downsizing realloc() unless the 1049 // TODO: note that tcmalloc will "ignore" a downsizing realloc() unless the
1050 // new size is a significant percentage smaller. We could do the same if we 1050 // new size is a significant percentage smaller. We could do the same if we
1051 // determine it is a win. 1051 // determine it is a win.
1052 if (actual_new_size == actual_old_size) { 1052 if (actual_new_size == actual_old_size) {
1053 // Trying to allocate a block of size new_size would give us a block of 1053 // Trying to allocate a block of size new_size would give us a block of
1054 // the same size as the one we've already got, so no point in doing 1054 // the same size as the one we've already got, so re-use the allocation
1055 // anything here. 1055 // after updating statistics (and cookies, if present).
1056 PartitionPageSetRawSize(page, PartitionCookieSizeAdjustAdd(new_size));
1057 #if DCHECK_IS_ON()
1058 // Write a new trailing cookie.
1059 PartitionCookieWriteValue(static_cast<char*>(ptr) + new_size);
1060 #endif
1056 return ptr; 1061 return ptr;
1057 } 1062 }
1058 1063
1059 // This realloc cannot be resized in-place. Sadness. 1064 // This realloc cannot be resized in-place. Sadness.
1060 void* ret = PartitionAllocGeneric(root, new_size, type_name); 1065 void* ret = PartitionAllocGeneric(root, new_size, type_name);
1061 size_t copy_size = actual_old_size; 1066 size_t copy_size = actual_old_size;
1062 if (new_size < copy_size) 1067 if (new_size < copy_size)
1063 copy_size = new_size; 1068 copy_size = new_size;
1064 1069
1065 memcpy(ret, ptr, copy_size); 1070 memcpy(ret, ptr, copy_size);
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 // can use PartitionAlloc to allocate and this can affect the statistics. 1437 // can use PartitionAlloc to allocate and this can affect the statistics.
1433 for (size_t i = 0; i < partitionNumBuckets; ++i) { 1438 for (size_t i = 0; i < partitionNumBuckets; ++i) {
1434 if (memory_stats[i].is_valid) 1439 if (memory_stats[i].is_valid)
1435 dumper->PartitionsDumpBucketStats(partition_name, &memory_stats[i]); 1440 dumper->PartitionsDumpBucketStats(partition_name, &memory_stats[i]);
1436 } 1441 }
1437 } 1442 }
1438 dumper->PartitionDumpTotals(partition_name, &stats); 1443 dumper->PartitionDumpTotals(partition_name, &stats);
1439 } 1444 }
1440 1445
1441 } // namespace base 1446 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/allocator/partition_allocator/partition_alloc_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698