2004-06-24 21:10:31 +00:00
|
|
|
/*---
|
|
|
|
This software is copyrighted by the Regents of the University of
|
|
|
|
California, and other parties. The following terms apply to all files
|
|
|
|
associated with the software unless explicitly disclaimed in
|
|
|
|
individual files.
|
|
|
|
|
|
|
|
The authors hereby grant permission to use, copy, modify, distribute,
|
|
|
|
and license this software and its documentation for any purpose,
|
|
|
|
provided that existing copyright notices are retained in all copies
|
|
|
|
and that this notice is included verbatim in any distributions. No
|
|
|
|
written agreement, license, or royalty fee is required for any of the
|
|
|
|
authorized uses. Modifications to this software may be copyrighted by
|
|
|
|
their authors and need not follow the licensing terms described here,
|
|
|
|
provided that the new terms are clearly indicated on the first page of
|
|
|
|
each file where they apply.
|
|
|
|
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
|
|
|
|
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
|
|
|
|
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
|
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
|
|
NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND
|
|
|
|
THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
|
|
|
|
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
|
|
|
|
GOVERNMENT USE: If you are acquiring this software on behalf of the
|
|
|
|
U.S. government, the Government shall have only "Restricted Rights" in
|
|
|
|
the software and related documentation as defined in the Federal
|
|
|
|
Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you are
|
|
|
|
acquiring the software on behalf of the Department of Defense, the
|
|
|
|
software shall be classified as "Commercial Computer Software" and the
|
|
|
|
Government shall have only "Restricted Rights" as defined in Clause
|
|
|
|
252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
|
|
|
|
authors grant the U.S. Government and others acting in its behalf
|
|
|
|
permission to use and distribute the software in accordance with the
|
|
|
|
terms specified in this license.
|
|
|
|
---*/
|
|
|
|
/*******************************
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* implementation of the page buffer
|
|
|
|
* *************************************************/
|
2004-07-06 01:22:18 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
2006-08-04 23:45:27 +00:00
|
|
|
|
|
|
|
#ifdef PROFILE_LATCHES_WRITE_ONLY
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <stdio.h> // Need _GNU_SOURCE for asprintf
|
|
|
|
#include <lladd/lhtable.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2004-07-06 01:22:18 +00:00
|
|
|
#include <lladd/common.h>
|
2004-07-20 00:15:17 +00:00
|
|
|
#include <latches.h>
|
2004-06-24 21:10:31 +00:00
|
|
|
#include <assert.h>
|
2004-07-23 20:21:44 +00:00
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
#include <lladd/bufferManager.h>
|
2007-03-04 02:46:23 +00:00
|
|
|
#include "bufferManager/pageArray.h"
|
2006-08-04 23:45:27 +00:00
|
|
|
|
2006-04-11 20:34:52 +00:00
|
|
|
#include <lladd/bufferPool.h>
|
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
#include <lladd/lockManager.h>
|
2004-06-30 01:09:57 +00:00
|
|
|
#include <lladd/pageCache.h>
|
2004-07-15 00:42:36 +00:00
|
|
|
#include "pageFile.h"
|
2006-08-04 23:45:27 +00:00
|
|
|
|
2006-04-14 03:45:26 +00:00
|
|
|
#include <lladd/truncation.h>
|
2004-07-14 20:49:18 +00:00
|
|
|
|
2006-08-10 23:45:25 +00:00
|
|
|
#include <lladd/lhtable.h>
|
|
|
|
|
2006-08-04 23:45:27 +00:00
|
|
|
#undef loadPage
|
|
|
|
#undef releasePage
|
|
|
|
#undef Page
|
|
|
|
|
|
|
|
#ifdef LONG_TEST
|
|
|
|
#define PIN_COUNT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PROFILE_LATCHES_WRITE_ONLY
|
|
|
|
|
|
|
|
// These should only be defined if PROFILE_LATCHES_WRITE_ONLY is set.
|
|
|
|
|
|
|
|
#undef loadPage
|
|
|
|
#undef releasePage
|
|
|
|
|
|
|
|
pthread_mutex_t profile_load_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
struct LH_ENTRY(table) * profile_load_hash = 0;
|
|
|
|
struct LH_ENTRY(table) * profile_load_pins_hash = 0;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PIN_COUNT
|
2006-07-25 01:00:46 +00:00
|
|
|
pthread_mutex_t pinCount_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
int pinCount = 0;
|
|
|
|
#endif
|
|
|
|
|
2006-08-10 23:45:25 +00:00
|
|
|
static struct LH_ENTRY(table) *activePages; /* page lookup */
|
2004-10-19 04:45:42 +00:00
|
|
|
/*static Page * activePagePtrs[MAX_BUFFER_SIZE];*/
|
|
|
|
|
2004-07-27 01:04:35 +00:00
|
|
|
|
|
|
|
static pthread_mutex_t loadPagePtr_mutex;
|
|
|
|
|
|
|
|
static Page * dummy_page;
|
2004-06-30 01:09:57 +00:00
|
|
|
|
2007-03-04 00:36:45 +00:00
|
|
|
static pthread_key_t lastPage;
|
2006-08-10 23:45:25 +00:00
|
|
|
|
2007-03-04 02:46:23 +00:00
|
|
|
static void bufManBufDeinit();
|
|
|
|
static compensated_function Page *bufManLoadPage(int xid, int pageid);
|
|
|
|
static void bufManReleasePage (Page * p);
|
|
|
|
|
2007-03-04 00:36:45 +00:00
|
|
|
static int bufManBufInit() {
|
2007-03-03 01:52:03 +00:00
|
|
|
|
2007-03-04 02:46:23 +00:00
|
|
|
releasePage = bufManReleasePage;
|
|
|
|
loadPage = bufManLoadPage;
|
|
|
|
writeBackPage = pageWrite;
|
|
|
|
forcePages = forcePageFile;
|
|
|
|
bufDeinit = bufManBufDeinit;
|
|
|
|
|
|
|
|
|
2007-03-03 01:52:03 +00:00
|
|
|
bufferPoolInit();
|
2004-06-30 01:09:57 +00:00
|
|
|
|
|
|
|
openPageFile();
|
2004-07-14 20:49:18 +00:00
|
|
|
|
2004-07-27 01:04:35 +00:00
|
|
|
|
|
|
|
pthread_mutex_init(&loadPagePtr_mutex, NULL);
|
|
|
|
|
2006-08-10 23:45:25 +00:00
|
|
|
activePages = LH_ENTRY(create)(16);
|
2004-07-27 01:04:35 +00:00
|
|
|
|
2004-08-17 01:46:17 +00:00
|
|
|
dummy_page = pageMalloc();
|
2006-04-11 20:34:52 +00:00
|
|
|
pageFree(dummy_page, -1);
|
2004-07-27 01:04:35 +00:00
|
|
|
Page *first;
|
2004-08-17 01:46:17 +00:00
|
|
|
first = pageMalloc();
|
2006-04-11 20:34:52 +00:00
|
|
|
pageFree(first, 0);
|
2006-08-10 23:45:25 +00:00
|
|
|
LH_ENTRY(insert)(activePages, &first->id, sizeof(int), first);
|
2004-10-19 04:45:42 +00:00
|
|
|
|
2004-07-27 01:04:35 +00:00
|
|
|
pageCacheInit(first);
|
|
|
|
|
2006-08-10 23:45:25 +00:00
|
|
|
int err = pthread_key_create(&lastPage, 0);
|
|
|
|
assert(!err);
|
|
|
|
|
2004-07-27 01:04:35 +00:00
|
|
|
assert(activePages);
|
2006-08-04 23:45:27 +00:00
|
|
|
#ifdef PROFILE_LATCHES_WRITE_ONLY
|
|
|
|
profile_load_hash = LH_ENTRY(create)(10);
|
|
|
|
profile_load_pins_hash = LH_ENTRY(create)(10);
|
|
|
|
#endif
|
2004-06-24 21:10:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-04 00:36:45 +00:00
|
|
|
static void bufManBufDeinit() {
|
2004-07-27 01:04:35 +00:00
|
|
|
|
|
|
|
DEBUG("pageCacheDeinit()");
|
2004-10-19 04:45:42 +00:00
|
|
|
|
2006-08-10 23:45:25 +00:00
|
|
|
struct LH_ENTRY(list) iter;
|
|
|
|
const struct LH_ENTRY(pair_t) * next;
|
|
|
|
LH_ENTRY(openlist(activePages, &iter));
|
2004-07-27 01:04:35 +00:00
|
|
|
|
2006-08-10 23:45:25 +00:00
|
|
|
while((next = LH_ENTRY(readlist)(&iter))) {
|
|
|
|
pageWrite((Page*)next->value);
|
2004-07-27 01:04:35 +00:00
|
|
|
DEBUG("+");
|
|
|
|
}
|
2007-03-03 01:52:03 +00:00
|
|
|
|
2006-08-10 23:45:25 +00:00
|
|
|
LH_ENTRY(destroy)(activePages);
|
|
|
|
|
2004-07-27 01:04:35 +00:00
|
|
|
pthread_mutex_destroy(&loadPagePtr_mutex);
|
|
|
|
|
2004-06-30 01:09:57 +00:00
|
|
|
pageCacheDeinit();
|
|
|
|
closePageFile();
|
2007-03-03 01:52:03 +00:00
|
|
|
|
|
|
|
bufferPoolDeInit();
|
2004-07-27 01:04:35 +00:00
|
|
|
|
2006-08-04 23:45:27 +00:00
|
|
|
#ifdef PIN_COUNT
|
2006-07-25 01:00:46 +00:00
|
|
|
if(pinCount != 0) {
|
|
|
|
printf("WARNING: At exit, %d pages were still pinned!\n", pinCount);
|
|
|
|
}
|
|
|
|
#endif
|
2004-06-30 01:09:57 +00:00
|
|
|
return;
|
2004-06-24 21:10:31 +00:00
|
|
|
}
|
2004-06-30 01:09:57 +00:00
|
|
|
/**
|
|
|
|
Just close file descriptors, don't do any other clean up. (For
|
|
|
|
testing.)
|
2004-06-28 22:48:02 +00:00
|
|
|
*/
|
2004-06-30 01:09:57 +00:00
|
|
|
void simulateBufferManagerCrash() {
|
|
|
|
closePageFile();
|
2006-08-04 23:45:27 +00:00
|
|
|
#ifdef PIN_COUNT
|
2006-07-25 01:00:46 +00:00
|
|
|
pinCount = 0;
|
|
|
|
#endif
|
2004-06-24 21:10:31 +00:00
|
|
|
}
|
|
|
|
|
2007-03-04 00:36:45 +00:00
|
|
|
static void bufManReleasePage (Page * p) {
|
2004-07-23 20:21:44 +00:00
|
|
|
unlock(p->loadlatch);
|
2006-08-04 23:45:27 +00:00
|
|
|
#ifdef PIN_COUNT
|
2006-07-25 01:00:46 +00:00
|
|
|
pthread_mutex_lock(&pinCount_mutex);
|
|
|
|
pinCount --;
|
|
|
|
pthread_mutex_unlock(&pinCount_mutex);
|
|
|
|
#endif
|
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
}
|
|
|
|
|
2006-04-14 03:45:26 +00:00
|
|
|
static Page * getPage(int pageid, int locktype) {
|
2004-07-27 01:04:35 +00:00
|
|
|
Page * ret;
|
|
|
|
int spin = 0;
|
2005-02-10 03:51:09 +00:00
|
|
|
|
2004-07-27 01:04:35 +00:00
|
|
|
pthread_mutex_lock(&loadPagePtr_mutex);
|
2006-08-10 23:45:25 +00:00
|
|
|
ret = LH_ENTRY(find)(activePages, &pageid, sizeof(int));
|
2004-07-27 01:04:35 +00:00
|
|
|
|
|
|
|
if(ret) {
|
2006-08-04 23:45:27 +00:00
|
|
|
#ifdef PROFILE_LATCHES_WRITE_ONLY
|
|
|
|
// "holder" will contain a \n delimited list of the sites that
|
|
|
|
// called loadPage() on the pinned page since the last time it was
|
|
|
|
// completely unpinned. One such site is responsible for the
|
|
|
|
// leak.
|
|
|
|
|
|
|
|
char * holder = LH_ENTRY(find)(profile_load_hash, &ret, sizeof(void*));
|
|
|
|
int * pins = LH_ENTRY(find)(profile_load_pins_hash, &ret, sizeof(void*));
|
|
|
|
char * holderD =0;
|
|
|
|
int pinsD = 0;
|
|
|
|
if(holder) {
|
|
|
|
holderD = strdup(holder);
|
|
|
|
pinsD = *pins;
|
|
|
|
}
|
|
|
|
#endif
|
2004-07-27 01:04:35 +00:00
|
|
|
if(locktype == RW) {
|
|
|
|
writelock(ret->loadlatch, 217);
|
|
|
|
} else {
|
|
|
|
readlock(ret->loadlatch, 217);
|
|
|
|
}
|
2006-08-04 23:45:27 +00:00
|
|
|
#ifdef PROFILE_LATCHES_WRITE_ONLY
|
|
|
|
if(holderD)
|
|
|
|
free(holderD);
|
|
|
|
#endif
|
2004-07-27 01:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (ret && (ret->id != pageid)) {
|
|
|
|
unlock(ret->loadlatch);
|
|
|
|
pthread_mutex_unlock(&loadPagePtr_mutex);
|
|
|
|
sched_yield();
|
|
|
|
pthread_mutex_lock(&loadPagePtr_mutex);
|
2006-08-10 23:45:25 +00:00
|
|
|
ret = LH_ENTRY(find)(activePages, &pageid, sizeof(int));
|
2004-07-27 01:04:35 +00:00
|
|
|
|
|
|
|
if(ret) {
|
2006-08-04 23:45:27 +00:00
|
|
|
#ifdef PROFILE_LATCHES_WRITE_ONLY
|
|
|
|
// "holder" will contain a \n delimited list of the sites that
|
|
|
|
// called loadPage() on the pinned page since the last time it was
|
|
|
|
// completely unpinned. One such site is responsible for the
|
|
|
|
// leak.
|
|
|
|
|
|
|
|
char * holder = LH_ENTRY(find)(profile_load_hash, &ret, sizeof(void*));
|
|
|
|
int * pins = LH_ENTRY(find)(profile_load_pins_hash, &ret, sizeof(void*));
|
|
|
|
|
|
|
|
char * holderD = 0;
|
|
|
|
int pinsD = 0;
|
|
|
|
if(holder) {
|
|
|
|
holderD = strdup(holder);
|
|
|
|
pinsD = *pins;
|
|
|
|
}
|
|
|
|
#endif
|
2004-07-27 01:04:35 +00:00
|
|
|
if(locktype == RW) {
|
|
|
|
writelock(ret->loadlatch, 217);
|
|
|
|
} else {
|
|
|
|
readlock(ret->loadlatch, 217);
|
|
|
|
}
|
2006-08-04 23:45:27 +00:00
|
|
|
#ifdef PROFILE_LATCHES_WRITE_ONLY
|
|
|
|
if(holderD)
|
|
|
|
free(holderD);
|
|
|
|
#endif
|
2004-07-27 01:04:35 +00:00
|
|
|
}
|
|
|
|
spin++;
|
2006-10-04 04:39:58 +00:00
|
|
|
if(spin > 10000 && !(spin % 10000)) {
|
2004-07-27 01:04:35 +00:00
|
|
|
printf("GetPage is stuck!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret) {
|
|
|
|
cacheHitOnPage(ret);
|
|
|
|
assert(ret->id == pageid);
|
|
|
|
pthread_mutex_unlock(&loadPagePtr_mutex);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* If ret is null, then we know that:
|
|
|
|
|
|
|
|
a) there is no cache entry for pageid
|
|
|
|
b) this is the only thread that has gotten this far,
|
|
|
|
and that will try to add an entry for pageid
|
|
|
|
c) the most recent version of this page has been
|
|
|
|
written to the OS's file cache. */
|
|
|
|
int oldid = -1;
|
|
|
|
|
|
|
|
if( cache_state == FULL ) {
|
|
|
|
|
|
|
|
/* Select an item from cache, and remove it atomicly. (So it's
|
|
|
|
only reclaimed once) */
|
|
|
|
|
|
|
|
ret = cacheStalePage();
|
|
|
|
cacheRemovePage(ret);
|
|
|
|
|
|
|
|
oldid = ret->id;
|
|
|
|
|
|
|
|
assert(oldid != pageid);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2004-08-17 01:46:17 +00:00
|
|
|
ret = pageMalloc();
|
2004-07-27 01:04:35 +00:00
|
|
|
ret->id = -1;
|
|
|
|
ret->inCache = 0;
|
|
|
|
}
|
|
|
|
|
2006-08-04 23:45:27 +00:00
|
|
|
// If you leak a page, and it eventually gets evicted, and reused, the system deadlocks here.
|
|
|
|
#ifdef PROFILE_LATCHES_WRITE_ONLY
|
|
|
|
// "holder" will contain a \n delimited list of the sites that
|
|
|
|
// called loadPage() on the pinned page since the last time it was
|
|
|
|
// completely unpinned. One such site is responsible for the
|
|
|
|
// leak.
|
|
|
|
|
|
|
|
char * holder = LH_ENTRY(find)(profile_load_hash, &ret, sizeof(void*));
|
|
|
|
int * pins = LH_ENTRY(find)(profile_load_pins_hash, &ret, sizeof(void*));
|
|
|
|
|
|
|
|
char * holderD = 0;
|
|
|
|
int pinsD = 0;
|
|
|
|
if(holder) {
|
|
|
|
holderD = strdup(holder);
|
|
|
|
pinsD = *pins;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2004-07-27 01:04:35 +00:00
|
|
|
writelock(ret->loadlatch, 217);
|
2006-08-04 23:45:27 +00:00
|
|
|
#ifdef PROFILE_LATCHES_WRITE_ONLY
|
|
|
|
if(holderD)
|
|
|
|
free(holderD);
|
|
|
|
#endif
|
2004-07-27 01:04:35 +00:00
|
|
|
|
|
|
|
/* Inserting this into the cache before releasing the mutex
|
|
|
|
ensures that constraint (b) above holds. */
|
2006-08-10 23:45:25 +00:00
|
|
|
LH_ENTRY(insert)(activePages, &pageid, sizeof(int), ret);
|
2004-07-27 01:04:35 +00:00
|
|
|
pthread_mutex_unlock(&loadPagePtr_mutex);
|
|
|
|
|
|
|
|
/* Could writelock(ret) go here? */
|
|
|
|
|
|
|
|
assert(ret != dummy_page);
|
|
|
|
if(ret->id != -1) {
|
|
|
|
pageWrite(ret);
|
|
|
|
}
|
|
|
|
|
2006-04-11 20:34:52 +00:00
|
|
|
pageFree(ret, pageid);
|
2004-07-27 01:04:35 +00:00
|
|
|
|
|
|
|
pageRead(ret);
|
|
|
|
|
|
|
|
writeunlock(ret->loadlatch);
|
|
|
|
|
|
|
|
pthread_mutex_lock(&loadPagePtr_mutex);
|
|
|
|
|
2006-08-10 23:45:25 +00:00
|
|
|
LH_ENTRY(remove)(activePages, &(oldid), sizeof(int));
|
2004-07-27 01:04:35 +00:00
|
|
|
|
2004-10-18 18:24:54 +00:00
|
|
|
/* @todo Put off putting this back into cache until we're done with
|
2004-07-27 01:04:35 +00:00
|
|
|
it. -- This could cause the cache to empty out if the ratio of
|
|
|
|
threads to buffer slots is above ~ 1/3, but it decreases the
|
|
|
|
liklihood of thrashing. */
|
|
|
|
cacheInsertPage(ret);
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&loadPagePtr_mutex);
|
2006-08-04 23:45:27 +00:00
|
|
|
#ifdef PROFILE_LATCHES_WRITE_ONLY
|
|
|
|
// "holder" will contain a \n delimited list of the sites that
|
|
|
|
// called loadPage() on the pinned page since the last time it was
|
|
|
|
// completely unpinned. One such site is responsible for the
|
|
|
|
// leak.
|
|
|
|
|
|
|
|
holder = LH_ENTRY(find)(profile_load_hash, &ret, sizeof(void*));
|
|
|
|
pins = LH_ENTRY(find)(profile_load_pins_hash, &ret, sizeof(void*));
|
|
|
|
|
|
|
|
if(holder) {
|
|
|
|
holderD = strdup(holder);
|
|
|
|
pinsD = *pins;
|
|
|
|
}
|
|
|
|
#endif
|
2004-07-27 01:04:35 +00:00
|
|
|
if(locktype == RW) {
|
|
|
|
writelock(ret->loadlatch, 217);
|
|
|
|
} else {
|
|
|
|
readlock(ret->loadlatch, 217);
|
|
|
|
}
|
2006-08-04 23:45:27 +00:00
|
|
|
#ifdef PROFILE_LATCHES_WRITE_ONLY
|
|
|
|
if(holderD)
|
|
|
|
free(holderD);
|
|
|
|
#endif
|
2004-07-27 01:04:35 +00:00
|
|
|
if(ret->id != pageid) {
|
|
|
|
unlock(ret->loadlatch);
|
|
|
|
printf("pageCache.c: Thrashing detected. Strongly consider increasing LLADD's buffer pool size!\n");
|
|
|
|
fflush(NULL);
|
|
|
|
return getPage(pageid, locktype);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-08-04 23:45:27 +00:00
|
|
|
#ifdef PROFILE_LATCHES_WRITE_ONLY
|
|
|
|
|
|
|
|
compensated_function Page * __profile_loadPage(int xid, int pageid, char * file, int line) {
|
|
|
|
|
|
|
|
Page * ret = loadPage(xid, pageid);
|
|
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock(&profile_load_mutex);
|
|
|
|
|
|
|
|
char * holder = LH_ENTRY(find)(profile_load_hash, &ret, sizeof(void*));
|
|
|
|
int * pins = LH_ENTRY(find)(profile_load_pins_hash, &ret, sizeof(void*));
|
|
|
|
|
|
|
|
if(!pins) {
|
|
|
|
pins = malloc(sizeof(int));
|
|
|
|
*pins = 0;
|
|
|
|
LH_ENTRY(insert)(profile_load_pins_hash, &ret, sizeof(void*), pins);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*pins) {
|
|
|
|
assert(holder);
|
|
|
|
char * newHolder;
|
|
|
|
asprintf(&newHolder, "%s\n%s:%d", holder, file, line);
|
|
|
|
free(holder);
|
|
|
|
holder = newHolder;
|
|
|
|
} else {
|
|
|
|
assert(!holder);
|
|
|
|
asprintf(&holder, "%s:%d", file, line);
|
|
|
|
}
|
|
|
|
(*pins)++;
|
|
|
|
LH_ENTRY(insert)(profile_load_hash, &ret, sizeof(void*), holder);
|
|
|
|
pthread_mutex_unlock(&profile_load_mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
compensated_function void __profile_releasePage(Page * p) {
|
|
|
|
pthread_mutex_lock(&profile_load_mutex);
|
|
|
|
|
|
|
|
// int pageid = p->id;
|
|
|
|
int * pins = LH_ENTRY(find)(profile_load_pins_hash, &p, sizeof(void*));
|
|
|
|
|
|
|
|
assert(pins);
|
|
|
|
|
|
|
|
if(*pins == 1) {
|
|
|
|
|
|
|
|
char * holder = LH_ENTRY(remove)(profile_load_hash, &p, sizeof(void*));
|
|
|
|
assert(holder);
|
|
|
|
free(holder);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(*pins)--;
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&profile_load_mutex);
|
|
|
|
|
|
|
|
releasePage(p);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-03-04 00:36:45 +00:00
|
|
|
static compensated_function Page *bufManLoadPage(int xid, int pageid) {
|
2006-07-25 01:00:46 +00:00
|
|
|
|
2005-02-16 04:11:14 +00:00
|
|
|
try_ret(NULL) {
|
|
|
|
if(globalLockManager.readLockPage) { globalLockManager.readLockPage(xid, pageid); }
|
|
|
|
} end_ret(NULL);
|
2006-08-04 23:45:27 +00:00
|
|
|
|
|
|
|
|
2006-08-10 23:45:25 +00:00
|
|
|
Page * ret = pthread_getspecific(lastPage);
|
|
|
|
|
|
|
|
if(ret && ret->id == pageid) {
|
|
|
|
pthread_mutex_lock(&loadPagePtr_mutex);
|
|
|
|
readlock(ret->loadlatch, 1);
|
|
|
|
if(ret->id != pageid) {
|
|
|
|
unlock(ret->loadlatch);
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
cacheHitOnPage(ret);
|
|
|
|
pthread_mutex_unlock(&loadPagePtr_mutex);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
if(!ret) {
|
|
|
|
ret = getPage(pageid, RO);
|
|
|
|
pthread_setspecific(lastPage, ret);
|
|
|
|
}
|
2006-07-25 01:00:46 +00:00
|
|
|
|
2006-08-04 23:45:27 +00:00
|
|
|
#ifdef PIN_COUNT
|
2006-07-25 01:00:46 +00:00
|
|
|
pthread_mutex_lock(&pinCount_mutex);
|
|
|
|
pinCount ++;
|
|
|
|
pthread_mutex_unlock(&pinCount_mutex);
|
|
|
|
#endif
|
|
|
|
|
2004-07-27 01:04:35 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2006-08-04 23:45:27 +00:00
|
|
|
|
2007-03-03 01:52:03 +00:00
|
|
|
Page * (*loadPage)(int xid, int pageid) = 0;
|
|
|
|
void (*releasePage)(Page * p) = 0;
|
2007-03-04 00:36:45 +00:00
|
|
|
void (*writeBackPage)(Page * p) = 0;
|
|
|
|
void (*forcePages)() = 0;
|
|
|
|
void (*bufDeinit)() = 0;
|
2007-03-04 02:46:23 +00:00
|
|
|
|
2007-03-04 00:36:45 +00:00
|
|
|
int bufInit(int type) {
|
|
|
|
static int lastType = 0;
|
|
|
|
if(type == BUFFER_MANAGER_REOPEN) {
|
|
|
|
type = lastType;
|
|
|
|
}
|
|
|
|
lastType = type;
|
|
|
|
if(type == BUFFER_MANAGER_HASH) {
|
|
|
|
bufManBufInit();
|
|
|
|
return 0;
|
2007-03-04 02:46:23 +00:00
|
|
|
} else if (type == BUFFER_MANAGER_MEM_ARRAY) {
|
|
|
|
paBufInit();
|
|
|
|
return 0;
|
2007-03-04 00:36:45 +00:00
|
|
|
} else {
|
|
|
|
// XXX error handling
|
|
|
|
abort();
|
|
|
|
}
|
2007-03-03 01:52:03 +00:00
|
|
|
}
|