43 if (_total_size > _max_size) {
54 if (_total_size > _max_size) {
66 if (_total_size > target_size) {
104 _max_updates_per_frame = max_updates_per_frame;
112 return _max_updates_per_frame;
118 INLINE PN_stdfloat AdaptiveLru::
119 calculate_exponential_moving_average(PN_stdfloat value, PN_stdfloat average)
const {
120 return ((value - average) * _weight) + average;
149 if (_lru !=
nullptr) {
177 if (_lru !=
nullptr) {
179 _lru->_total_size -= _lru_size;
180 _lru->_total_size += lru_size;
181 _lru_size = lru_size;
183 _lru_size = lru_size;
size_t get_total_size() const
Returns the total size of all objects currently active on the LRU.
void set_max_size(size_t max_size)
Changes the max size of all objects that are allowed to be active on the LRU.
PN_stdfloat get_weight() const
Returns the weight value used to compute the exponential moving average.
void set_lru_size(size_t lru_size)
Specifies the size of this page, presumably in bytes, although any unit is possible.
size_t get_lru_size() const
Returns the size of this page as reported to the LRU, presumably in bytes.
bool do_validate()
Checks that the LRU is internally consistent.
void mark_used_lru() const
To be called when the page is used; this will move it to the tail of the AdaptiveLru queue it is alre...
void dequeue_lru()
Removes the page from its AdaptiveLru.
void enqueue_lru(AdaptiveLru *lru)
Adds the page to the LRU for the first time, or marks it recently-accessed if it has already been add...
bool validate()
Checks that the LRU is internally self-consistent.
size_t get_max_size() const
Returns the max size of all objects that are allowed to be active on the LRU.
Similar to MutexHolder, but for a light mutex.
void set_max_updates_per_frame(int max_updates_per_frame)
Specifies the maximum number of pages the AdaptiveLru will update each frame.
One atomic piece that may be managed by a AdaptiveLru chain.
A basic LRU-type algorithm, except that it is adaptive and attempts to avoid evicting pages that have...
void set_weight(PN_stdfloat weight)
Specifies the weight value used to compute the exponential moving average.
int get_max_updates_per_frame() const
Returns the maximum number of pages the AdaptiveLru will update each frame.
void consider_evict()
Evicts a sequence of objects if the queue is full.
void evict_to(size_t target_size)
Evicts a sequence of objects until the queue fits within the indicated target size,...
void do_evict_to(size_t target_size, bool hard_evict)
Evicts pages until the LRU is within the indicated size.
AdaptiveLru * get_lru() const
Returns the LRU that manages this page, or NULL if it is not currently managed by any LRU.