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

Function getAllocatorFragmentation

src/defrag.cpp:938–951  ·  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

936 * or not, a false detection can cause the defragmenter to waste a lot of CPU
937 * without the possibility of getting any results. */
938float getAllocatorFragmentation(size_t *out_frag_bytes) {
939 size_t resident, active, allocated;
940 zmalloc_get_allocator_info(&allocated, &active, &resident);
941 float frag_pct = ((float)active / allocated)*100 - 100;
942 size_t frag_bytes = active - allocated;
943 float rss_pct = ((float)resident / allocated)*100 - 100;
944 size_t rss_bytes = resident - allocated;
945 if(out_frag_bytes)
946 *out_frag_bytes = frag_bytes;
947 serverLog(LL_DEBUG,
948 "allocated=%zu, active=%zu, resident=%zu, frag=%.0f%% (%.0f%% rss), frag_bytes=%zu (%zu rss)",
949 allocated, active, resident, frag_pct, rss_pct, frag_bytes, rss_bytes);
950 return frag_pct;
951}
952
953/* We may need to defrag other globals, one small allocation can hold a full allocator run.
954 * so although small, it is still important to defrag these */

Callers 2

computeDefragCyclesFunction · 0.85
activeDefragCycleFunction · 0.85

Calls 2

serverLogFunction · 0.85

Tested by

no test coverage detected