34 #if defined(LIBC_SCCS) && !defined(lint) 35 static char sccsid[] =
"@(#)mpool.c 8.5 (Berkeley) 7/26/94";
38 #include <sys/param.h> 48 #include "../include/db.h" 50 #define __MPOOLINTERFACE_PRIVATE 56 #define mpool_open __mpool_open 57 #define mpool_filter __mpool_filter 58 #define mpool_new __mpool_new 59 #define mpool_get __mpool_get 60 #define mpool_put __mpool_put 61 #define mpool_sync __mpool_sync 62 #define mpool_close __mpool_close 91 if (!S_ISREG(sb.st_mode)) {
100 for (entry = 0; entry <
HASHSIZE; ++entry)
102 mp->maxcache = maxcache;
103 mp->npages = sb.st_size / pagesize;
104 mp->pagesize = pagesize;
116 void (*pgin)
__P((
void *,
pgno_t,
void *));
117 void (*pgout)
__P((
void *,
pgno_t,
void *));
138 (void)fprintf(stderr,
"mpool_new: page allocation overflow.\n");
189 (void)fprintf(stderr,
190 "mpool_get: page %d already pinned\n", bp->
pgno);
218 if (lseek(mp->
fd, off, SEEK_SET) != off)
240 if (mp->pgin !=
NULL)
261 bp = (
BKT *)((
char *)page -
sizeof(
BKT));
264 (void)fprintf(stderr,
265 "mpool_put: page %d not pinned\n", bp->
pgno);
285 while ((bp = mp->lqh.cqh_first) != (
void *)&mp->lqh) {
306 for (bp = mp->lqh.cqh_first;
307 bp != (
void *)&mp->lqh; bp = bp->q.cqe_next)
327 #define weak_alias(original, alias) \ 328 asm (".weak " #alias "\n" #alias " = " #original); 359 for (bp = mp->lqh.cqh_first;
360 bp != (
void *)&mp->lqh; bp = bp->q.cqe_next)
388 #if defined(DEBUG) || defined(PURIFY) 391 bp->
page = (
char *)bp +
sizeof(
BKT);
416 if (lseek(mp->
fd, off, SEEK_SET) != off)
437 head = &mp->hqh[
HASHKEY(pgno)];
438 for (bp = head->cqh_first; bp != (
void *)head; bp = bp->hq.cqe_next)
439 if (bp->
pgno == pgno) {
464 (void)fprintf(stderr,
"%lu pages in the file\n", mp->npages);
465 (void)fprintf(stderr,
466 "page size %lu, cacheing %lu pages of %lu page max cache\n",
467 mp->pagesize, mp->curcache, mp->maxcache);
468 (void)fprintf(stderr,
"%lu page puts, %lu page gets, %lu page new\n",
469 mp->pageput, mp->pageget, mp->pagenew);
470 (void)fprintf(stderr,
"%lu page allocs, %lu page flushes\n",
471 mp->pagealloc, mp->pageflush);
472 if (mp->cachehit + mp->cachemiss)
473 (void)fprintf(stderr,
474 "%.0f%% cache hit rate (%lu hits, %lu misses)\n",
475 ((
double)mp->cachehit / (mp->cachehit + mp->cachemiss))
476 * 100, mp->cachehit, mp->cachemiss);
477 (void)fprintf(stderr,
"%lu page reads, %lu page writes\n",
478 mp->pageread, mp->pagewrite);
482 for (bp = mp->lqh.cqh_first;
483 bp != (
void *)&mp->lqh; bp = bp->q.cqe_next) {
484 (void)fprintf(stderr,
"%s%d", sep, bp->
pgno);
486 (void)fprintf(stderr,
"d");
488 (void)fprintf(stderr,
"P");
496 (void)fprintf(stderr,
"\n");
static int mpool_write(MPOOL *mp, BKT *bp)
static BKT * mpool_look(MPOOL *mp, pgno_t pgno)
#define CIRCLEQ_REMOVE(head, elm, field)
#define CIRCLEQ_INSERT_HEAD(head, elm, field)
#define CIRCLEQ_INSERT_TAIL(head, elm, field)
#define CIRCLEQ_INIT(head)
static BKT * mpool_bkt(MPOOL *mp)
static BKT *mpool_bkt __P((MPOOL *))