Cleaned up page locking + a harmless memory bug. Add missing locks to page writeback.

This commit is contained in:
Sears Russell 2009-08-08 07:59:19 +00:00
parent 3760fd1fea
commit a0f9a7bc81
4 changed files with 13 additions and 5 deletions

View file

@ -80,7 +80,9 @@ int main(int argc, char ** argv) {
for(long i =0; i < page_count; i++) {
Page * p = loadPage(-1, i);
writelock(p->rwlatch,0);
stasis_dirty_page_table_set_dirty(stasis_runtime_dirty_page_table(), p);
unlock(p->rwlatch);
releasePage(p);
}

View file

@ -51,8 +51,8 @@ static void pageSetNode(void * page, node_t * n, void * ignore) {
static inline struct Page_s ** pagePendingPtr(Page * p) {
return ((struct Page_s **)(&((p)->next)));
}
static inline int* pagePinCountPtr(Page * p) {
return ((int*)(&((p)->queue)));
static inline intptr_t* pagePinCountPtr(Page * p) {
return ((intptr_t*)(&((p)->queue)));
}
#ifdef LONG_RUN
@ -92,7 +92,7 @@ inline static void checkPageState(Page * p) { }
inline static int tryToWriteBackPage(pageid_t page) {
Page * p = lhfind(cachedPages, &page, sizeof(page));
Page * p = LH_ENTRY(find)(cachedPages, &page, sizeof(page));
if(!p) { return ENOENT; }
@ -105,7 +105,7 @@ inline static int tryToWriteBackPage(pageid_t page) {
DEBUG("Write(%ld)\n", (long)victim->id);
page_handle->write(page_handle, p); /// XXX pageCleanup and pageFlushed might be heavyweight.
assert(!p->dirty);
assert(!stasis_dirty_page_table_is_dirty(stasis_runtime_dirty_page_table(), p));
return 0;
}
@ -379,7 +379,10 @@ static void bhReleasePage(Page * p) {
pthread_mutex_unlock(&mut);
}
static int bhWriteBackPage(pageid_t pageid) {
return tryToWriteBackPage(pageid);
pthread_mutex_lock(&mut);
int ret = tryToWriteBackPage(pageid);
pthread_mutex_unlock(&mut);
return ret;
}
static void bhForcePages() {
page_handle->force_file(page_handle);

View file

@ -32,6 +32,7 @@ struct stasis_dirty_page_table_t {
void stasis_dirty_page_table_set_dirty(stasis_dirty_page_table_t * dirtyPages, Page * p) {
pthread_mutex_lock(&dirtyPages->mutex);
assertlocked(p->rwlatch);
if(!p->dirty) {
p->dirty = 1;
dpt_entry * e = malloc(sizeof(*e));

View file

@ -277,7 +277,9 @@ static void TregionAllocHelper(int xid, pageid_t page, pageid_t pageCount, int a
// prevents the file from becoming sparse.
for(pageid_t i = page+1; i < newPageid; i++) {
Page * p = loadUninitializedPage(xid, i);
writelock(p->rwlatch, 0);
stasis_dirty_page_table_set_dirty(stasis_runtime_dirty_page_table(), p);
unlock(p->rwlatch);
releasePage(p);
}