[BACK]Return to mpool.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / include

Annotation of src/include/mpool.h, Revision 1.13.2.1

1.13.2.1! yamt        1: /*     $NetBSD: mpool.h,v 1.13 2008/08/26 21:18:38 joerg Exp $ */
1.6       cgd         2:
1.1       proven      3: /*-
1.7       cgd         4:  * Copyright (c) 1991, 1993, 1994
1.3       cgd         5:  *     The Regents of the University of California.  All rights reserved.
1.1       proven      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
1.10      agc        15:  * 3. Neither the name of the University nor the names of its contributors
1.1       proven     16:  *    may be used to endorse or promote products derived from this software
                     17:  *    without specific prior written permission.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     20:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     21:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     22:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     23:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     24:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     25:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     27:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     29:  * SUCH DAMAGE.
                     30:  *
1.7       cgd        31:  *     @(#)mpool.h     8.2 (Berkeley) 7/14/94
1.1       proven     32:  */
                     33:
1.8       perry      34: #ifndef _MPOOL_H_
                     35: #define _MPOOL_H_
                     36:
1.9       ad         37: #include <sys/cdefs.h>
1.7       cgd        38: #include <sys/queue.h>
                     39:
1.1       proven     40: /*
1.7       cgd        41:  * The memory pool scheme is a simple one.  Each in-memory page is referenced
                     42:  * by a bucket which is threaded in up to two of three ways.  All active pages
                     43:  * are threaded on a hash chain (hashed by page number) and an lru chain.
                     44:  * Inactive pages are threaded on a free chain.  Each reference to a memory
                     45:  * pool is handed an opaque MPOOL cookie which stores all of this information.
1.1       proven     46:  */
                     47: #define        HASHSIZE        128
                     48: #define        HASHKEY(pgno)   ((pgno - 1) % HASHSIZE)
                     49:
1.7       cgd        50: /* The BKT structures are the elements of the queues. */
                     51: typedef struct _bkt {
1.13.2.1! yamt       52:        TAILQ_ENTRY(_bkt) hq;           /* hash queue */
        !            53:        TAILQ_ENTRY(_bkt) q;            /* lru queue */
1.7       cgd        54:        void    *page;                  /* page */
                     55:        pgno_t   pgno;                  /* page number */
1.1       proven     56:
                     57: #define        MPOOL_DIRTY     0x01            /* page needs to be written */
                     58: #define        MPOOL_PINNED    0x02            /* page is pinned into memory */
1.12      perry      59:        uint8_t flags;                  /* flags */
1.1       proven     60: } BKT;
                     61:
                     62: typedef struct MPOOL {
1.13.2.1! yamt       63:        TAILQ_HEAD(_lqh, _bkt) lqh;     /* lru queue head */
1.7       cgd        64:                                        /* hash queue array */
1.13.2.1! yamt       65:        TAILQ_HEAD(_hqh, _bkt) hqh[HASHSIZE];
1.7       cgd        66:        pgno_t  curcache;               /* current number of cached pages */
                     67:        pgno_t  maxcache;               /* max number of cached pages */
                     68:        pgno_t  npages;                 /* number of pages in the file */
1.13      joerg      69:        unsigned long   pagesize;               /* file page size */
1.7       cgd        70:        int     fd;                     /* file descriptor */
                     71:                                        /* page in conversion routine */
1.11      perry      72:        void    (*pgin)(void *, pgno_t, void *);
1.7       cgd        73:                                        /* page out conversion routine */
1.11      perry      74:        void    (*pgout)(void *, pgno_t, void *);
1.7       cgd        75:        void    *pgcookie;              /* cookie for page in/out routines */
1.1       proven     76: #ifdef STATISTICS
1.13      joerg      77:        unsigned long   cachehit;
                     78:        unsigned long   cachemiss;
                     79:        unsigned long   pagealloc;
                     80:        unsigned long   pageflush;
                     81:        unsigned long   pageget;
                     82:        unsigned long   pagenew;
                     83:        unsigned long   pageput;
                     84:        unsigned long   pageread;
                     85:        unsigned long   pagewrite;
1.1       proven     86: #endif
                     87: } MPOOL;
                     88:
                     89: __BEGIN_DECLS
1.11      perry      90: MPOOL  *mpool_open(void *, int, pgno_t, pgno_t);
                     91: void    mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *),
                     92:            void (*)(void *, pgno_t, void *), void *);
                     93: void   *mpool_new(MPOOL *, pgno_t *);
1.13      joerg      94: void   *mpool_get(MPOOL *, pgno_t, unsigned int);
                     95: int     mpool_put(MPOOL *, void *, unsigned int);
1.11      perry      96: int     mpool_sync(MPOOL *);
                     97: int     mpool_close(MPOOL *);
1.1       proven     98: #ifdef STATISTICS
1.11      perry      99: void    mpool_stat(MPOOL *);
1.1       proven    100: #endif
                    101: __END_DECLS
1.8       perry     102:
                    103: #endif /* _MPOOL_H_ */

CVSweb <webmaster@jp.NetBSD.org>