today's tutorial -- hysteresis
Posted: Tue Oct 07, 2003 7:45 am
Hi there
today comes a small tutorial (if i can call it that way) about hysteresis cycles. This technique is widely used in monitoring systems and networking, and i think it can have a lot of interresting applications in the field of OS programming.
What is hysteresis
Let's say you have an integer variable X (which may cover a large kind of values like CPU time, available memory space, disk fragmentation level, etc) and an action that you wish to execute to keep X under a given threshold Xmax.
One simple example (on which i'll focus) is that
Now, if you just let the swapper start when X>Xmax and stop it when X<Xmax, you'll find yourself in a situation where the swapper will be (almost) continuously running as soon as Xmax is reached and that the system needs more memory:
If we apply this to our swapping technique, it will get the following behaviour:
So, voil?. That's all for now about hysteresis
today comes a small tutorial (if i can call it that way) about hysteresis cycles. This technique is widely used in monitoring systems and networking, and i think it can have a lot of interresting applications in the field of OS programming.
What is hysteresis
Let's say you have an integer variable X (which may cover a large kind of values like CPU time, available memory space, disk fragmentation level, etc) and an action that you wish to execute to keep X under a given threshold Xmax.
One simple example (on which i'll focus) is that
where X will be the used page count, and Xmax is computed at system boot time to be (available_memory * 9)/10if the amount of available physical page frame is lower than 10% of the physical memory, wake up the swapper subsystem to free some memory
Now, if you just let the swapper start when X>Xmax and stop it when X<Xmax, you'll find yourself in a situation where the swapper will be (almost) continuously running as soon as Xmax is reached and that the system needs more memory:
- on X==Xmax, the swapper will find one page to be swapped out
- X will be decremented (as there's one more free page) and the swapper stops.
- X then the system requests one more physical page and the swapper is waken up again, freeing one single page, etc.
If we apply this to our swapping technique, it will get the following behaviour:
- As soon as the amount of free physical page gets too low (say, only 10Mb left, or something), the system enters "stressed mode" and starts swapping (the cooling process).
- the swap will go on as long as the amount of freed pages is unsufficient to say we returned to the "normal mode". (say, as long as there is less than 30Mb left). Only then do we consider that the system has recovered a 'stable' state and that the swapper can be turned off.
Code: Select all
virtual class HysteresisController extends PeriodicMonitor {
int start_level;
int stop_level;
virtual int probe(); // override this so that it returns X
thread cooler;
boolean cooling=false;
/* this function is called periodically by the Monitoring System
* (we assume this is a sideeffect of creating a new
* PeriodicMonitor object)
*/
void monitor() {
if (cooling && probe()<stop_level) {
cooler.stop();
cooling=false;
}
if (!cooling && probe()>start_level) {
cooling.start();
cooling=true;
}
}
}