MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / tcache_bin_flush_small

Function tcache_bin_flush_small

deps/jemalloc/src/tcache.c:133–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133void
134tcache_bin_flush_small(tsd_t *tsd, tcache_t *tcache, cache_bin_t *tbin,
135 szind_t binind, unsigned rem) {
136 bool merged_stats = false;
137
138 assert(binind < SC_NBINS);
139 assert((cache_bin_sz_t)rem <= tbin->ncached);
140
141 arena_t *arena = tcache->arena;
142 assert(arena != NULL);
143 unsigned nflush = tbin->ncached - rem;
144 VARIABLE_ARRAY(extent_t *, item_extent, nflush);
145
146 /* Look up extent once per item. */
147 if (config_opt_safety_checks) {
148 tbin_extents_lookup_size_check(tsd_tsdn(tsd), tbin, binind,
149 nflush, item_extent);
150 } else {
151 for (unsigned i = 0 ; i < nflush; i++) {
152 item_extent[i] = iealloc(tsd_tsdn(tsd),
153 *(tbin->avail - 1 - i));
154 }
155 }
156 while (nflush > 0) {
157 /* Lock the arena bin associated with the first object. */
158 extent_t *extent = item_extent[0];
159 unsigned bin_arena_ind = extent_arena_ind_get(extent);
160 arena_t *bin_arena = arena_get(tsd_tsdn(tsd), bin_arena_ind,
161 false);
162 unsigned binshard = extent_binshard_get(extent);
163 assert(binshard < bin_infos[binind].n_shards);
164 bin_t *bin = &bin_arena->bins[binind].bin_shards[binshard];
165
166 if (config_prof && bin_arena == arena) {
167 if (arena_prof_accum(tsd_tsdn(tsd), arena,
168 tcache->prof_accumbytes)) {
169 prof_idump(tsd_tsdn(tsd));
170 }
171 tcache->prof_accumbytes = 0;
172 }
173
174 malloc_mutex_lock(tsd_tsdn(tsd), &bin->lock);
175 if (config_stats && bin_arena == arena && !merged_stats) {
176 merged_stats = true;
177 bin->stats.nflushes++;
178 bin->stats.nrequests += tbin->tstats.nrequests;
179 tbin->tstats.nrequests = 0;
180 }
181 unsigned ndeferred = 0;
182 for (unsigned i = 0; i < nflush; i++) {
183 void *ptr = *(tbin->avail - 1 - i);
184 extent = item_extent[i];
185 assert(ptr != NULL && extent != NULL);
186
187 if (extent_arena_ind_get(extent) == bin_arena_ind
188 && extent_binshard_get(extent) == binshard) {
189 arena_dalloc_bin_junked_locked(tsd_tsdn(tsd),
190 bin_arena, bin, binind, extent, ptr);

Callers 3

tcache_event_hardFunction · 0.70
tcache_flush_cacheFunction · 0.70
tcache_dalloc_smallFunction · 0.50

Calls 13

extent_arena_ind_getFunction · 0.85
extent_binshard_getFunction · 0.85
arena_bin_choose_lockFunction · 0.85
prof_idumpFunction · 0.70
tsd_tsdnFunction · 0.50
ieallocFunction · 0.50
arena_getFunction · 0.50
arena_prof_accumFunction · 0.50
malloc_mutex_lockFunction · 0.50
malloc_mutex_unlockFunction · 0.50

Tested by

no test coverage detected