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