29 friend class AdaptiveLru;
34 friend class AdaptiveLru;
45class EXPCL_PANDA_GOBJ AdaptiveLru :
public Namable {
47 explicit AdaptiveLru(
const std::string &name,
size_t max_size);
56 INLINE
void evict_to(
size_t target_size);
61 void output(std::ostream &out)
const;
62 void write(std::ostream &out,
int indent_level)
const;
75 enum LruPagePriority {
80 LPP_Intermediate = 30,
82 LPP_TotalPriorities = 50,
85 INLINE PN_stdfloat calculate_exponential_moving_average(PN_stdfloat value, PN_stdfloat average)
const;
94 void do_evict_to(
size_t target_size,
bool hard_evict);
102 unsigned int _current_frame_identifier;
104 int _max_updates_per_frame;
121 friend class AdaptiveLruPage;
137 explicit AdaptiveLruPage(
size_t lru_size);
138 AdaptiveLruPage(
const AdaptiveLruPage ©);
139 void operator = (
const AdaptiveLruPage ©);
141 virtual ~AdaptiveLruPage();
143 INLINE AdaptiveLru *
get_lru()
const;
156 virtual void output(std::ostream &out)
const;
157 virtual void write(std::ostream &out,
int indent_level)
const;
169 unsigned int _first_frame_identifier;
170 unsigned int _current_frame_identifier;
171 unsigned int _update_frame_identifier;
173 int _current_frame_usage;
174 int _last_frame_usage;
175 int _update_total_usage;
177 PN_stdfloat _average_frame_utilization;
179 friend class AdaptiveLru;
182inline std::ostream &operator << (std::ostream &out,
const AdaptiveLru &lru) {
187inline std::ostream &operator << (std::ostream &out,
const AdaptiveLruPage &page) {
194void test_adaptive_lru();
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
One atomic piece that may be managed by a AdaptiveLru chain.
AdaptiveLru * get_lru() const
Returns the LRU that manages this page, or NULL if it is not currently managed by any LRU.
size_t get_lru_size() const
Returns the size of this page as reported to the LRU, presumably in bytes.
void set_lru_size(size_t lru_size)
Specifies the size of this page, presumably in bytes, although any unit is possible.
virtual void evict_lru()
Evicts the page from the LRU.
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...
unsigned int get_num_inactive_frames() const
Returns the number of frames since the page was last accessed on its LRU.
unsigned int get_num_frames() const
Returns the number of frames since the page was first added to its LRU.
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...
void dequeue_lru()
Removes the page from its AdaptiveLru.
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.
void set_max_size(size_t max_size)
Changes the max size of all objects that are allowed to be active on the LRU.
bool do_validate()
Checks that the LRU is internally consistent.
void do_add_page(AdaptiveLruPage *page)
Adds a new page the the LRU.
void set_max_updates_per_frame(int max_updates_per_frame)
Specifies the maximum number of pages the AdaptiveLru will update each frame.
int get_max_updates_per_frame() const
Returns the maximum number of pages the AdaptiveLru will update each frame.
void update_page(AdaptiveLruPage *page)
This updates the page's average utilization.
void begin_epoch()
Marks the end of the previous epoch and the beginning of the next one.
PN_stdfloat get_weight() const
Returns the weight value used to compute the exponential moving average.
void do_access_page(AdaptiveLruPage *page)
Marks a page accessed.
void do_evict_to(size_t target_size, bool hard_evict)
Evicts pages until the LRU is within the indicated size.
void do_partial_lru_update(int num_updates)
This only updates a number of pages up to the specified maximum_updates.
size_t get_total_size() const
Returns the total size of all objects currently active on the LRU.
void consider_evict()
Evicts a sequence of objects if the queue is full.
size_t count_active_size() const
Returns the total size of the pages that were enqueued since the last call to begin_epoch().
bool validate()
Checks that the LRU is internally self-consistent.
void evict_to(size_t target_size)
Evicts a sequence of objects until the queue fits within the indicated target size,...
size_t get_max_size() const
Returns the max size of all objects that are allowed to be active on the LRU.
void do_remove_page(AdaptiveLruPage *page)
Removes a page from the LRU.
This is a standard, non-reentrant mutex, similar to the Mutex class.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.