Path: blob/main/crypto/krb5/src/plugins/kdb/db2/libdb2/mpool/mpool.h
34927 views
/*-1* Copyright (c) 1991, 1993, 19942* The Regents of the University of California. All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. All advertising materials mentioning features or use of this software13* must display the following acknowledgement:14* This product includes software developed by the University of15* California, Berkeley and its contributors.16* 4. Neither the name of the University nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*32* @(#)mpool.h 8.4 (Berkeley) 11/2/9533*/3435#include "db-queue.h"3637/*38* The memory pool scheme is a simple one. Each in-memory page is referenced39* by a bucket which is threaded in up to two of three ways. All active pages40* are threaded on a hash chain (hashed by page number) and an lru chain.41* Inactive pages are threaded on a free chain. Each reference to a memory42* pool is handed an opaque MPOOL cookie which stores all of this information.43*/44#define HASHSIZE 12845#define HASHKEY(pgno) ((pgno - 1) % HASHSIZE)4647/* The BKT structures are the elements of the queues. */48typedef struct _bkt {49TAILQ_ENTRY(_bkt) hq; /* hash queue */50TAILQ_ENTRY(_bkt) q; /* lru queue */51void *page; /* page */52db_pgno_t pgno; /* page number */5354#define MPOOL_DIRTY 0x01 /* page needs to be written */55#define MPOOL_PINNED 0x02 /* page is pinned into memory */56#define MPOOL_INUSE 0x04 /* page address is valid */57u_int8_t flags; /* flags */58} BKT;5960typedef struct MPOOL {61TAILQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */62/* hash queue array */63TAILQ_HEAD(_hqh, _bkt) hqh[HASHSIZE];64db_pgno_t curcache; /* current number of cached pages */65db_pgno_t maxcache; /* max number of cached pages */66db_pgno_t npages; /* number of pages in the file */67u_long pagesize; /* file page size */68int fd; /* file descriptor */69/* page in conversion routine */70void (*pgin) __P((void *, db_pgno_t, void *));71/* page out conversion routine */72void (*pgout) __P((void *, db_pgno_t, void *));73void *pgcookie; /* cookie for page in/out routines */74#ifdef STATISTICS75u_long cachehit;76u_long cachemiss;77u_long pagealloc;78u_long pageflush;79u_long pageget;80u_long pagenew;81u_long pageput;82u_long pageread;83u_long pagewrite;84#endif85} MPOOL;8687#define MPOOL_IGNOREPIN 0x01 /* Ignore if the page is pinned. */88#define MPOOL_PAGE_REQUEST 0x01 /* Allocate a new page with a89specific page number. */90#define MPOOL_PAGE_NEXT 0x02 /* Allocate a new page with the next91page number. */9293#define mpool_open kdb2_mpool_open94#define mpool_filter kdb2_mpool_filter95#define mpool_new kdb2_mpool_new96#define mpool_get kdb2_mpool_get97#define mpool_delete kdb2_mpool_delete98#define mpool_put kdb2_mpool_put99#define mpool_sync kdb2_mpool_sync100#define mpool_close kdb2_mpool_close101#define mpool_stat kdb2_mpool_stat102103__BEGIN_DECLS104MPOOL *mpool_open __P((void *, int, db_pgno_t, db_pgno_t));105void mpool_filter __P((MPOOL *, void (*)(void *, db_pgno_t, void *),106void (*)(void *, db_pgno_t, void *), void *));107void *mpool_new __P((MPOOL *, db_pgno_t *, u_int));108void *mpool_get __P((MPOOL *, db_pgno_t, u_int));109int mpool_delete __P((MPOOL *, void *));110int mpool_put __P((MPOOL *, void *, u_int));111int mpool_sync __P((MPOOL *));112int mpool_close __P((MPOOL *));113114void mpool_stat __P((MPOOL *));115116__END_DECLS117118119