source: rtems-libbsd/freebsd-userspace/include/mpool.h @ bf4a338

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since bf4a338 was e4e1746, checked in by Jennifer Averett <jennifer.averett@…>, on 09/12/12 at 15:59:41

Added userspace db files.

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*-
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
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *      This product includes software developed by the University of
16 *      California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
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.4 (Berkeley) 11/2/95
34 * $FreeBSD$
35 */
36
37#ifndef _MPOOL_H_
38#define _MPOOL_H_
39
40#include <sys/queue.h>
41
42/*
43 * The memory pool scheme is a simple one.  Each in-memory page is referenced
44 * by a bucket which is threaded in up to two of three ways.  All active pages
45 * are threaded on a hash chain (hashed by page number) and an lru chain.
46 * Inactive pages are threaded on a free chain.  Each reference to a memory
47 * pool is handed an opaque MPOOL cookie which stores all of this information.
48 */
49#define HASHSIZE        128
50#define HASHKEY(pgno)   ((pgno - 1 + HASHSIZE) % HASHSIZE)
51
52/* The BKT structures are the elements of the queues. */
53typedef struct _bkt {
54        TAILQ_ENTRY(_bkt) hq;           /* hash queue */
55        TAILQ_ENTRY(_bkt) q;            /* lru queue */
56        void    *page;                  /* page */
57        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 */
61#define MPOOL_INUSE     0x04            /* page address is valid */
62        u_int8_t flags;                 /* flags */
63} BKT;
64
65typedef struct MPOOL {
66        TAILQ_HEAD(_lqh, _bkt) lqh;     /* lru queue head */
67                                        /* hash queue array */
68        TAILQ_HEAD(_hqh, _bkt) hqh[HASHSIZE];
69        pgno_t  curcache;               /* current number of cached pages */
70        pgno_t  maxcache;               /* max number of cached pages */
71        pgno_t  npages;                 /* number of pages in the file */
72        unsigned long   pagesize;       /* file page size */
73        int     fd;                     /* file descriptor */
74                                        /* page in conversion routine */
75        void    (*pgin)(void *, pgno_t, void *);
76                                        /* page out conversion routine */
77        void    (*pgout)(void *, pgno_t, void *);
78        void    *pgcookie;              /* cookie for page in/out routines */
79#ifdef STATISTICS
80        unsigned long   cachehit;
81        unsigned long   cachemiss;
82        unsigned long   pagealloc;
83        unsigned long   pageflush;
84        unsigned long   pageget;
85        unsigned long   pagenew;
86        unsigned long   pageput;
87        unsigned long   pageread;
88        unsigned long   pagewrite;
89#endif
90} MPOOL;
91
92#define MPOOL_IGNOREPIN 0x01            /* Ignore if the page is pinned. */
93#define MPOOL_PAGE_REQUEST      0x01    /* Allocate a new page with a
94                                           specific page number. */
95#define MPOOL_PAGE_NEXT         0x02    /* Allocate a new page with the next
96                                          page number. */
97
98__BEGIN_DECLS
99MPOOL   *mpool_open(void *, int, pgno_t, pgno_t);
100void     mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *),
101            void (*)(void *, pgno_t, void *), void *);
102void    *mpool_new(MPOOL *, pgno_t *, unsigned int);
103void    *mpool_get(MPOOL *, pgno_t, unsigned int);
104int      mpool_delete(MPOOL *, void *);
105int      mpool_put(MPOOL *, void *, unsigned int);
106int      mpool_sync(MPOOL *);
107int      mpool_close(MPOOL *);
108#ifdef STATISTICS
109void     mpool_stat(MPOOL *);
110#endif
111__END_DECLS
112
113#endif
Note: See TracBrowser for help on using the repository browser.