decide if defrag is needed, and at what CPU effort to invest in it */
| 1063 | |
| 1064 | /* decide if defrag is needed, and at what CPU effort to invest in it */ |
| 1065 | void computeDefragCycles() { |
| 1066 | size_t frag_bytes; |
| 1067 | float frag_pct = getAllocatorFragmentation(&frag_bytes); |
| 1068 | /* If we're not already running, and below the threshold, exit. */ |
| 1069 | if (!g_pserver->active_defrag_running) { |
| 1070 | if(frag_pct < cserver.active_defrag_threshold_lower || frag_bytes < cserver.active_defrag_ignore_bytes) |
| 1071 | return; |
| 1072 | } |
| 1073 | |
| 1074 | /* Calculate the adaptive aggressiveness of the defrag */ |
| 1075 | int cpu_pct = INTERPOLATE(frag_pct, |
| 1076 | cserver.active_defrag_threshold_lower, |
| 1077 | cserver.active_defrag_threshold_upper, |
| 1078 | cserver.active_defrag_cycle_min, |
| 1079 | cserver.active_defrag_cycle_max); |
| 1080 | cpu_pct = LIMIT(cpu_pct, |
| 1081 | cserver.active_defrag_cycle_min, |
| 1082 | cserver.active_defrag_cycle_max); |
| 1083 | /* We allow increasing the aggressiveness during a scan, but don't |
| 1084 | * reduce it. */ |
| 1085 | if (!g_pserver->active_defrag_running || |
| 1086 | cpu_pct > g_pserver->active_defrag_running) |
| 1087 | { |
| 1088 | g_pserver->active_defrag_running = cpu_pct; |
| 1089 | serverLog(LL_VERBOSE, |
| 1090 | "Starting active defrag, frag=%.0f%%, frag_bytes=%zu, cpu=%d%%", |
| 1091 | frag_pct, frag_bytes, cpu_pct); |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | /* Perform incremental defragmentation work from the serverCron. |
| 1096 | * This works in a similar way to activeExpireCycle, in the sense that |
no test coverage detected