Release idle memory to the central cache
| 233 | |
| 234 | // Release idle memory to the central cache |
| 235 | void ThreadCache::Scavenge() { |
| 236 | // If the low-water mark for the free list is L, it means we would |
| 237 | // not have had to allocate anything from the central cache even if |
| 238 | // we had reduced the free list size by L. We aim to get closer to |
| 239 | // that situation by dropping L/2 nodes from the free list. This |
| 240 | // may not release much memory, but if so we will call scavenge again |
| 241 | // pretty soon and the low-water marks will be high on that call. |
| 242 | //int64 start = CycleClock::Now(); |
| 243 | for (unsigned int cl = 0; cl < kNumClasses; cl++) { |
| 244 | FreeList* list = &list_[cl]; |
| 245 | const int lowmark = list->lowwatermark(); |
| 246 | if (lowmark > 0) { |
| 247 | const int drop = (lowmark > 1) ? lowmark/2 : 1; |
| 248 | ReleaseToCentralCache(list, cl, drop); |
| 249 | |
| 250 | // Shrink the max length if it isn't used. Only shrink down to |
| 251 | // batch_size -- if the thread was active enough to get the max_length |
| 252 | // above batch_size, it will likely be that active again. If |
| 253 | // max_length shinks below batch_size, the thread will have to |
| 254 | // go through the slow-start behavior again. The slow-start is useful |
| 255 | // mainly for threads that stay relatively idle for their entire |
| 256 | // lifetime. |
| 257 | const int batch_size = Static::sizemap()->num_objects_to_move(cl); |
| 258 | if (static_cast<int>(list->max_length()) > batch_size) { |
| 259 | list->set_max_length( |
| 260 | max<int>(list->max_length() - batch_size, batch_size)); |
| 261 | } |
| 262 | } |
| 263 | list->clear_lowwatermark(); |
| 264 | } |
| 265 | |
| 266 | IncreaseCacheLimit(); |
| 267 | |
| 268 | // int64 finish = CycleClock::Now(); |
| 269 | // CycleTimer ct; |
| 270 | // MESSAGE("GC: %.0f ns\n", ct.CyclesToUsec(finish-start)*1000.0); |
| 271 | } |
| 272 | |
| 273 | void ThreadCache::IncreaseCacheLimit() { |
| 274 | SpinLockHolder h(Static::pageheap_lock()); |
nothing calls this directly
no test coverage detected