Changeset 83
- Timestamp:
- 06/29/05 03:23:09 (4 years ago)
- Files:
-
- src/state.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/state.c
r82 r83 27 27 #include "swaps.h" 28 28 29 /* The allocation/deallocation algorithm is driven by a state machine. 30 */ 29 31 30 32 // TODO: Adaptive cooldown_time? … … 80 82 timer_tick(); 81 83 82 if ( likely(the_state != st_diet) && unlikely(reqbytes > 0))84 if (unlikely(reqbytes > 0) && likely(the_state != st_diet)) 83 85 { 86 /* In any state except "diet," where allocation is inhibited, a shortage of 87 * memory means we forget what state we're in and jump straight to "hungry" 88 * mode, allocating a new swapfile along the way. If the allocation fails, 89 * we bail out into "diet" mode. 90 */ 84 91 if (likely(alloc_swapfile(reqbytes))) state_to(st_hungry); 85 92 else state_to(st_diet); … … 87 94 else if (unlikely(timer_timeout())) 88 95 { 96 /* All states except "steady" are designed to time out eventually; in every 97 * case that leads back to "steady" so we can make it a general rule that 98 * timeout leads to "steady." 99 * The only other action that accompanies timeout is when timing out of the 100 * "overfed" state, which is where we normally deallocate. 101 */ 89 102 if (the_state == st_overfed) free_swapfile(-reqbytes); 90 103 state_to(st_steady); … … 93 106 { 94 107 case st_diet: 108 /* If we overallocated and now find ourselves with more swap space than we 109 * think we need, deallocate it right away. Don't leave "diet" state just 110 * yet in that case, however, or we may invite thrashing. 111 */ 95 112 if (unlikely(reqbytes < 0)) free_swapfile(-reqbytes); 96 113 break; 97 114 case st_hungry: 115 /* The "hungry" state can either time out, or allocate more swap space and 116 * loop back to itself, resetting the timer (or if allocation fails, bail 117 * out to "diet"). In other words, all actions for this state have been 118 * handled by the general cases above. 119 */ 98 120 break; 99 121 case st_steady: 122 /* If we have more swap space than we need, go to "overfed" state which may 123 * eventually lead to deallocation. 124 */ 100 125 if (unlikely(reqbytes < 0)) state_to(st_overfed); 101 126 break; 102 127 case st_overfed: 128 /* There are two ways out of "overfed" state: either we find that we no 129 * longer have more memory than we need, in which case we default back to 130 * steady state; or we time out as per the general case described above, 131 * having had excess swap space for an entire timer period and therefore 132 * deallocating swap space. 133 */ 103 134 if (unlikely(reqbytes >= 0)) state_to(st_steady); 104 135 break;
