decide if defrag is needed, and at what CPU effort to invest in it */
| 1044 | |
| 1045 | /* decide if defrag is needed, and at what CPU effort to invest in it */ |
| 1046 | void computeDefragCycles() { |
| 1047 | size_t frag_bytes; |
| 1048 | float frag_pct = getAllocatorFragmentation(&frag_bytes); |
| 1049 | /* If we're not already running, and below the threshold, exit. */ |
| 1050 | if (!server.active_defrag_running) { |
| 1051 | if(frag_pct < server.active_defrag_threshold_lower || frag_bytes < server.active_defrag_ignore_bytes) |
| 1052 | return; |
| 1053 | } |
| 1054 | |
| 1055 | /* Calculate the adaptive aggressiveness of the defrag */ |
| 1056 | int cpu_pct = INTERPOLATE(frag_pct, |
| 1057 | server.active_defrag_threshold_lower, |
| 1058 | server.active_defrag_threshold_upper, |
| 1059 | server.active_defrag_cycle_min, |
| 1060 | server.active_defrag_cycle_max); |
| 1061 | cpu_pct = LIMIT(cpu_pct, |
| 1062 | server.active_defrag_cycle_min, |
| 1063 | server.active_defrag_cycle_max); |
| 1064 | /* We allow increasing the aggressiveness during a scan, but don't |
| 1065 | * reduce it. */ |
| 1066 | if (!server.active_defrag_running || |
| 1067 | cpu_pct > server.active_defrag_running) |
| 1068 | { |
| 1069 | server.active_defrag_running = cpu_pct; |
| 1070 | serverLog(LL_VERBOSE, |
| 1071 | "Starting active defrag, frag=%.0f%%, frag_bytes=%zu, cpu=%d%%", |
| 1072 | frag_pct, frag_bytes, cpu_pct); |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | /* Perform incremental defragmentation work from the serverCron. |
| 1077 | * This works in a similar way to activeExpireCycle, in the sense that |
no test coverage detected