Use TAILQ instead of CIRCLEQ.
This commit is contained in:
parent
1d2187bfdb
commit
fabacd3a11
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=70492
@ -51,8 +51,8 @@
|
|||||||
|
|
||||||
/* The BKT structures are the elements of the queues. */
|
/* The BKT structures are the elements of the queues. */
|
||||||
typedef struct _bkt {
|
typedef struct _bkt {
|
||||||
CIRCLEQ_ENTRY(_bkt) hq; /* hash queue */
|
TAILQ_ENTRY(_bkt) hq; /* hash queue */
|
||||||
CIRCLEQ_ENTRY(_bkt) q; /* lru queue */
|
TAILQ_ENTRY(_bkt) q; /* lru queue */
|
||||||
void *page; /* page */
|
void *page; /* page */
|
||||||
pgno_t pgno; /* page number */
|
pgno_t pgno; /* page number */
|
||||||
|
|
||||||
@ -62,9 +62,9 @@ typedef struct _bkt {
|
|||||||
} BKT;
|
} BKT;
|
||||||
|
|
||||||
typedef struct MPOOL {
|
typedef struct MPOOL {
|
||||||
CIRCLEQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */
|
TAILQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */
|
||||||
/* hash queue array */
|
/* hash queue array */
|
||||||
CIRCLEQ_HEAD(_hqh, _bkt) hqh[HASHSIZE];
|
TAILQ_HEAD(_hqh, _bkt) hqh[HASHSIZE];
|
||||||
pgno_t curcache; /* current number of cached pages */
|
pgno_t curcache; /* current number of cached pages */
|
||||||
pgno_t maxcache; /* max number of cached pages */
|
pgno_t maxcache; /* max number of cached pages */
|
||||||
pgno_t npages; /* number of pages in the file */
|
pgno_t npages; /* number of pages in the file */
|
||||||
|
@ -86,9 +86,9 @@ mpool_open(key, fd, pagesize, maxcache)
|
|||||||
/* Allocate and initialize the MPOOL cookie. */
|
/* Allocate and initialize the MPOOL cookie. */
|
||||||
if ((mp = (MPOOL *)calloc(1, sizeof(MPOOL))) == NULL)
|
if ((mp = (MPOOL *)calloc(1, sizeof(MPOOL))) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
CIRCLEQ_INIT(&mp->lqh);
|
TAILQ_INIT(&mp->lqh);
|
||||||
for (entry = 0; entry < HASHSIZE; ++entry)
|
for (entry = 0; entry < HASHSIZE; ++entry)
|
||||||
CIRCLEQ_INIT(&mp->hqh[entry]);
|
TAILQ_INIT(&mp->hqh[entry]);
|
||||||
mp->maxcache = maxcache;
|
mp->maxcache = maxcache;
|
||||||
mp->npages = sb.st_size / pagesize;
|
mp->npages = sb.st_size / pagesize;
|
||||||
mp->pagesize = pagesize;
|
mp->pagesize = pagesize;
|
||||||
@ -142,8 +142,8 @@ mpool_new(mp, pgnoaddr)
|
|||||||
bp->flags = MPOOL_PINNED;
|
bp->flags = MPOOL_PINNED;
|
||||||
|
|
||||||
head = &mp->hqh[HASHKEY(bp->pgno)];
|
head = &mp->hqh[HASHKEY(bp->pgno)];
|
||||||
CIRCLEQ_INSERT_HEAD(head, bp, hq);
|
TAILQ_INSERT_HEAD(head, bp, hq);
|
||||||
CIRCLEQ_INSERT_TAIL(&mp->lqh, bp, q);
|
TAILQ_INSERT_TAIL(&mp->lqh, bp, q);
|
||||||
return (bp->page);
|
return (bp->page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,10 +186,10 @@ mpool_get(mp, pgno, flags)
|
|||||||
* of the lru chain.
|
* of the lru chain.
|
||||||
*/
|
*/
|
||||||
head = &mp->hqh[HASHKEY(bp->pgno)];
|
head = &mp->hqh[HASHKEY(bp->pgno)];
|
||||||
CIRCLEQ_REMOVE(head, bp, hq);
|
TAILQ_REMOVE(head, bp, hq);
|
||||||
CIRCLEQ_INSERT_HEAD(head, bp, hq);
|
TAILQ_INSERT_HEAD(head, bp, hq);
|
||||||
CIRCLEQ_REMOVE(&mp->lqh, bp, q);
|
TAILQ_REMOVE(&mp->lqh, bp, q);
|
||||||
CIRCLEQ_INSERT_TAIL(&mp->lqh, bp, q);
|
TAILQ_INSERT_TAIL(&mp->lqh, bp, q);
|
||||||
|
|
||||||
/* Return a pinned page. */
|
/* Return a pinned page. */
|
||||||
bp->flags |= MPOOL_PINNED;
|
bp->flags |= MPOOL_PINNED;
|
||||||
@ -222,8 +222,8 @@ mpool_get(mp, pgno, flags)
|
|||||||
* of the lru chain.
|
* of the lru chain.
|
||||||
*/
|
*/
|
||||||
head = &mp->hqh[HASHKEY(bp->pgno)];
|
head = &mp->hqh[HASHKEY(bp->pgno)];
|
||||||
CIRCLEQ_INSERT_HEAD(head, bp, hq);
|
TAILQ_INSERT_HEAD(head, bp, hq);
|
||||||
CIRCLEQ_INSERT_TAIL(&mp->lqh, bp, q);
|
TAILQ_INSERT_TAIL(&mp->lqh, bp, q);
|
||||||
|
|
||||||
/* Run through the user's filter. */
|
/* Run through the user's filter. */
|
||||||
if (mp->pgin != NULL)
|
if (mp->pgin != NULL)
|
||||||
@ -271,8 +271,8 @@ mpool_close(mp)
|
|||||||
BKT *bp;
|
BKT *bp;
|
||||||
|
|
||||||
/* Free up any space allocated to the lru pages. */
|
/* Free up any space allocated to the lru pages. */
|
||||||
while ((bp = mp->lqh.cqh_first) != (void *)&mp->lqh) {
|
while ((bp = TAILQ_FIRST(&mp->lqh)) != (void *)&mp->lqh) {
|
||||||
CIRCLEQ_REMOVE(&mp->lqh, mp->lqh.cqh_first, q);
|
TAILQ_REMOVE(&mp->lqh, bp, q);
|
||||||
free(bp);
|
free(bp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,8 +292,7 @@ mpool_sync(mp)
|
|||||||
BKT *bp;
|
BKT *bp;
|
||||||
|
|
||||||
/* Walk the lru chain, flushing any dirty pages to disk. */
|
/* Walk the lru chain, flushing any dirty pages to disk. */
|
||||||
for (bp = mp->lqh.cqh_first;
|
TAILQ_FOREACH(bp, &mp->lqh, q)
|
||||||
bp != (void *)&mp->lqh; bp = bp->q.cqe_next)
|
|
||||||
if (bp->flags & MPOOL_DIRTY &&
|
if (bp->flags & MPOOL_DIRTY &&
|
||||||
mpool_write(mp, bp) == RET_ERROR)
|
mpool_write(mp, bp) == RET_ERROR)
|
||||||
return (RET_ERROR);
|
return (RET_ERROR);
|
||||||
@ -323,8 +322,7 @@ mpool_bkt(mp)
|
|||||||
* off any lists. If we don't find anything we grow the cache anyway.
|
* off any lists. If we don't find anything we grow the cache anyway.
|
||||||
* The cache never shrinks.
|
* The cache never shrinks.
|
||||||
*/
|
*/
|
||||||
for (bp = mp->lqh.cqh_first;
|
TAILQ_FOREACH(bp, &mp->lqh, q)
|
||||||
bp != (void *)&mp->lqh; bp = bp->q.cqe_next)
|
|
||||||
if (!(bp->flags & MPOOL_PINNED)) {
|
if (!(bp->flags & MPOOL_PINNED)) {
|
||||||
/* Flush if dirty. */
|
/* Flush if dirty. */
|
||||||
if (bp->flags & MPOOL_DIRTY &&
|
if (bp->flags & MPOOL_DIRTY &&
|
||||||
@ -335,8 +333,8 @@ mpool_bkt(mp)
|
|||||||
#endif
|
#endif
|
||||||
/* Remove from the hash and lru queues. */
|
/* Remove from the hash and lru queues. */
|
||||||
head = &mp->hqh[HASHKEY(bp->pgno)];
|
head = &mp->hqh[HASHKEY(bp->pgno)];
|
||||||
CIRCLEQ_REMOVE(head, bp, hq);
|
TAILQ_REMOVE(head, bp, hq);
|
||||||
CIRCLEQ_REMOVE(&mp->lqh, bp, q);
|
TAILQ_REMOVE(&mp->lqh, bp, q);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
{ void *spage;
|
{ void *spage;
|
||||||
spage = bp->page;
|
spage = bp->page;
|
||||||
@ -402,7 +400,7 @@ mpool_look(mp, pgno)
|
|||||||
BKT *bp;
|
BKT *bp;
|
||||||
|
|
||||||
head = &mp->hqh[HASHKEY(pgno)];
|
head = &mp->hqh[HASHKEY(pgno)];
|
||||||
for (bp = head->cqh_first; bp != (void *)head; bp = bp->hq.cqe_next)
|
TAILQ_FOREACH(bp, head, hq)
|
||||||
if (bp->pgno == pgno) {
|
if (bp->pgno == pgno) {
|
||||||
#ifdef STATISTICS
|
#ifdef STATISTICS
|
||||||
++mp->cachehit;
|
++mp->cachehit;
|
||||||
@ -446,8 +444,7 @@ mpool_stat(mp)
|
|||||||
|
|
||||||
sep = "";
|
sep = "";
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
for (bp = mp->lqh.cqh_first;
|
TAILQ_FOREACH(bp, &mp->lqh, q) {
|
||||||
bp != (void *)&mp->lqh; bp = bp->q.cqe_next) {
|
|
||||||
(void)fprintf(stderr, "%s%d", sep, bp->pgno);
|
(void)fprintf(stderr, "%s%d", sep, bp->pgno);
|
||||||
if (bp->flags & MPOOL_DIRTY)
|
if (bp->flags & MPOOL_DIRTY)
|
||||||
(void)fprintf(stderr, "d");
|
(void)fprintf(stderr, "d");
|
||||||
|
Loading…
Reference in New Issue
Block a user