Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
4.0 KiB

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