Annotation of src/include/mpool.h, Revision 1.9
1.9 ! millert 1: /* $OpenBSD: mpool.h,v 1.8 2002/02/17 19:42:21 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.
1.9 ! millert 16: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 17: * may be used to endorse or promote products derived from this software
18: * without specific prior written permission.
19: *
20: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30: * SUCH DAMAGE.
31: *
1.5 millert 32: * @(#)mpool.h 8.4 (Berkeley) 11/2/95
1.1 deraadt 33: */
34:
1.3 millert 35: #ifndef _MPOOL_H_
36: #define _MPOOL_H_
37:
1.2 deraadt 38: #include <sys/queue.h>
39:
1.1 deraadt 40: /*
1.2 deraadt 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 deraadt 46: */
47: #define HASHSIZE 128
1.6 millert 48: #define HASHKEY(pgno) ((pgno - 1 + HASHSIZE) % HASHSIZE)
1.1 deraadt 49:
1.2 deraadt 50: /* The BKT structures are the elements of the queues. */
51: typedef struct _bkt {
52: CIRCLEQ_ENTRY(_bkt) hq; /* hash queue */
53: CIRCLEQ_ENTRY(_bkt) q; /* lru queue */
54: void *page; /* page */
55: pgno_t pgno; /* page number */
1.1 deraadt 56:
57: #define MPOOL_DIRTY 0x01 /* page needs to be written */
58: #define MPOOL_PINNED 0x02 /* page is pinned into memory */
1.5 millert 59: #define MPOOL_INUSE 0x04 /* page address is valid */
1.2 deraadt 60: u_int8_t flags; /* flags */
1.1 deraadt 61: } BKT;
62:
63: typedef struct MPOOL {
1.2 deraadt 64: CIRCLEQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */
65: /* hash queue array */
66: CIRCLEQ_HEAD(_hqh, _bkt) hqh[HASHSIZE];
67: pgno_t curcache; /* current number of cached pages */
68: pgno_t maxcache; /* max number of cached pages */
69: pgno_t npages; /* number of pages in the file */
70: u_long pagesize; /* file page size */
71: int fd; /* file descriptor */
72: /* page in conversion routine */
1.7 millert 73: void (*pgin)(void *, pgno_t, void *);
1.2 deraadt 74: /* page out conversion routine */
1.7 millert 75: void (*pgout)(void *, pgno_t, void *);
1.2 deraadt 76: void *pgcookie; /* cookie for page in/out routines */
1.1 deraadt 77: #ifdef STATISTICS
1.2 deraadt 78: u_long cachehit;
79: u_long cachemiss;
80: u_long pagealloc;
81: u_long pageflush;
82: u_long pageget;
83: u_long pagenew;
84: u_long pageput;
85: u_long pageread;
86: u_long pagewrite;
1.1 deraadt 87: #endif
88: } MPOOL;
89:
1.5 millert 90: #define MPOOL_IGNOREPIN 0x01 /* Ignore if the page is pinned. */
91: #define MPOOL_PAGE_REQUEST 0x01 /* Allocate a new page with a
92: specific page number. */
93: #define MPOOL_PAGE_NEXT 0x02 /* Allocate a new page with the next
94: page number. */
95:
1.1 deraadt 96: __BEGIN_DECLS
1.7 millert 97: MPOOL *mpool_open(void *, int, pgno_t, pgno_t);
1.8 millert 98: void mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *),
99: void (*)(void *, pgno_t, void *), void *);
1.7 millert 100: void *mpool_new(MPOOL *, pgno_t *, u_int);
101: void *mpool_get(MPOOL *, pgno_t, u_int);
102: int mpool_delete(MPOOL *, void *);
103: int mpool_put(MPOOL *, void *, u_int);
104: int mpool_sync(MPOOL *);
105: int mpool_close(MPOOL *);
1.1 deraadt 106: #ifdef STATISTICS
1.7 millert 107: void mpool_stat(MPOOL *);
1.1 deraadt 108: #endif
109: __END_DECLS
1.3 millert 110:
111: #endif