Back to index

lightning-sunbird  0.9+nobinonly
mpool.h
Go to the documentation of this file.
00001 /*-
00002  * Copyright (c) 1991, 1993, 1994
00003  *     The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. ***REMOVED*** - see 
00014  *    ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
00015  * 4. Neither the name of the University nor the names of its contributors
00016  *    may be used to endorse or promote products derived from this software
00017  *    without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00020  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00023  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00024  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00025  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00026  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00027  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00028  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00029  * SUCH DAMAGE.
00030  *
00031  *     @(#)mpool.h   8.2 (Berkeley) 7/14/94
00032  */
00033 
00034 #include <sys/queue.h>
00035 
00036 /*
00037  * The memory pool scheme is a simple one.  Each in-memory page is referenced
00038  * by a bucket which is threaded in up to two of three ways.  All active pages
00039  * are threaded on a hash chain (hashed by page number) and an lru chain.
00040  * Inactive pages are threaded on a free chain.  Each reference to a memory
00041  * pool is handed an opaque MPOOL cookie which stores all of this information.
00042  */
00043 #define       HASHSIZE      128
00044 #define       HASHKEY(pgno) ((pgno - 1) % HASHSIZE)
00045 
00046 /* The BKT structures are the elements of the queues. */
00047 typedef struct _bkt {
00048        CIRCLEQ_ENTRY(_bkt) hq;            /* hash queue */
00049        CIRCLEQ_ENTRY(_bkt) q;             /* lru queue */
00050        void    *page;                     /* page */
00051        pgno_t   pgno;                     /* page number */
00052 
00053 #define       MPOOL_DIRTY   0x01          /* page needs to be written */
00054 #define       MPOOL_PINNED  0x02          /* page is pinned into memory */
00055        uint8 flags;                /* flags */
00056 } BKT;
00057 
00058 typedef struct MPOOL {
00059        CIRCLEQ_HEAD(_lqh, _bkt) lqh;      /* lru queue head */
00060                                    /* hash queue array */
00061        CIRCLEQ_HEAD(_hqh, _bkt) hqh[HASHSIZE];
00062        pgno_t curcache;            /* current number of cached pages */
00063        pgno_t maxcache;            /* max number of cached pages */
00064        pgno_t npages;                     /* number of pages in the file */
00065        uint32 pagesize;            /* file page size */
00066        int    fd;                  /* file descriptor */
00067                                    /* page in conversion routine */
00068        void    (*pgin) (void *, pgno_t, void *);
00069                                    /* page out conversion routine */
00070        void    (*pgout) (void *, pgno_t, void *);
00071        void   *pgcookie;           /* cookie for page in/out routines */
00072 #ifdef STATISTICS
00073        uint32 cachehit;
00074        uint32 cachemiss;
00075        uint32 pagealloc;
00076        uint32 pageflush;
00077        uint32 pageget;
00078        uint32 pagenew;
00079        uint32 pageput;
00080        uint32 pageread;
00081        uint32 pagewrite;
00082 #endif
00083 } MPOOL;
00084 
00085 __BEGIN_DECLS
00086 MPOOL  *mpool_open (void *, int, pgno_t, pgno_t);
00087 void    mpool_filter (MPOOL *, void (*)(void *, pgno_t, void *),
00088            void (*)(void *, pgno_t, void *), void *);
00089 void   *mpool_new (MPOOL *, pgno_t *);
00090 void   *mpool_get (MPOOL *, pgno_t, uint);
00091 int     mpool_put (MPOOL *, void *, uint);
00092 int     mpool_sync (MPOOL *);
00093 int     mpool_close (MPOOL *);
00094 #ifdef STATISTICS
00095 void    mpool_stat (MPOOL *);
00096 #endif
00097 __END_DECLS