Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added debug logging for default store object, added spurious event co… #81

Merged
merged 6 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# UMAP v1.0.0

[![Travis Build Status](https://travis-ci.com/LLNL/umap.svg?branch=develop)](https://travis-ci.com/LLNL/Umpire)
[![Travis Build Status](https://travis-ci.com/LLNL/umap.svg?branch=develop)](https://travis-ci.com/LLNL/umap)
[![Documentation Status](https://readthedocs.org/projects/llnl-umap/badge/?version=develop)](https://llnl-umap.readthedocs.io/en/develop/?badge=develop)

Umap is a library that provides an mmap()-like interface to a simple, user-
Expand Down
117 changes: 63 additions & 54 deletions src/umap/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ void Buffer::mark_page_as_present(PageDescriptor* pd)
lock();

pd->set_state_present();
wakeup_page_state_waiters(pd);

if ( m_waits_for_state_change )
pthread_cond_broadcast( &m_state_change_cond );

unlock();
}
Expand All @@ -41,6 +43,7 @@ void Buffer::mark_page_as_free( PageDescriptor* pd )
m_present_pages.erase(pd->page);

pd->set_state_free();
pd->spurious_count = 0;

//
// We only put the page descriptor back onto the free list if it isn't
Expand All @@ -51,7 +54,8 @@ void Buffer::mark_page_as_free( PageDescriptor* pd )
if ( ! pd->deferred )
release_page_descriptor(pd);

wakeup_page_state_waiters(pd);
if ( m_waits_for_state_change )
pthread_cond_broadcast( &m_state_change_cond );

pd->page = nullptr;

Expand All @@ -63,7 +67,7 @@ void Buffer::release_page_descriptor( PageDescriptor* pd )
m_free_pages.push_back(pd);

if ( m_waits_for_avail_pd )
pthread_cond_signal(&m_avail_pd_cond);
pthread_cond_broadcast(&m_avail_pd_cond);
}

//
Expand Down Expand Up @@ -123,18 +127,21 @@ PageDescriptor* Buffer::evict_oldest_page()
//
void Buffer::evict_region(RegionDescriptor* rd)
{
lock();

while ( rd->count() ) {
auto pd = rd->get_next_page_descriptor();
pd->deferred = true;
wait_for_page_state(pd, PageDescriptor::State::PRESENT);
pd->set_state_leaving();
m_rm->get_evict_manager()->schedule_eviction(pd);
wait_for_page_state(pd, PageDescriptor::State::FREE);
if (m_rm->get_num_active_regions() > 1) {
lock();
while ( rd->count() ) {
auto pd = rd->get_next_page_descriptor();
pd->deferred = true;
wait_for_page_state(pd, PageDescriptor::State::PRESENT);
pd->set_state_leaving();
m_rm->get_evict_manager()->schedule_eviction(pd);
wait_for_page_state(pd, PageDescriptor::State::FREE);
}
unlock();
}
else {
m_rm->get_evict_manager()->EvictAll();
}

unlock();
}

bool Buffer::low_threshold_reached( void )
Expand All @@ -158,6 +165,14 @@ void Buffer::process_page_event(char* paddr, bool iswrite, RegionDescriptor* rd)
UMAP_LOG(Debug, "PRE: " << pd << " From: " << this);
}
else {
static int hiwat = 0;

pd->spurious_count++;
if (pd->spurious_count > hiwat) {
hiwat = pd->spurious_count;
UMAP_LOG(Info, "New Spurious cound high water mark: " << hiwat);
}

UMAP_LOG(Debug, "SPU: " << pd << " From: " << this);
unlock();
return;
Expand Down Expand Up @@ -199,22 +214,28 @@ PageDescriptor* Buffer::page_already_present( char* page_addr )
while (1) {
auto pp = m_present_pages.find(page_addr);

//
// Most likely case
//
if ( pp == m_present_pages.end() )
return nullptr;

//
// Next most likely is that it is just present in the buffer
//
if ( pp->second->state == PageDescriptor::State::PRESENT )
return pp->second;

// There is a chance that the state of this page is not/no-longer
// PRESENT. If this is the case, we need to wait for it to finish
// with whatever is happening to it and then check again
//
if ( pp != m_present_pages.end() ) {
if ( pp->second->state != PageDescriptor::State::PRESENT ) {
UMAP_LOG(Debug, "Waiting for state: (ANY)" << ", " << pp->second);
await_state_change_notification( pp->second );
}
else {
return pp->second;
}
}
else {
return nullptr;
}
UMAP_LOG(Debug, "Waiting for state: (ANY)" << ", " << pp->second);

++m_stats.waits;
++m_waits_for_state_change;
pthread_cond_wait(&m_state_change_cond, &m_mutex);
--m_waits_for_state_change;
}
}

Expand All @@ -223,7 +244,11 @@ PageDescriptor* Buffer::get_page_descriptor(char* vaddr, RegionDescriptor* rd)
while ( m_free_pages.size() == 0 ) {
++m_waits_for_avail_pd;
m_stats.not_avail++;

++m_stats.waits;
++m_waits_for_state_change;
pthread_cond_wait(&m_avail_pd_cond, &m_mutex);

--m_waits_for_avail_pd;
}

Expand All @@ -237,10 +262,10 @@ PageDescriptor* Buffer::get_page_descriptor(char* vaddr, RegionDescriptor* rd)
rval->dirty = false;
rval->deferred = false;
rval->set_state_filling();
rval->spurious_count = 0;

m_stats.pages_inserted++;
auto it = m_busy_pages.begin();
m_busy_pages.insert(it, rval);
m_busy_pages.push_front(rval);

return rval;
}
Expand Down Expand Up @@ -283,31 +308,18 @@ void Buffer::unlock()

void Buffer::wait_for_page_state( PageDescriptor* pd, PageDescriptor::State st)
{
UMAP_LOG(Debug, "Waiting for state: " << st << ", " << pd);

while ( pd->state != st ) {
UMAP_LOG(Debug, "Waiting for state: " << st << ", " << pd);
await_state_change_notification(pd);
}
}
++m_stats.waits;
++m_waits_for_state_change;

void Buffer::wakeup_page_state_waiters( PageDescriptor* pd )
{
auto pp = m_pages_awaiting_state_change.find(pd->page);
if ( pp != m_pages_awaiting_state_change.end() )
pthread_cond_broadcast(&m_state_change_cond);
}
++m_stats.waits;
++m_waits_for_state_change;
pthread_cond_wait(&m_state_change_cond, &m_mutex);

void Buffer::await_state_change_notification( PageDescriptor* pd )
{
m_stats.waits++;
++m_waits_for_state_change;
UMAP_LOG(Debug, "m_waits_for_state_change: "
<< m_waits_for_state_change
<< ", " << pd);
m_pages_awaiting_state_change[pd->page] = m_waits_for_state_change;
pthread_cond_wait(&m_state_change_cond, &m_mutex);
--m_waits_for_state_change;
if (m_waits_for_state_change == 0)
m_pages_awaiting_state_change.erase(pd->page);
--m_waits_for_state_change;
}
}

Buffer::Buffer( void )
Expand All @@ -333,7 +345,7 @@ Buffer::Buffer( void )
}

Buffer::~Buffer( void ) {
std::cout << m_stats << std::endl;
UMAP_LOG(Debug, m_stats);

assert("Pages are still present" && m_present_pages.size() == 0);
pthread_cond_destroy(&m_avail_pd_cond);
Expand All @@ -347,12 +359,9 @@ std::ostream& operator<<(std::ostream& os, const Umap::Buffer* b)
if ( b != nullptr ) {
os << "{ m_size: " << b->m_size
<< ", m_waits_for_avail_pd: " << b->m_waits_for_avail_pd
<< ", m_array: " << (void*)(b->m_array)
<< ", m_present_pages.size(): " << std::setw(2) << b->m_present_pages.size()
<< ", m_free_pages.size(): " << std::setw(2) << b->m_free_pages.size()
<< ", m_busy_pages.size(): " << std::setw(2) << b->m_busy_pages.size()
<< ", m_evict_low_water: " << std::setw(2) << b->m_evict_low_water
<< ", m_evict_high_water: " << std::setw(2) << b->m_evict_high_water
<< " }"
;
}
Expand Down
6 changes: 2 additions & 4 deletions src/umap/Buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <pthread.h>
#include <unordered_map>
#include <vector>
#include <deque>

#include "umap/RegionDescriptor.hpp"
#include "umap/PageDescriptor.hpp"
Expand Down Expand Up @@ -54,7 +55,7 @@ namespace Umap {
std::unordered_map<char*, PageDescriptor*> m_present_pages;

std::vector<PageDescriptor*> m_free_pages;
std::vector<PageDescriptor*> m_busy_pages;
std::deque<PageDescriptor*> m_busy_pages;

uint64_t m_evict_low_water; // % to evict too
uint64_t m_evict_high_water; // % to start evicting
Expand All @@ -66,7 +67,6 @@ namespace Umap {

int m_waits_for_state_change;
pthread_cond_t m_state_change_cond;
std::unordered_map<char*, int> m_pages_awaiting_state_change;

BufferStats m_stats;

Expand All @@ -79,8 +79,6 @@ namespace Umap {
void lock();
void unlock();
void wait_for_page_state( PageDescriptor* pd, PageDescriptor::State st);
void wakeup_page_state_waiters( PageDescriptor* pd );
void await_state_change_notification( PageDescriptor* pd );
};

std::ostream& operator<<(std::ostream& os, const Umap::BufferStats& stats);
Expand Down
4 changes: 4 additions & 0 deletions src/umap/EvictManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ void EvictManager::EvictMgr( void ) {
void EvictManager::EvictAll( void )
{
UMAP_LOG(Debug, "Entered");

for (auto pd = m_buffer->evict_oldest_page(); pd != nullptr; pd = m_buffer->evict_oldest_page()) {
UMAP_LOG(Debug, "evicting: " << pd);
schedule_eviction(pd);
}

m_evict_workers->wait_for_idle();

UMAP_LOG(Debug, "Done");
}

Expand Down
2 changes: 1 addition & 1 deletion src/umap/EvictManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ namespace Umap {
EvictManager( void );
~EvictManager( void );
void schedule_eviction(PageDescriptor* pd);
void EvictAll( void );

private:
Buffer* m_buffer;
EvictWorkers* m_evict_workers;

void EvictMgr(void);
void EvictAll( void );
void ThreadEntry( void );
};
} // end of namespace Umap
Expand Down
16 changes: 11 additions & 5 deletions src/umap/PageDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@ namespace Umap {
{
if (pd != nullptr) {
os << "{ "
<< " page: " << (void*)(pd->page)
<< ", state: " << pd->print_state()
<< ", dirty: " << (pd->dirty ? "TRUE" : "FALSE")
<< ", deferred: " << (pd->deferred ? "TRUE" : "FALSE")
<< " }";
<< (void*)(pd->page)
<< ", " << pd->print_state();

if ( pd->dirty )
os << ", DIRTY";
if ( pd->deferred )
os << ", DEFERRED";
if ( pd->spurious_count )
os << ", spurious: " << pd->spurious_count;

os << " }";
}
else {
os << "{ nullptr }";
Expand Down
1 change: 1 addition & 0 deletions src/umap/PageDescriptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Umap {
bool dirty;
bool deferred;
bool data_present;
int spurious_count;

std::string print_state( void ) const;
void set_state_free( void );
Expand Down
2 changes: 1 addition & 1 deletion src/umap/RegionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ uint64_t RegionManager::get_max_pages_in_memory( void )
{
static uint64_t total_mem_kb = 0;
const uint64_t oneK = 1024;
const uint64_t percent = 98; // 98% of available memory
const uint64_t percent = 90; // 90% of available memory

// Lazily set total_mem_kb global
if ( ! total_mem_kb ) {
Expand Down
1 change: 1 addition & 0 deletions src/umap/RegionManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class RegionManager {
FillWorkers* get_fill_workers_h() { return m_fill_workers; }
EvictManager* get_evict_manager() { return m_evict_manager; }
RegionDescriptor* containing_region( char* vaddr );
uint64_t get_num_active_regions( void ) { return (uint64_t)m_active_regions.size(); }

private:
Version m_version;
Expand Down
Loading