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.

111 lines
4.2 KiB

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