MCPcopy Create free account
hub / github.com/beefytech/Beef / FetchFromCentralCache

Method FetchFromCentralCache

BeefTools/BeefMem/gperftools/src/thread_cache.cc:153–188  ·  view source on GitHub ↗

Remove some objects of class "cl" from central cache and add to thread heap. On success, return the first object for immediate use; otherwise return NULL.

Source from the content-addressed store, hash-verified

151// Remove some objects of class "cl" from central cache and add to thread heap.
152// On success, return the first object for immediate use; otherwise return NULL.
153void* ThreadCache::FetchFromCentralCache(size_t cl, size_t byte_size) {
154 FreeList* list = &list_[cl];
155 ASSERT(list->empty());
156 const int batch_size = Static::sizemap()->num_objects_to_move(cl);
157
158 const int num_to_move = min<int>(list->max_length(), batch_size);
159 void *start, *end;
160 int fetch_count = Static::central_cache()[cl].RemoveRange(
161 &start, &end, num_to_move);
162
163 ASSERT((start == NULL) == (fetch_count == 0));
164 if (--fetch_count >= 0) {
165 size_ += byte_size * fetch_count;
166 list->PushRange(fetch_count, SLL_Next(start), end);
167 }
168
169 // Increase max length slowly up to batch_size. After that,
170 // increase by batch_size in one shot so that the length is a
171 // multiple of batch_size.
172 if (list->max_length() < batch_size) {
173 list->set_max_length(list->max_length() + 1);
174 } else {
175 // Don't let the list get too long. In 32 bit builds, the length
176 // is represented by a 16 bit int, so we need to watch out for
177 // integer overflow.
178 int new_length = min<int>(list->max_length() + batch_size,
179 kMaxDynamicFreeListLength);
180 // The list's max_length must always be a multiple of batch_size,
181 // and kMaxDynamicFreeListLength is not necessarily a multiple
182 // of batch_size.
183 new_length -= new_length % batch_size;
184 ASSERT(new_length % batch_size == 0);
185 list->set_max_length(new_length);
186 }
187 return start;
188}
189
190void ThreadCache::ListTooLong(FreeList* list, size_t cl) {
191 const int batch_size = Static::sizemap()->num_objects_to_move(cl);

Callers

nothing calls this directly

Calls 7

SLL_NextFunction · 0.70
emptyMethod · 0.45
num_objects_to_moveMethod · 0.45
max_lengthMethod · 0.45
RemoveRangeMethod · 0.45
PushRangeMethod · 0.45
set_max_lengthMethod · 0.45

Tested by

no test coverage detected