Return a struct redisMemOverhead filled with memory overhead * information used for the MEMORY OVERHEAD and INFO command. The returned * structure pointer should be freed calling freeMemoryOverheadData(). */
| 1063 | * information used for the MEMORY OVERHEAD and INFO command. The returned |
| 1064 | * structure pointer should be freed calling freeMemoryOverheadData(). */ |
| 1065 | struct redisMemOverhead *getMemoryOverheadData(void) { |
| 1066 | serverAssert(GlobalLocksAcquired()); |
| 1067 | int j; |
| 1068 | size_t mem_total = 0; |
| 1069 | size_t mem = 0; |
| 1070 | size_t zmalloc_used = zmalloc_used_memory(); |
| 1071 | struct redisMemOverhead *mh = (redisMemOverhead*)zcalloc(sizeof(*mh), MALLOC_LOCAL); |
| 1072 | |
| 1073 | mh->total_allocated = zmalloc_used; |
| 1074 | mh->startup_allocated = g_pserver->initial_memory_usage; |
| 1075 | mh->peak_allocated = g_pserver->stat_peak_memory; |
| 1076 | mh->total_frag = |
| 1077 | (float)g_pserver->cron_malloc_stats.process_rss / g_pserver->cron_malloc_stats.zmalloc_used; |
| 1078 | mh->total_frag_bytes = |
| 1079 | g_pserver->cron_malloc_stats.process_rss - g_pserver->cron_malloc_stats.zmalloc_used; |
| 1080 | mh->allocator_frag = |
| 1081 | (float)g_pserver->cron_malloc_stats.allocator_active / g_pserver->cron_malloc_stats.allocator_allocated; |
| 1082 | mh->allocator_frag_bytes = |
| 1083 | g_pserver->cron_malloc_stats.allocator_active - g_pserver->cron_malloc_stats.allocator_allocated; |
| 1084 | mh->allocator_rss = |
| 1085 | (float)g_pserver->cron_malloc_stats.allocator_resident / g_pserver->cron_malloc_stats.allocator_active; |
| 1086 | mh->allocator_rss_bytes = |
| 1087 | g_pserver->cron_malloc_stats.allocator_resident - g_pserver->cron_malloc_stats.allocator_active; |
| 1088 | mh->rss_extra = |
| 1089 | (float)g_pserver->cron_malloc_stats.process_rss / g_pserver->cron_malloc_stats.allocator_resident; |
| 1090 | mh->rss_extra_bytes = |
| 1091 | g_pserver->cron_malloc_stats.process_rss - g_pserver->cron_malloc_stats.allocator_resident; |
| 1092 | |
| 1093 | mem_total += g_pserver->initial_memory_usage; |
| 1094 | |
| 1095 | mem = 0; |
| 1096 | if (g_pserver->repl_backlog && g_pserver->repl_backlog != g_pserver->repl_backlog_disk) |
| 1097 | mem += zmalloc_size(g_pserver->repl_backlog); |
| 1098 | mh->repl_backlog = mem; |
| 1099 | mem_total += mem; |
| 1100 | |
| 1101 | /* Computing the memory used by the clients would be O(N) if done |
| 1102 | * here online. We use our values computed incrementally by |
| 1103 | * clientsCronTrackClientsMemUsage(). */ |
| 1104 | mh->clients_slaves = g_pserver->stat_clients_type_memory[CLIENT_TYPE_SLAVE]; |
| 1105 | mh->clients_normal = g_pserver->stat_clients_type_memory[CLIENT_TYPE_MASTER]+ |
| 1106 | g_pserver->stat_clients_type_memory[CLIENT_TYPE_PUBSUB]+ |
| 1107 | g_pserver->stat_clients_type_memory[CLIENT_TYPE_NORMAL]; |
| 1108 | mem_total += mh->clients_slaves; |
| 1109 | mem_total += mh->clients_normal; |
| 1110 | |
| 1111 | mem = 0; |
| 1112 | if (g_pserver->aof_state != AOF_OFF) { |
| 1113 | mem += sdsZmallocSize(g_pserver->aof_buf); |
| 1114 | mem += aofRewriteBufferSize(); |
| 1115 | } |
| 1116 | mh->aof_buffer = mem; |
| 1117 | mem_total+=mem; |
| 1118 | |
| 1119 | mem = g_pserver->lua_scripts_mem; |
| 1120 | mem += dictSize(g_pserver->lua_scripts) * sizeof(dictEntry) + |
| 1121 | dictSlots(g_pserver->lua_scripts) * sizeof(dictEntry*); |
| 1122 | mem += dictSize(g_pserver->repl_scriptcache_dict) * sizeof(dictEntry) + |
no test coverage detected