This is a rewrite based on work done by Max Laier and myself at isilon which was itself based on another PID controller I used in the I/O stack. I'm not sure what to do about the copyright. There was no copyright on the original work because it was embedded in the vm_pageout.c file. The algorithm clearly has no protected IP as it has been in literature for generations and was originally inspired by steering ships.
This patch smooths out the page daemon work and avoids frequent sleep/wakeup cycles by effectively estimating demand and changes in demand to adjust the number of pages processed. There is an enormous amount of literature available on PID controllers. I have optimized this one for use in daemon regulation by preventing negative values, negative integral windup, and by using simple math in discrete time steps. The default gains were tuned based on a wide variety of page consumption rates. I might like a slightly faster ramp-up but that comes at the cost of stability.
I would appreciate feedback on the discussion in comments. Is this sufficient for someone else to apply this pid controller to another daemon? Many of our threshold based regulation systems (high/low water & wake point) produce really undesirable results. Sawtooth output, long delays when consumers run out of a resource and pause waiting on the daemon during periods of high demand. Excessive reclamation of resources during periods of low demand. etc. My goal with this pid controller would be to see it applied to eliminate these stalls and improve liveliness and regulation of the system at large. Some other candidates are laundry, buf daemon, bufspace daemon, vnlru, etc.
Isilon was able to use tighter targets with lower thresholds leaving fewer pages free under normal conditions. I have not made that change here but I think it's worthwhile. On my system the standard target is 1.5GB free.
On my parallel dd test I have seen improvements by as much as 50% owing to less frequent blocking.