PeriodicFlush() is much more convoluted than it needs to be: it has triple nesting, local variables counting refs and return values, and increments the mapFileUseCount iterator unnecessarily. Removing all of that makes the function much easier to understand.
Backport of core PR19085.
Depends on D8617.