Panda3D
|
Least Recently Used algorithm implementation: In the Lru, each "memory page" has an associated class LruPage. More...
#include "lru.h"
Classes | |
struct | _LruVariables |
Public Types | |
typedef struct Lru::_LruVariables | LruVariables |
Public Member Functions | |
Lru (int maximum_memory, int maximum_pages, int maximum_page_types) | |
void | access_page (LruPage *lru_page) |
This must always be called before accessing or using a page's memory since it pages in the page if it is currently paged out. | |
void | add_cached_page (LruPagePriority priority, LruPage *lru_page) |
Adds a page that is already paged in to the LRU based on the given priority. | |
void | add_page (LruPagePriority priority, LruPage *lru_page) |
Adds a page to the LRU based on the given priority. | |
LruPage * | allocate_page (int size) |
void | begin_frame () |
This must be called before each frame. | |
void | calculate_lru_statistics (void) |
Debug function. | |
void | count_priority_level_pages (void) |
Debug function. | |
void | free_page (LruPage *lru_page) |
void | lock_page (LruPage *lru_page) |
bool | page_out_lru (int memory_required) |
Pages out the lowest priority pages until the memory_required is satisfied. | |
void | partial_lru_update (int maximum_updates) |
This only updates a number of pages up to the specified maximum_updates. | |
bool | register_lru_page_type (int index, LruPageTypeFunction page_in_function, LruPageTypeFunction page_out_function) |
Registers a specific type of page and its required page in and out functions. | |
void | remove_page (LruPage *lru_page) |
Removes a page from the LRU. | |
void | set_maximum_frame_bandwidth_utilization (PN_stdfloat maximum_frame_bandwidth_utilization) |
void | unlock_all_pages (void) |
void | unlock_page (LruPage *lru_page) |
void | update_entire_lru () |
This updates all the pages in the Lru. | |
void | update_start_update_lru_page (LruPage *lru_page) |
Public Attributes | |
LruVariables | _m |
Friends | |
class | LruPage |
Least Recently Used algorithm implementation: In the Lru, each "memory page" has an associated class LruPage.
The Lru has a range of priorities from LPP_Highest to LPP_PagedOut. Each priority has a doubly linked list of LruPages. The algorithim uses an adaptive method based on the average utilization of each page per frame (or time slice). The average utilization is calculated with an exponetial moving average. This is superior to a standard average since a standard average becomes less and less adaptive the longer a page exists. The average utilization is used to set the priority of each page. A higher average utilization automatically raises the priority of a page and a lower average utilization automatically lowers the priority of a page. Therefore, pages with a higher average utilization have a higher chance of being kept in memory or cached and pages with a lower average utilization have a higher chance of being paged out. When a page is paged in and there is not enough memory available, then the lowest priority pages will be paged out first until there is enough memory available.
void Lru::access_page | ( | LruPage * | lru_page | ) |
This must always be called before accessing or using a page's memory since it pages in the page if it is currently paged out.
Definition at line 455 of file lru.cxx.
References add_page(), page_out_lru(), and remove_page().
void Lru::add_cached_page | ( | LruPagePriority | priority, |
LruPage * | lru_page | ||
) |
Adds a page that is already paged in to the LRU based on the given priority.
Definition at line 359 of file lru.cxx.
References add_page(), and page_out_lru().
void Lru::add_page | ( | LruPagePriority | priority, |
LruPage * | lru_page | ||
) |
Adds a page to the LRU based on the given priority.
Definition at line 332 of file lru.cxx.
Referenced by access_page(), add_cached_page(), and page_out_lru().
void Lru::begin_frame | ( | ) |
void Lru::calculate_lru_statistics | ( | void | ) |
void Lru::count_priority_level_pages | ( | void | ) |
bool Lru::page_out_lru | ( | int | memory_required | ) |
Pages out the lowest priority pages until the memory_required is satisfied.
This will unlock all pages if needed.
Definition at line 883 of file lru.cxx.
References add_page(), and remove_page().
Referenced by access_page(), and add_cached_page().
void Lru::partial_lru_update | ( | int | maximum_updates | ) |
bool Lru::register_lru_page_type | ( | int | index, |
LruPageTypeFunction | page_in_function, | ||
LruPageTypeFunction | page_out_function | ||
) |
void Lru::remove_page | ( | LruPage * | lru_page | ) |
Removes a page from the LRU.
Definition at line 386 of file lru.cxx.
Referenced by access_page(), and page_out_lru().
void Lru::update_entire_lru | ( | ) |
This updates all the pages in the Lru.
Lru::partial_lru_update should be called instead due to performance reasons.