OLD | NEW |
1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 committed_[page_num >> 3] |= (1 << (page_num & 0x7)); | 159 committed_[page_num >> 3] |= (1 << (page_num & 0x7)); |
160 } | 160 } |
161 | 161 |
162 public: | 162 public: |
163 typedef uintptr_t Number; | 163 typedef uintptr_t Number; |
164 | 164 |
165 explicit TCMalloc_PageMap1_LazyCommit(void* (*allocator)(size_t)) { | 165 explicit TCMalloc_PageMap1_LazyCommit(void* (*allocator)(size_t)) { |
166 // TODO(jar): We need a reservation function, but current API to this class | 166 // TODO(jar): We need a reservation function, but current API to this class |
167 // only provides an allocator. | 167 // only provides an allocator. |
168 // Get decommitted memory. We will commit as necessary. | 168 // Get decommitted memory. We will commit as necessary. |
| 169 size_t size = sizeof(*array_) << BITS; |
169 array_ = reinterpret_cast<void**>(VirtualAlloc( | 170 array_ = reinterpret_cast<void**>(VirtualAlloc( |
170 NULL, sizeof(*array_) << BITS, MEM_RESERVE, PAGE_READWRITE)); | 171 NULL, size, MEM_RESERVE, PAGE_READWRITE)); |
| 172 tcmalloc::update_metadata_system_bytes(size); |
| 173 tcmalloc::update_metadata_unmapped_bytes(size); |
171 | 174 |
172 // Make sure we divided LENGTH evenly. | 175 // Make sure we divided LENGTH evenly. |
173 ASSERT(sizeof(committed_) * 8 == (LENGTH * sizeof(*array_)) >> kPageShift); | 176 ASSERT(sizeof(committed_) * 8 == (LENGTH * sizeof(*array_)) >> kPageShift); |
174 // Indicate that none of the pages of array_ have been committed yet. | 177 // Indicate that none of the pages of array_ have been committed yet. |
175 memset(committed_, 0, sizeof(committed_)); | 178 memset(committed_, 0, sizeof(committed_)); |
176 } | 179 } |
177 | 180 |
178 // Ensure that the map contains initialized and committed entries in array_ to | 181 // Ensure that the map contains initialized and committed entries in array_ to |
179 // describe pages "x .. x+n-1". | 182 // describe pages "x .. x+n-1". |
180 // Returns true if successful, false if we could not ensure this. | 183 // Returns true if successful, false if we could not ensure this. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 #ifndef NDEBUG | 251 #ifndef NDEBUG |
249 // Validate we are committing new sections, and hence we're not clearing any | 252 // Validate we are committing new sections, and hence we're not clearing any |
250 // existing data. | 253 // existing data. |
251 MEMORY_BASIC_INFORMATION info = {0}; | 254 MEMORY_BASIC_INFORMATION info = {0}; |
252 size_t result = VirtualQuery(start, &info, sizeof(info)); | 255 size_t result = VirtualQuery(start, &info, sizeof(info)); |
253 ASSERT(result); | 256 ASSERT(result); |
254 ASSERT(0 == (info.State & MEM_COMMIT)); // It starts with uncommitted. | 257 ASSERT(0 == (info.State & MEM_COMMIT)); // It starts with uncommitted. |
255 ASSERT(info.RegionSize >= length); // Entire length is uncommitted. | 258 ASSERT(info.RegionSize >= length); // Entire length is uncommitted. |
256 #endif | 259 #endif |
257 | 260 |
258 // TODO(jar): We need a commit that automatically tallies metadata_bytes. | |
259 TCMalloc_SystemCommit(start, length); | 261 TCMalloc_SystemCommit(start, length); |
260 tcmalloc::increment_metadata_system_bytes(length); | 262 tcmalloc::update_metadata_unmapped_bytes(-length); |
261 | 263 |
262 #ifndef NDEBUG | 264 #ifndef NDEBUG |
263 result = VirtualQuery(start, &info, sizeof(info)); | 265 result = VirtualQuery(start, &info, sizeof(info)); |
264 ASSERT(result); | 266 ASSERT(result); |
265 ASSERT(0 != (info.State & MEM_COMMIT)); // Now it is committed. | 267 ASSERT(0 != (info.State & MEM_COMMIT)); // Now it is committed. |
266 ASSERT(info.RegionSize >= length); // Entire length is committed. | 268 ASSERT(info.RegionSize >= length); // Entire length is committed. |
267 #endif | 269 #endif |
268 | 270 |
269 // As noted in the large comment/example describing this method, we will | 271 // As noted in the large comment/example describing this method, we will |
270 // never be called with a range of pages very much inside this |first_page| | 272 // never be called with a range of pages very much inside this |first_page| |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 } | 517 } |
516 // Advance to next interior entry | 518 // Advance to next interior entry |
517 k = ((k >> LEAF_BITS) + 1) << LEAF_BITS; | 519 k = ((k >> LEAF_BITS) + 1) << LEAF_BITS; |
518 } | 520 } |
519 } | 521 } |
520 return NULL; | 522 return NULL; |
521 } | 523 } |
522 }; | 524 }; |
523 | 525 |
524 #endif // TCMALLOC_PAGEMAP_H_ | 526 #endif // TCMALLOC_PAGEMAP_H_ |
OLD | NEW |