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