MCPcopy Create free account
hub / github.com/F-Stack/f-stack / getAllocatorFragmentation

Function getAllocatorFragmentation

app/redis-6.2.6/src/defrag.c:920–933  ·  view source on GitHub ↗

Utility function to get the fragmentation ratio from jemalloc. * It is critical to do that by comparing only heap maps that belong to * jemalloc, and skip ones the jemalloc keeps as spare. Since we use this * fragmentation ratio in order to decide if a defrag action should be taken * or not, a false detection can cause the defragmenter to waste a lot of CPU * without the possibility of gettin

Source from the content-addressed store, hash-verified

918 * or not, a false detection can cause the defragmenter to waste a lot of CPU
919 * without the possibility of getting any results. */
920float getAllocatorFragmentation(size_t *out_frag_bytes) {
921 size_t resident, active, allocated;
922 zmalloc_get_allocator_info(&allocated, &active, &resident);
923 float frag_pct = ((float)active / allocated)*100 - 100;
924 size_t frag_bytes = active - allocated;
925 float rss_pct = ((float)resident / allocated)*100 - 100;
926 size_t rss_bytes = resident - allocated;
927 if(out_frag_bytes)
928 *out_frag_bytes = frag_bytes;
929 serverLog(LL_DEBUG,
930 "allocated=%zu, active=%zu, resident=%zu, frag=%.0f%% (%.0f%% rss), frag_bytes=%zu (%zu rss)",
931 allocated, active, resident, frag_pct, rss_pct, frag_bytes, rss_bytes);
932 return frag_pct;
933}
934
935/* We may need to defrag other globals, one small allocation can hold a full allocator run.
936 * so although small, it is still important to defrag these */

Callers 2

computeDefragCyclesFunction · 0.85
activeDefragCycleFunction · 0.85

Calls 1

Tested by

no test coverage detected