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