Add getCachedPage() call. This allows dirtyPageTable to write back pages with out accidentally reading them back in from disk with loadPage(). This should improve performance and allow loadPageOfType() to be used safely.

This commit is contained in:
Sears Russell 2009-07-14 07:46:47 +00:00
parent 4493dbb88b
commit b44f8b17b3
6 changed files with 45 additions and 9 deletions

View file

@ -164,6 +164,7 @@ compensated_function void __profile_releasePage(Page * p) {
Page * (*loadPageImpl)(int xid, pageid_t pageid, pagetype_t type) = 0; Page * (*loadPageImpl)(int xid, pageid_t pageid, pagetype_t type) = 0;
Page * (*loadUninitPageImpl)(int xid, pageid_t pageid) = 0; Page * (*loadUninitPageImpl)(int xid, pageid_t pageid) = 0;
Page * (*getCachedPageImpl)(int xid, pageid_t pageid) = 0;
void (*releasePageImpl)(Page * p) = 0; void (*releasePageImpl)(Page * p) = 0;
void (*writeBackPage)(Page * p) = 0; void (*writeBackPage)(Page * p) = 0;
void (*forcePages)() = 0; void (*forcePages)() = 0;
@ -175,7 +176,6 @@ Page * loadPage(int xid, pageid_t pageid) {
// This lock is released at Tcommit() // This lock is released at Tcommit()
if(globalLockManager.readLockPage) { globalLockManager.readLockPage(xid, pageid); } if(globalLockManager.readLockPage) { globalLockManager.readLockPage(xid, pageid); }
return loadPageImpl(xid, pageid, UNKNOWN_TYPE_PAGE); return loadPageImpl(xid, pageid, UNKNOWN_TYPE_PAGE);
} }
Page * loadPageOfType(int xid, pageid_t pageid, pagetype_t type) { Page * loadPageOfType(int xid, pageid_t pageid, pagetype_t type) {
if(globalLockManager.readLockPage) { globalLockManager.readLockPage(xid, pageid); } if(globalLockManager.readLockPage) { globalLockManager.readLockPage(xid, pageid); }
@ -186,9 +186,10 @@ Page * loadUninitializedPage(int xid, pageid_t pageid) {
if(globalLockManager.readLockPage) { globalLockManager.readLockPage(xid, pageid); } if(globalLockManager.readLockPage) { globalLockManager.readLockPage(xid, pageid); }
return loadUninitPageImpl(xid, pageid); return loadUninitPageImpl(xid, pageid);
} }
Page * getCachedPage(int xid, pageid_t pageid) {
return getCachedPageImpl(xid, pageid);
}
void releasePage(Page * p) { void releasePage(Page * p) {
releasePageImpl(p); releasePageImpl(p);
} }

View file

@ -190,6 +190,27 @@ static void * writeBackWorker(void * ignored) {
return 0; return 0;
} }
static Page * bhGetCachedPage(int xid, const pageid_t pageid) {
pthread_mutex_lock(&mut);
// Is the page in cache?
Page * ret = LH_ENTRY(find)(cachedPages, &pageid, sizeof(pageid));
if(ret) {
checkPageState(ret);
if(!*pagePendingPtr(ret)) {
// good
if(!*pagePinCountPtr(ret) ) {
// Then ret is in lru (otherwise it would be pending, or not cached); remove it.
lru->remove(lru, ret);
}
(*pagePinCountPtr(ret))++;
} else {
ret = 0;
}
}
pthread_mutex_unlock(&mut);
return ret;
}
static Page * bhLoadPageImpl_helper(int xid, const pageid_t pageid, int uninitialized, pagetype_t type) { static Page * bhLoadPageImpl_helper(int xid, const pageid_t pageid, int uninitialized, pagetype_t type) {
// Note: Calls to loadlatch in this function violate lock order, but // Note: Calls to loadlatch in this function violate lock order, but
@ -397,6 +418,7 @@ void stasis_buffer_manager_hash_open(stasis_page_handle_t * h) {
loadPageImpl = bhLoadPageImpl; loadPageImpl = bhLoadPageImpl;
loadUninitPageImpl = bhLoadUninitPageImpl; loadUninitPageImpl = bhLoadUninitPageImpl;
getCachedPageImpl = bhGetCachedPage;
releasePageImpl = bhReleasePage; releasePageImpl = bhReleasePage;
writeBackPage = bhWriteBackPage; writeBackPage = bhWriteBackPage;
forcePages = bhForcePages; forcePages = bhForcePages;

View file

@ -45,6 +45,7 @@ int stasis_buffer_manager_deprecated_open(stasis_page_handle_t * ph) {
releasePageImpl = bufManReleasePage; releasePageImpl = bufManReleasePage;
loadPageImpl = bufManLoadPage; loadPageImpl = bufManLoadPage;
loadUninitPageImpl = bufManLoadUninitPage; loadUninitPageImpl = bufManLoadUninitPage;
getCachedPageImpl = bufManLoadPage; // Since this code is deprecated, loadPage is "good enough" though it breaks segments.
writeBackPage = pageWrite_legacyWrapper; writeBackPage = pageWrite_legacyWrapper;
forcePages = forcePageFile_legacyWrapper; forcePages = forcePageFile_legacyWrapper;
forcePageRange = forceRangePageFile_legacyWrapper; forcePageRange = forceRangePageFile_legacyWrapper;

View file

@ -62,6 +62,7 @@ void stasis_buffer_manager_mem_array_open () {
releasePageImpl = paReleasePage; releasePageImpl = paReleasePage;
loadPageImpl = paLoadPage; loadPageImpl = paLoadPage;
getCachedPageImpl = paLoadPage;
writeBackPage = paWriteBackPage; writeBackPage = paWriteBackPage;
forcePages = paForcePages; forcePages = paForcePages;
stasis_buffer_manager_close = paBufDeinit; stasis_buffer_manager_close = paBufDeinit;

View file

@ -91,9 +91,11 @@ void stasis_dirty_page_table_flush(stasis_dirty_page_table_t * dirtyPages) {
pthread_mutex_unlock(&dirtyPages->mutex); pthread_mutex_unlock(&dirtyPages->mutex);
for(i = 0; i < MAX_BUFFER_SIZE && staleDirtyPages[i] != -1; i++) { for(i = 0; i < MAX_BUFFER_SIZE && staleDirtyPages[i] != -1; i++) {
p = loadPage(-1, staleDirtyPages[i]); p = getCachedPage(-1, staleDirtyPages[i]);
writeBackPage(p); if(p) {
releasePage(p); writeBackPage(p);
releasePage(p);
}
} }
free(staleDirtyPages); free(staleDirtyPages);
} }
@ -117,9 +119,11 @@ void stasis_dirty_page_table_flush_range(stasis_dirty_page_table_t * dirtyPages,
pthread_mutex_unlock(&dirtyPages->mutex); pthread_mutex_unlock(&dirtyPages->mutex);
for(i = 0; i < MAX_BUFFER_SIZE && staleDirtyPages[i] != -1; i++) { for(i = 0; i < MAX_BUFFER_SIZE && staleDirtyPages[i] != -1; i++) {
p = loadPage(-1, staleDirtyPages[i]); p = getCachedPage(-1, staleDirtyPages[i]);
writeBackPage(p); if(p) {
releasePage(p); writeBackPage(p);
releasePage(p);
}
} }
free(staleDirtyPages); free(staleDirtyPages);
forcePageRange(start*PAGE_SIZE,stop*PAGE_SIZE); forcePageRange(start*PAGE_SIZE,stop*PAGE_SIZE);

View file

@ -97,6 +97,7 @@ Page * loadPageOfType(int xid, pageid_t pageid, pagetype_t type);
Page * loadUninitializedPage(int xid, pageid_t pageid); Page * loadUninitializedPage(int xid, pageid_t pageid);
Page * getCachedPage(int xid, const pageid_t pageid);
/** /**
This is the function pointer that stasis_buffer_manager_open sets in order to This is the function pointer that stasis_buffer_manager_open sets in order to
@ -104,6 +105,12 @@ Page * loadUninitializedPage(int xid, pageid_t pageid);
*/ */
extern Page * (*loadPageImpl)(int xid, pageid_t pageid, pagetype_t type); extern Page * (*loadPageImpl)(int xid, pageid_t pageid, pagetype_t type);
extern Page * (*loadUninitPageImpl)(int xid, pageid_t pageid); extern Page * (*loadUninitPageImpl)(int xid, pageid_t pageid);
/**
Get a page from cache. This function should never block on I/O.
@return a pointer to the page, or NULL if the page is not in cache, or is being read from disk.
*/
extern Page * (*getCachedPageImpl)(int xid, pageid_t pageid);
/** /**
loadPage aquires a lock when it is called, effectively pinning it loadPage aquires a lock when it is called, effectively pinning it
in memory. releasePage releases this lock. in memory. releasePage releases this lock.