17c478bd9Sstevel@tonic-gate /* 256a424ccSmp * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 356a424ccSmp * Use is subject to license terms. 47c478bd9Sstevel@tonic-gate */ 57c478bd9Sstevel@tonic-gate 67c478bd9Sstevel@tonic-gate #ifndef _KRB5_DB2_MPOOL_MPOOL_H 77c478bd9Sstevel@tonic-gate #define _KRB5_DB2_MPOOL_MPOOL_H 87c478bd9Sstevel@tonic-gate 97c478bd9Sstevel@tonic-gate #ifdef __cplusplus 107c478bd9Sstevel@tonic-gate extern "C" { 117c478bd9Sstevel@tonic-gate #endif 127c478bd9Sstevel@tonic-gate 137c478bd9Sstevel@tonic-gate /* 147c478bd9Sstevel@tonic-gate * Copyright (c) 1991, 1993, 1994 157c478bd9Sstevel@tonic-gate * The Regents of the University of California. All rights reserved. 167c478bd9Sstevel@tonic-gate * 177c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 187c478bd9Sstevel@tonic-gate * modification, are permitted provided that the following conditions 197c478bd9Sstevel@tonic-gate * are met: 207c478bd9Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 217c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 227c478bd9Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 237c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 247c478bd9Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 257c478bd9Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software 267c478bd9Sstevel@tonic-gate * must display the following acknowledgement: 277c478bd9Sstevel@tonic-gate * This product includes software developed by the University of 287c478bd9Sstevel@tonic-gate * California, Berkeley and its contributors. 297c478bd9Sstevel@tonic-gate * 4. Neither the name of the University nor the names of its contributors 307c478bd9Sstevel@tonic-gate * may be used to endorse or promote products derived from this software 317c478bd9Sstevel@tonic-gate * without specific prior written permission. 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 347c478bd9Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 357c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 367c478bd9Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 377c478bd9Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 387c478bd9Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 397c478bd9Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 407c478bd9Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 417c478bd9Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 427c478bd9Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 437c478bd9Sstevel@tonic-gate * SUCH DAMAGE. 447c478bd9Sstevel@tonic-gate * 457c478bd9Sstevel@tonic-gate * @(#)mpool.h 8.4 (Berkeley) 11/2/95 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #include "db-queue.h" 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * The memory pool scheme is a simple one. Each in-memory page is referenced 527c478bd9Sstevel@tonic-gate * by a bucket which is threaded in up to two of three ways. All active pages 537c478bd9Sstevel@tonic-gate * are threaded on a hash chain (hashed by page number) and an lru chain. 547c478bd9Sstevel@tonic-gate * Inactive pages are threaded on a free chain. Each reference to a memory 557c478bd9Sstevel@tonic-gate * pool is handed an opaque MPOOL cookie which stores all of this information. 567c478bd9Sstevel@tonic-gate */ 577c478bd9Sstevel@tonic-gate #define HASHSIZE 128 587c478bd9Sstevel@tonic-gate #define HASHKEY(pgno) ((pgno - 1) % HASHSIZE) 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* The BKT structures are the elements of the queues. */ 617c478bd9Sstevel@tonic-gate typedef struct _bkt { 627c478bd9Sstevel@tonic-gate CIRCLEQ_ENTRY(_bkt) hq; /* hash queue */ 637c478bd9Sstevel@tonic-gate CIRCLEQ_ENTRY(_bkt) q; /* lru queue */ 647c478bd9Sstevel@tonic-gate void *page; /* page */ 657c478bd9Sstevel@tonic-gate db_pgno_t pgno; /* page number */ 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate #define MPOOL_DIRTY 0x01 /* page needs to be written */ 687c478bd9Sstevel@tonic-gate #define MPOOL_PINNED 0x02 /* page is pinned into memory */ 697c478bd9Sstevel@tonic-gate #define MPOOL_INUSE 0x04 /* page address is valid */ 707c478bd9Sstevel@tonic-gate u_int8_t flags; /* flags */ 717c478bd9Sstevel@tonic-gate } BKT; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate typedef struct MPOOL { 747c478bd9Sstevel@tonic-gate CIRCLEQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */ 757c478bd9Sstevel@tonic-gate /* hash queue array */ 767c478bd9Sstevel@tonic-gate CIRCLEQ_HEAD(_hqh, _bkt) hqh[HASHSIZE]; 777c478bd9Sstevel@tonic-gate db_pgno_t curcache; /* current number of cached pages */ 787c478bd9Sstevel@tonic-gate db_pgno_t maxcache; /* max number of cached pages */ 797c478bd9Sstevel@tonic-gate db_pgno_t npages; /* number of pages in the file */ 807c478bd9Sstevel@tonic-gate u_long pagesize; /* file page size */ 817c478bd9Sstevel@tonic-gate int fd; /* file descriptor */ 827c478bd9Sstevel@tonic-gate /* page in conversion routine */ 837c478bd9Sstevel@tonic-gate void (*pgin) __P((void *, db_pgno_t, void *)); 847c478bd9Sstevel@tonic-gate /* page out conversion routine */ 857c478bd9Sstevel@tonic-gate void (*pgout) __P((void *, db_pgno_t, void *)); 867c478bd9Sstevel@tonic-gate void *pgcookie; /* cookie for page in/out routines */ 877c478bd9Sstevel@tonic-gate #ifdef STATISTICS 887c478bd9Sstevel@tonic-gate u_long cachehit; 897c478bd9Sstevel@tonic-gate u_long cachemiss; 907c478bd9Sstevel@tonic-gate u_long pagealloc; 917c478bd9Sstevel@tonic-gate u_long pageflush; 927c478bd9Sstevel@tonic-gate u_long pageget; 937c478bd9Sstevel@tonic-gate u_long pagenew; 947c478bd9Sstevel@tonic-gate u_long pageput; 957c478bd9Sstevel@tonic-gate u_long pageread; 967c478bd9Sstevel@tonic-gate u_long pagewrite; 977c478bd9Sstevel@tonic-gate #endif 987c478bd9Sstevel@tonic-gate } MPOOL; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate #define MPOOL_IGNOREPIN 0x01 /* Ignore if the page is pinned. */ 1017c478bd9Sstevel@tonic-gate #define MPOOL_PAGE_REQUEST 0x01 /* Allocate a new page with a 1027c478bd9Sstevel@tonic-gate specific page number. */ 1037c478bd9Sstevel@tonic-gate #define MPOOL_PAGE_NEXT 0x02 /* Allocate a new page with the next 1047c478bd9Sstevel@tonic-gate page number. */ 1057c478bd9Sstevel@tonic-gate 10656a424ccSmp #define mpool_open kdb2_mpool_open 10756a424ccSmp #define mpool_filter kdb2_mpool_filter 10856a424ccSmp #define mpool_new kdb2_mpool_new 10956a424ccSmp #define mpool_get kdb2_mpool_get 11056a424ccSmp #define mpool_delete kdb2_mpool_delete 11156a424ccSmp #define mpool_put kdb2_mpool_put 11256a424ccSmp #define mpool_sync kdb2_mpool_sync 11356a424ccSmp #define mpool_close kdb2_mpool_close 11456a424ccSmp #define mpool_stat kdb2_mpool_stat 11556a424ccSmp 1167c478bd9Sstevel@tonic-gate __BEGIN_DECLS 1177c478bd9Sstevel@tonic-gate MPOOL *mpool_open __P((void *, int, db_pgno_t, db_pgno_t)); 1187c478bd9Sstevel@tonic-gate void mpool_filter __P((MPOOL *, void (*)(void *, db_pgno_t, void *), 1197c478bd9Sstevel@tonic-gate void (*)(void *, db_pgno_t, void *), void *)); 1207c478bd9Sstevel@tonic-gate void *mpool_new __P((MPOOL *, db_pgno_t *, u_int)); 1217c478bd9Sstevel@tonic-gate void *mpool_get __P((MPOOL *, db_pgno_t, u_int)); 1227c478bd9Sstevel@tonic-gate int mpool_delete __P((MPOOL *, void *)); 1237c478bd9Sstevel@tonic-gate int mpool_put __P((MPOOL *, void *, u_int)); 1247c478bd9Sstevel@tonic-gate int mpool_sync __P((MPOOL *)); 1257c478bd9Sstevel@tonic-gate int mpool_close __P((MPOOL *)); 1267c478bd9Sstevel@tonic-gate #ifdef STATISTICS 1277c478bd9Sstevel@tonic-gate void mpool_stat __P((MPOOL *)); 1287c478bd9Sstevel@tonic-gate #endif 1297c478bd9Sstevel@tonic-gate __END_DECLS 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1327c478bd9Sstevel@tonic-gate } 1337c478bd9Sstevel@tonic-gate #endif 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate #endif /* !_KRB5_DB2_MPOOL_MPOOL_H */ 136