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