mpool.h 4.3 KB

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