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

Side by Side Diff: third_party/tcmalloc/chromium/src/common.cc

Issue 8570023: Add a guard page in front of metadata allocations. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | third_party/tcmalloc/chromium/src/page_heap_allocator.h » ('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) 2008, Google Inc. 1 // Copyright (c) 2008, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 16 matching lines...) Expand all
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 // --- 30 // ---
31 // Author: Sanjay Ghemawat <opensource@google.com> 31 // Author: Sanjay Ghemawat <opensource@google.com>
32 32
33 #include "config.h" 33 #include "config.h"
34 #include "common.h" 34 #include "common.h"
35 #include "system-alloc.h" 35 #include "system-alloc.h"
36 36
37 #if defined(HAVE_UNISTD_H) && defined(HAVE_GETPAGESIZE)
38 #include <unistd.h> // for getpagesize
39 #endif
40
37 namespace tcmalloc { 41 namespace tcmalloc {
38 42
39 // Note: the following only works for "n"s that fit in 32-bits, but 43 // Note: the following only works for "n"s that fit in 32-bits, but
40 // that is fine since we only use it for small sizes. 44 // that is fine since we only use it for small sizes.
41 static inline int LgFloor(size_t n) { 45 static inline int LgFloor(size_t n) {
42 int log = 0; 46 int log = 0;
43 for (int i = 4; i >= 0; --i) { 47 for (int i = 4; i >= 0; --i) {
44 int shift = (1 << i); 48 int shift = (1 << i);
45 size_t x = n >> shift; 49 size_t x = n >> shift;
46 if (x != 0) { 50 if (x != 0) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 int(class_to_size_[cl]), 198 int(class_to_size_[cl]),
195 int(class_to_pages_[cl] << kPageShift), 199 int(class_to_pages_[cl] << kPageShift),
196 max_waste * 100.0 / alloc_size 200 max_waste * 100.0 / alloc_size
197 ); 201 );
198 } 202 }
199 } 203 }
200 204
201 // Metadata allocator -- keeps stats about how many bytes allocated. 205 // Metadata allocator -- keeps stats about how many bytes allocated.
202 static uint64_t metadata_system_bytes_ = 0; 206 static uint64_t metadata_system_bytes_ = 0;
203 void* MetaDataAlloc(size_t bytes) { 207 void* MetaDataAlloc(size_t bytes) {
204 void* result = TCMalloc_SystemAlloc(bytes, NULL); 208 static size_t pagesize;
209 #ifdef HAVE_GETPAGESIZE
210 if (pagesize == 0)
211 pagesize = getpagesize();
212 #endif
213
214 void* result = TCMalloc_SystemAlloc(bytes, NULL, pagesize);
205 if (result != NULL) { 215 if (result != NULL) {
206 metadata_system_bytes_ += bytes; 216 metadata_system_bytes_ += bytes;
207 } 217 }
208 return result; 218 return result;
209 } 219 }
210 220
211 uint64_t metadata_system_bytes() { return metadata_system_bytes_; } 221 uint64_t metadata_system_bytes() { return metadata_system_bytes_; }
212 222
213 void increment_metadata_system_bytes(size_t bytes) { 223 void increment_metadata_system_bytes(size_t bytes) {
214 metadata_system_bytes_ += bytes; 224 metadata_system_bytes_ += bytes;
215 } 225 }
216 226
217 } // namespace tcmalloc 227 } // namespace tcmalloc
OLDNEW
« no previous file with comments | « no previous file | third_party/tcmalloc/chromium/src/page_heap_allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698