Annotation of kernel/bsd/include/mpool.h, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: /*-
        !            26:  * Copyright (c) 1991, 1993
        !            27:  *     The Regents of the University of California.  All rights reserved.
        !            28:  *
        !            29:  * Redistribution and use in source and binary forms, with or without
        !            30:  * modification, are permitted provided that the following conditions
        !            31:  * are met:
        !            32:  * 1. Redistributions of source code must retain the above copyright
        !            33:  *    notice, this list of conditions and the following disclaimer.
        !            34:  * 2. Redistributions in binary form must reproduce the above copyright
        !            35:  *    notice, this list of conditions and the following disclaimer in the
        !            36:  *    documentation and/or other materials provided with the distribution.
        !            37:  * 3. All advertising materials mentioning features or use of this software
        !            38:  *    must display the following acknowledgement:
        !            39:  *     This product includes software developed by the University of
        !            40:  *     California, Berkeley and its contributors.
        !            41:  * 4. Neither the name of the University nor the names of its contributors
        !            42:  *    may be used to endorse or promote products derived from this software
        !            43:  *    without specific prior written permission.
        !            44:  *
        !            45:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            46:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            47:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            48:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            49:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            50:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            51:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            52:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            53:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            54:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            55:  * SUCH DAMAGE.
        !            56:  *
        !            57:  *     @(#)mpool.h     8.1 (Berkeley) 6/2/93
        !            58:  */
        !            59: 
        !            60: /*
        !            61:  * The memory pool scheme is a simple one.  Each in memory page is referenced
        !            62:  * by a bucket which is threaded in three ways.  All active pages are threaded
        !            63:  * on a hash chain (hashed by the page number) and an lru chain.  Inactive
        !            64:  * pages are threaded on a free chain.  Each reference to a memory pool is
        !            65:  * handed an MPOOL which is the opaque cookie passed to all of the memory
        !            66:  * routines.
        !            67:  */
        !            68: #define        HASHSIZE        128
        !            69: #define        HASHKEY(pgno)   ((pgno - 1) % HASHSIZE)
        !            70: 
        !            71: /* The BKT structures are the elements of the lists. */
        !            72: typedef struct BKT {
        !            73:        struct BKT      *hnext;         /* next hash bucket */
        !            74:        struct BKT      *hprev;         /* previous hash bucket */
        !            75:        struct BKT      *cnext;         /* next free/lru bucket */
        !            76:        struct BKT      *cprev;         /* previous free/lru bucket */
        !            77:        void            *page;          /* page */
        !            78:        pgno_t          pgno;           /* page number */
        !            79: 
        !            80: #define        MPOOL_DIRTY     0x01            /* page needs to be written */
        !            81: #define        MPOOL_PINNED    0x02            /* page is pinned into memory */
        !            82:        unsigned long   flags;          /* flags */
        !            83: } BKT;
        !            84: 
        !            85: /* The BKTHDR structures are the heads of the lists. */
        !            86: typedef struct BKTHDR {
        !            87:        struct BKT      *hnext;         /* next hash bucket */
        !            88:        struct BKT      *hprev;         /* previous hash bucket */
        !            89:        struct BKT      *cnext;         /* next free/lru bucket */
        !            90:        struct BKT      *cprev;         /* previous free/lru bucket */
        !            91: } BKTHDR;
        !            92: 
        !            93: typedef struct MPOOL {
        !            94:        BKTHDR  free;                   /* The free list. */
        !            95:        BKTHDR  lru;                    /* The LRU list. */
        !            96:        BKTHDR  hashtable[HASHSIZE];    /* Hashed list by page number. */
        !            97:        pgno_t  curcache;               /* Current number of cached pages. */
        !            98:        pgno_t  maxcache;               /* Max number of cached pages. */
        !            99:        pgno_t  npages;                 /* Number of pages in the file. */
        !           100:        u_long  pagesize;               /* File page size. */
        !           101:        int     fd;                     /* File descriptor. */
        !           102:                                        /* Page in conversion routine. */
        !           103:        void    (*pgin) __P((void *, pgno_t, void *));
        !           104:                                        /* Page out conversion routine. */
        !           105:        void    (*pgout) __P((void *, pgno_t, void *));
        !           106:        void    *pgcookie;              /* Cookie for page in/out routines. */
        !           107: #ifdef STATISTICS
        !           108:        unsigned long   cachehit;
        !           109:        unsigned long   cachemiss;
        !           110:        unsigned long   pagealloc;
        !           111:        unsigned long   pageflush;
        !           112:        unsigned long   pageget;
        !           113:        unsigned long   pagenew;
        !           114:        unsigned long   pageput;
        !           115:        unsigned long   pageread;
        !           116:        unsigned long   pagewrite;
        !           117: #endif
        !           118: } MPOOL;
        !           119: 
        !           120: #ifdef __MPOOLINTERFACE_PRIVATE
        !           121: /* Macros to insert/delete into/from hash chain. */
        !           122: #define rmhash(bp) { \
        !           123:         (bp)->hprev->hnext = (bp)->hnext; \
        !           124:         (bp)->hnext->hprev = (bp)->hprev; \
        !           125: }
        !           126: #define inshash(bp, pg) { \
        !           127:        hp = &mp->hashtable[HASHKEY(pg)]; \
        !           128:         (bp)->hnext = hp->hnext; \
        !           129:         (bp)->hprev = (struct BKT *)hp; \
        !           130:         hp->hnext->hprev = (bp); \
        !           131:         hp->hnext = (bp); \
        !           132: }
        !           133: 
        !           134: /* Macros to insert/delete into/from lru and free chains. */
        !           135: #define        rmchain(bp) { \
        !           136:         (bp)->cprev->cnext = (bp)->cnext; \
        !           137:         (bp)->cnext->cprev = (bp)->cprev; \
        !           138: }
        !           139: #define inschain(bp, dp) { \
        !           140:         (bp)->cnext = (dp)->cnext; \
        !           141:         (bp)->cprev = (struct BKT *)(dp); \
        !           142:         (dp)->cnext->cprev = (bp); \
        !           143:         (dp)->cnext = (bp); \
        !           144: }
        !           145: #endif
        !           146: 
        !           147: __BEGIN_DECLS
        !           148: MPOOL  *mpool_open __P((DBT *, int, pgno_t, pgno_t));
        !           149: void    mpool_filter __P((MPOOL *, void (*)(void *, pgno_t, void *),
        !           150:            void (*)(void *, pgno_t, void *), void *));
        !           151: void   *mpool_new __P((MPOOL *, pgno_t *));
        !           152: void   *mpool_get __P((MPOOL *, pgno_t, u_int));
        !           153: int     mpool_put __P((MPOOL *, void *, u_int));
        !           154: int     mpool_sync __P((MPOOL *));
        !           155: int     mpool_close __P((MPOOL *));
        !           156: #ifdef STATISTICS
        !           157: void    mpool_stat __P((MPOOL *));
        !           158: #endif
        !           159: __END_DECLS

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.