| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: mpool.h,v 1.14 2013/11/22 16:25:01 christos Exp $ */ | | 1 | /* $NetBSD: mpool.h,v 1.15 2016/09/24 20:11:43 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1991, 1993, 1994 | | 4 | * Copyright (c) 1991, 1993, 1994 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -46,26 +46,27 @@ | | | @@ -46,26 +46,27 @@ |
46 | */ | | 46 | */ |
47 | #define HASHSIZE 128 | | 47 | #define HASHSIZE 128 |
48 | #define HASHKEY(pgno) ((pgno - 1) % HASHSIZE) | | 48 | #define HASHKEY(pgno) ((pgno - 1) % HASHSIZE) |
49 | | | 49 | |
50 | /* The BKT structures are the elements of the queues. */ | | 50 | /* The BKT structures are the elements of the queues. */ |
51 | typedef struct _bkt { | | 51 | typedef struct _bkt { |
52 | TAILQ_ENTRY(_bkt) hq; /* hash queue */ | | 52 | TAILQ_ENTRY(_bkt) hq; /* hash queue */ |
53 | TAILQ_ENTRY(_bkt) q; /* lru queue */ | | 53 | TAILQ_ENTRY(_bkt) q; /* lru queue */ |
54 | void *page; /* page */ | | 54 | void *page; /* page */ |
55 | pgno_t pgno; /* page number */ | | 55 | pgno_t pgno; /* page number */ |
56 | | | 56 | |
57 | #define MPOOL_DIRTY 0x01 /* page needs to be written */ | | 57 | #define MPOOL_DIRTY 0x01 /* page needs to be written */ |
58 | #define MPOOL_PINNED 0x02 /* page is pinned into memory */ | | 58 | #define MPOOL_PINNED 0x02 /* page is pinned into memory */ |
| | | 59 | #define MPOOL_INUSE 0x04 /* page address is valid */ |
59 | uint8_t flags; /* flags */ | | 60 | uint8_t flags; /* flags */ |
60 | } BKT; | | 61 | } BKT; |
61 | | | 62 | |
62 | typedef struct MPOOL { | | 63 | typedef struct MPOOL { |
63 | TAILQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */ | | 64 | TAILQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */ |
64 | /* hash queue array */ | | 65 | /* hash queue array */ |
65 | TAILQ_HEAD(_hqh, _bkt) hqh[HASHSIZE]; | | 66 | TAILQ_HEAD(_hqh, _bkt) hqh[HASHSIZE]; |
66 | pgno_t curcache; /* current number of cached pages */ | | 67 | pgno_t curcache; /* current number of cached pages */ |
67 | pgno_t maxcache; /* max number of cached pages */ | | 68 | pgno_t maxcache; /* max number of cached pages */ |
68 | pgno_t npages; /* number of pages in the file */ | | 69 | pgno_t npages; /* number of pages in the file */ |
69 | unsigned long pagesize; /* file page size */ | | 70 | unsigned long pagesize; /* file page size */ |
70 | int fd; /* file descriptor */ | | 71 | int fd; /* file descriptor */ |
71 | /* page in conversion routine */ | | 72 | /* page in conversion routine */ |
| @@ -76,28 +77,39 @@ typedef struct MPOOL { | | | @@ -76,28 +77,39 @@ typedef struct MPOOL { |
76 | #ifdef STATISTICS | | 77 | #ifdef STATISTICS |
77 | unsigned long cachehit; | | 78 | unsigned long cachehit; |
78 | unsigned long cachemiss; | | 79 | unsigned long cachemiss; |
79 | unsigned long pagealloc; | | 80 | unsigned long pagealloc; |
80 | unsigned long pageflush; | | 81 | unsigned long pageflush; |
81 | unsigned long pageget; | | 82 | unsigned long pageget; |
82 | unsigned long pagenew; | | 83 | unsigned long pagenew; |
83 | unsigned long pageput; | | 84 | unsigned long pageput; |
84 | unsigned long pageread; | | 85 | unsigned long pageread; |
85 | unsigned long pagewrite; | | 86 | unsigned long pagewrite; |
86 | #endif | | 87 | #endif |
87 | } MPOOL; | | 88 | } MPOOL; |
88 | | | 89 | |
| | | 90 | /* flags for get/put */ |
| | | 91 | #define MPOOL_IGNOREPIN 0x01 /* Ignore if the page is pinned. */ |
| | | 92 | /* flags for newf */ |
| | | 93 | #define MPOOL_PAGE_REQUEST 0x01 /* Allocate a new page with a |
| | | 94 | specific page number. */ |
| | | 95 | #define MPOOL_PAGE_NEXT 0x02 /* Allocate a new page with the next |
| | | 96 | page number. */ |
| | | 97 | |
89 | __BEGIN_DECLS | | 98 | __BEGIN_DECLS |
90 | MPOOL *mpool_open(void *, int, pgno_t, pgno_t); | | 99 | MPOOL *mpool_open(void *, int, pgno_t, pgno_t); |
91 | void mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *), | | 100 | void mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *), |
92 | void (*)(void *, pgno_t, void *), void *); | | 101 | void (*)(void *, pgno_t, void *), void *); |
93 | void *mpool_new(MPOOL *, pgno_t *); | | 102 | void *mpool_new(MPOOL *, pgno_t *); |
94 | void *mpool_get(MPOOL *, pgno_t, unsigned int); | | 103 | void *mpool_newf(MPOOL *, pgno_t *, unsigned int); |
| | | 104 | int mpool_delete(MPOOL *, void *); |
| | | 105 | void *mpool_get(MPOOL *, pgno_t); |
| | | 106 | void *mpool_getf(MPOOL *, pgno_t, unsigned int); |
95 | int mpool_put(MPOOL *, void *, unsigned int); | | 107 | int mpool_put(MPOOL *, void *, unsigned int); |
96 | int mpool_sync(MPOOL *); | | 108 | int mpool_sync(MPOOL *); |
97 | int mpool_close(MPOOL *); | | 109 | int mpool_close(MPOOL *); |
98 | #ifdef STATISTICS | | 110 | #ifdef STATISTICS |
99 | void mpool_stat(MPOOL *); | | 111 | void mpool_stat(MPOOL *); |
100 | #endif | | 112 | #endif |
101 | __END_DECLS | | 113 | __END_DECLS |
102 | | | 114 | |
103 | #endif /* _MPOOL_H_ */ | | 115 | #endif /* _MPOOL_H_ */ |