Deleted Added
full compact
mpool.h (2162) mpool.h (14288)
1/*-
1/*-
2 * Copyright (c) 1991, 1993
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 14 unchanged lines hidden (view full) ---

25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 14 unchanged lines hidden (view full) ---

25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)mpool.h 8.1 (Berkeley) 6/2/93
33 * @(#)mpool.h 8.2 (Berkeley) 7/14/94
34 */
35
36#ifndef _MPOOL_H_
37#define _MPOOL_H_
38
34 */
35
36#ifndef _MPOOL_H_
37#define _MPOOL_H_
38
39#include <sys/queue.h>
40
39/*
41/*
40 * The memory pool scheme is a simple one. Each in memory page is referenced
41 * by a bucket which is threaded in three ways. All active pages are threaded
42 * on a hash chain (hashed by the page number) and an lru chain. Inactive
43 * pages are threaded on a free chain. Each reference to a memory pool is
44 * handed an MPOOL which is the opaque cookie passed to all of the memory
45 * routines.
42 * The memory pool scheme is a simple one. Each in-memory page is referenced
43 * by a bucket which is threaded in up to two of three ways. All active pages
44 * are threaded on a hash chain (hashed by page number) and an lru chain.
45 * Inactive pages are threaded on a free chain. Each reference to a memory
46 * pool is handed an opaque MPOOL cookie which stores all of this information.
46 */
47#define HASHSIZE 128
48#define HASHKEY(pgno) ((pgno - 1) % HASHSIZE)
49
47 */
48#define HASHSIZE 128
49#define HASHKEY(pgno) ((pgno - 1) % HASHSIZE)
50
50/* The BKT structures are the elements of the lists. */
51typedef struct BKT {
52 struct BKT *hnext; /* next hash bucket */
53 struct BKT *hprev; /* previous hash bucket */
54 struct BKT *cnext; /* next free/lru bucket */
55 struct BKT *cprev; /* previous free/lru bucket */
56 void *page; /* page */
57 pgno_t pgno; /* page number */
51/* The BKT structures are the elements of the queues. */
52typedef struct _bkt {
53 CIRCLEQ_ENTRY(_bkt) hq; /* hash queue */
54 CIRCLEQ_ENTRY(_bkt) q; /* lru queue */
55 void *page; /* page */
56 pgno_t pgno; /* page number */
58
59#define MPOOL_DIRTY 0x01 /* page needs to be written */
60#define MPOOL_PINNED 0x02 /* page is pinned into memory */
57
58#define MPOOL_DIRTY 0x01 /* page needs to be written */
59#define MPOOL_PINNED 0x02 /* page is pinned into memory */
61 unsigned long flags; /* flags */
60 u_int8_t flags; /* flags */
62} BKT;
63
61} BKT;
62
64/* The BKTHDR structures are the heads of the lists. */
65typedef struct BKTHDR {
66 struct BKT *hnext; /* next hash bucket */
67 struct BKT *hprev; /* previous hash bucket */
68 struct BKT *cnext; /* next free/lru bucket */
69 struct BKT *cprev; /* previous free/lru bucket */
70} BKTHDR;
71
72typedef struct MPOOL {
63typedef struct MPOOL {
73 BKTHDR free; /* The free list. */
74 BKTHDR lru; /* The LRU list. */
75 BKTHDR hashtable[HASHSIZE]; /* Hashed list by page number. */
76 pgno_t curcache; /* Current number of cached pages. */
77 pgno_t maxcache; /* Max number of cached pages. */
78 pgno_t npages; /* Number of pages in the file. */
79 u_long pagesize; /* File page size. */
80 int fd; /* File descriptor. */
81 /* Page in conversion routine. */
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 */
82 void (*pgin) __P((void *, pgno_t, void *));
73 void (*pgin) __P((void *, pgno_t, void *));
83 /* Page out conversion routine. */
74 /* page out conversion routine */
84 void (*pgout) __P((void *, pgno_t, void *));
75 void (*pgout) __P((void *, pgno_t, void *));
85 void *pgcookie; /* Cookie for page in/out routines. */
76 void *pgcookie; /* cookie for page in/out routines */
86#ifdef STATISTICS
77#ifdef STATISTICS
87 unsigned long cachehit;
88 unsigned long cachemiss;
89 unsigned long pagealloc;
90 unsigned long pageflush;
91 unsigned long pageget;
92 unsigned long pagenew;
93 unsigned long pageput;
94 unsigned long pageread;
95 unsigned long pagewrite;
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;
96#endif
97} MPOOL;
98
87#endif
88} MPOOL;
89
99#ifdef __MPOOLINTERFACE_PRIVATE
100/* Macros to insert/delete into/from hash chain. */
101#define rmhash(bp) { \
102 (bp)->hprev->hnext = (bp)->hnext; \
103 (bp)->hnext->hprev = (bp)->hprev; \
104}
105#define inshash(bp, pg) { \
106 hp = &mp->hashtable[HASHKEY(pg)]; \
107 (bp)->hnext = hp->hnext; \
108 (bp)->hprev = (struct BKT *)hp; \
109 hp->hnext->hprev = (bp); \
110 hp->hnext = (bp); \
111}
112
113/* Macros to insert/delete into/from lru and free chains. */
114#define rmchain(bp) { \
115 (bp)->cprev->cnext = (bp)->cnext; \
116 (bp)->cnext->cprev = (bp)->cprev; \
117}
118#define inschain(bp, dp) { \
119 (bp)->cnext = (dp)->cnext; \
120 (bp)->cprev = (struct BKT *)(dp); \
121 (dp)->cnext->cprev = (bp); \
122 (dp)->cnext = (bp); \
123}
124#endif
125
126__BEGIN_DECLS
90__BEGIN_DECLS
127MPOOL *mpool_open __P((DBT *, int, pgno_t, pgno_t));
91MPOOL *mpool_open __P((void *, int, pgno_t, pgno_t));
128void mpool_filter __P((MPOOL *, void (*)(void *, pgno_t, void *),
129 void (*)(void *, pgno_t, void *), void *));
130void *mpool_new __P((MPOOL *, pgno_t *));
131void *mpool_get __P((MPOOL *, pgno_t, u_int));
132int mpool_put __P((MPOOL *, void *, u_int));
133int mpool_sync __P((MPOOL *));
134int mpool_close __P((MPOOL *));
135#ifdef STATISTICS
136void mpool_stat __P((MPOOL *));
137#endif
138__END_DECLS
139
140#endif
92void mpool_filter __P((MPOOL *, void (*)(void *, pgno_t, void *),
93 void (*)(void *, pgno_t, void *), void *));
94void *mpool_new __P((MPOOL *, pgno_t *));
95void *mpool_get __P((MPOOL *, pgno_t, u_int));
96int mpool_put __P((MPOOL *, void *, u_int));
97int mpool_sync __P((MPOOL *));
98int mpool_close __P((MPOOL *));
99#ifdef STATISTICS
100void mpool_stat __P((MPOOL *));
101#endif
102__END_DECLS
103
104#endif