This implements MEMORY DOCTOR. An human readable analysis of the Redis * memory condition. */
| 1174 | /* This implements MEMORY DOCTOR. An human readable analysis of the Redis |
| 1175 | * memory condition. */ |
| 1176 | sds getMemoryDoctorReport(void) { |
| 1177 | serverAssert(GlobalLocksAcquired()); |
| 1178 | int empty = 0; /* Instance is empty or almost empty. */ |
| 1179 | int big_peak = 0; /* Memory peak is much larger than used mem. */ |
| 1180 | int high_frag = 0; /* High fragmentation. */ |
| 1181 | int high_alloc_frag = 0;/* High allocator fragmentation. */ |
| 1182 | int high_proc_rss = 0; /* High process rss overhead. */ |
| 1183 | int high_alloc_rss = 0; /* High rss overhead. */ |
| 1184 | int big_slave_buf = 0; /* Slave buffers are too big. */ |
| 1185 | int big_client_buf = 0; /* Client buffers are too big. */ |
| 1186 | int many_scripts = 0; /* Script cache has too many scripts. */ |
| 1187 | int num_reports = 0; |
| 1188 | struct redisMemOverhead *mh = getMemoryOverheadData(); |
| 1189 | |
| 1190 | if (mh->total_allocated < (1024*1024*5)) { |
| 1191 | empty = 1; |
| 1192 | num_reports++; |
| 1193 | } else { |
| 1194 | /* Peak is > 150% of current used memory? */ |
| 1195 | if (((float)mh->peak_allocated / mh->total_allocated) > 1.5) { |
| 1196 | big_peak = 1; |
| 1197 | num_reports++; |
| 1198 | } |
| 1199 | |
| 1200 | /* Fragmentation is higher than 1.4 and 10MB ?*/ |
| 1201 | if (mh->total_frag > 1.4 && mh->total_frag_bytes > 10<<20) { |
| 1202 | high_frag = 1; |
| 1203 | num_reports++; |
| 1204 | } |
| 1205 | |
| 1206 | /* External fragmentation is higher than 1.1 and 10MB? */ |
| 1207 | if (mh->allocator_frag > 1.1 && mh->allocator_frag_bytes > 10<<20) { |
| 1208 | high_alloc_frag = 1; |
| 1209 | num_reports++; |
| 1210 | } |
| 1211 | |
| 1212 | /* Allocator rss is higher than 1.1 and 10MB ? */ |
| 1213 | if (mh->allocator_rss > 1.1 && mh->allocator_rss_bytes > 10<<20) { |
| 1214 | high_alloc_rss = 1; |
| 1215 | num_reports++; |
| 1216 | } |
| 1217 | |
| 1218 | /* Non-Allocator rss is higher than 1.1 and 10MB ? */ |
| 1219 | if (mh->rss_extra > 1.1 && mh->rss_extra_bytes > 10<<20) { |
| 1220 | high_proc_rss = 1; |
| 1221 | num_reports++; |
| 1222 | } |
| 1223 | |
| 1224 | /* Clients using more than 200k each average? */ |
| 1225 | long numslaves = listLength(g_pserver->slaves); |
| 1226 | long numclients = listLength(g_pserver->clients)-numslaves; |
| 1227 | if ((numclients > 0) && mh->clients_normal / numclients > (1024*200)) { |
| 1228 | big_client_buf = 1; |
| 1229 | num_reports++; |
| 1230 | } |
| 1231 | |
| 1232 | /* Slaves using more than 10 MB each? */ |
| 1233 | if (numslaves > 0 && mh->clients_slaves / numslaves > (1024*1024*10)) { |
no test coverage detected