Skip to content

Commit

Permalink
Don't count pagefaults if the previous page is in LRU list
Browse files Browse the repository at this point in the history
  • Loading branch information
valyala committed Feb 21, 2012
1 parent 1ba4e9b commit 04cc87b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ops_count_test.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
using namespace std; using namespace std;


// Simulates a LRU list of pages, which can contain up to _max_lru_size entries. // Simulates a LRU list of pages, which can contain up to _max_lru_size entries.
// Each page has size PAGE_MASK + 1. // Each page's size is PAGE_MASK + 1 bytes.
struct lru struct lru
{ {
typedef list<uintptr_t> lru_t; typedef list<uintptr_t> lru_t;


static const uintptr_t PAGE_MASK = (((uintptr_t)1) << 12) - 1; static const uintptr_t PAGE_MASK = (((uintptr_t)1) << 12) - 1;


// Maximum number of pages in LRU list. // Maximum number of pages in LRU list.
static const size_t MAX_LRU_SIZE = 16; static const size_t MAX_LRU_SIZE = 20;


// LRU list of pages. Front of the list contains least recently used pages. // LRU list of pages. Front of the list contains least recently used pages.
static lru_t lru_pages; static lru_t lru_pages;
Expand All @@ -49,11 +49,18 @@ struct lru
{ {
assert(lru_pages.size() <= MAX_LRU_SIZE); assert(lru_pages.size() <= MAX_LRU_SIZE);


uintptr_t page_num = ((uintptr_t)ptr) & ~PAGE_MASK; const uintptr_t page_num = ((uintptr_t)ptr) & ~PAGE_MASK;
lru_t::iterator it = find(lru_pages.begin(), lru_pages.end(), lru_t::iterator it = find(lru_pages.begin(), lru_pages.end(),
page_num); page_num);
if (it == lru_pages.end()) { if (it == lru_pages.end()) {
++pagefaults; const uintptr_t prev_page_num = page_num - PAGE_MASK - 1;
if (count(lru_pages.begin(), lru_pages.end(), prev_page_num) == 0) {
// Count pagefault only if the previous page is not in the LRU list.
// If the previous page is in the LRU list, then assume that the current
// page is already pre-fetched, so no hard pagefault.
++pagefaults;
}

lru_pages.push_front(page_num); lru_pages.push_front(page_num);
if (lru_pages.size() > MAX_LRU_SIZE) { if (lru_pages.size() > MAX_LRU_SIZE) {
lru_pages.pop_back(); lru_pages.pop_back();
Expand Down

0 comments on commit 04cc87b

Please sign in to comment.