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