Print this page
3752 want more verifiable dbuf user eviction
Submitted by: Justin Gibbs <justing@spectralogic.com>
Submitted by: Will Andrews <willa@spectralogic.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/sys/zap_leaf.h
+++ new/usr/src/uts/common/fs/zfs/sys/zap_leaf.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 25 #ifndef _SYS_ZAP_LEAF_H
26 26 #define _SYS_ZAP_LEAF_H
27 27
28 28 #include <sys/zap.h>
29 29
30 30 #ifdef __cplusplus
31 31 extern "C" {
32 32 #endif
33 33
34 34 struct zap;
35 35 struct zap_name;
36 36 struct zap_stats;
37 37
38 38 #define ZAP_LEAF_MAGIC 0x2AB1EAF
39 39
40 40 /* chunk size = 24 bytes */
41 41 #define ZAP_LEAF_CHUNKSIZE 24
42 42
43 43 /*
44 44 * The amount of space available for chunks is:
45 45 * block size (1<<l->l_bs) - hash entry size (2) * number of hash
46 46 * entries - header space (2*chunksize)
47 47 */
48 48 #define ZAP_LEAF_NUMCHUNKS(l) \
49 49 (((1<<(l)->l_bs) - 2*ZAP_LEAF_HASH_NUMENTRIES(l)) / \
50 50 ZAP_LEAF_CHUNKSIZE - 2)
51 51
52 52 /*
53 53 * The amount of space within the chunk available for the array is:
54 54 * chunk size - space for type (1) - space for next pointer (2)
55 55 */
56 56 #define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3)
57 57
58 58 #define ZAP_LEAF_ARRAY_NCHUNKS(bytes) \
59 59 (((bytes)+ZAP_LEAF_ARRAY_BYTES-1)/ZAP_LEAF_ARRAY_BYTES)
60 60
61 61 /*
62 62 * Low water mark: when there are only this many chunks free, start
63 63 * growing the ptrtbl. Ideally, this should be larger than a
64 64 * "reasonably-sized" entry. 20 chunks is more than enough for the
65 65 * largest directory entry (MAXNAMELEN (256) byte name, 8-byte value),
66 66 * while still being only around 3% for 16k blocks.
67 67 */
68 68 #define ZAP_LEAF_LOW_WATER (20)
69 69
70 70 /*
71 71 * The leaf hash table has block size / 2^5 (32) number of entries,
72 72 * which should be more than enough for the maximum number of entries,
73 73 * which is less than block size / CHUNKSIZE (24) / minimum number of
74 74 * chunks per entry (3).
75 75 */
76 76 #define ZAP_LEAF_HASH_SHIFT(l) ((l)->l_bs - 5)
77 77 #define ZAP_LEAF_HASH_NUMENTRIES(l) (1 << ZAP_LEAF_HASH_SHIFT(l))
78 78
79 79 /*
80 80 * The chunks start immediately after the hash table. The end of the
81 81 * hash table is at l_hash + HASH_NUMENTRIES, which we simply cast to a
82 82 * chunk_t.
83 83 */
84 84 #define ZAP_LEAF_CHUNK(l, idx) \
85 85 ((zap_leaf_chunk_t *) \
86 86 ((l)->l_phys->l_hash + ZAP_LEAF_HASH_NUMENTRIES(l)))[idx]
87 87 #define ZAP_LEAF_ENTRY(l, idx) (&ZAP_LEAF_CHUNK(l, idx).l_entry)
88 88
89 89 typedef enum zap_chunk_type {
90 90 ZAP_CHUNK_FREE = 253,
91 91 ZAP_CHUNK_ENTRY = 252,
92 92 ZAP_CHUNK_ARRAY = 251,
93 93 ZAP_CHUNK_TYPE_MAX = 250
94 94 } zap_chunk_type_t;
95 95
96 96 #define ZLF_ENTRIES_CDSORTED (1<<0)
97 97
98 98 /*
99 99 * TAKE NOTE:
100 100 * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified.
101 101 */
102 102 typedef struct zap_leaf_phys {
103 103 struct zap_leaf_header {
104 104 uint64_t lh_block_type; /* ZBT_LEAF */
105 105 uint64_t lh_pad1;
106 106 uint64_t lh_prefix; /* hash prefix of this leaf */
107 107 uint32_t lh_magic; /* ZAP_LEAF_MAGIC */
108 108 uint16_t lh_nfree; /* number free chunks */
109 109 uint16_t lh_nentries; /* number of entries */
110 110 uint16_t lh_prefix_len; /* num bits used to id this */
111 111
112 112 /* above is accessable to zap, below is zap_leaf private */
113 113
114 114 uint16_t lh_freelist; /* chunk head of free list */
115 115 uint8_t lh_flags; /* ZLF_* flags */
116 116 uint8_t lh_pad2[11];
117 117 } l_hdr; /* 2 24-byte chunks */
118 118
119 119 /*
↓ open down ↓ |
119 lines elided |
↑ open up ↑ |
120 120 * The header is followed by a hash table with
121 121 * ZAP_LEAF_HASH_NUMENTRIES(zap) entries. The hash table is
122 122 * followed by an array of ZAP_LEAF_NUMCHUNKS(zap)
123 123 * zap_leaf_chunk structures. These structures are accessed
124 124 * with the ZAP_LEAF_CHUNK() macro.
125 125 */
126 126
127 127 uint16_t l_hash[1];
128 128 } zap_leaf_phys_t;
129 129
130 +typedef struct zap_leaf_dbuf {
131 + uint8_t zldb_pad[offsetof(dmu_buf_t, db_data)];
132 + zap_leaf_phys_t *zldb_data;
133 +} zap_leaf_dbuf_t;
134 +
130 135 typedef union zap_leaf_chunk {
131 136 struct zap_leaf_entry {
132 137 uint8_t le_type; /* always ZAP_CHUNK_ENTRY */
133 138 uint8_t le_value_intlen; /* size of value's ints */
134 139 uint16_t le_next; /* next entry in hash chain */
135 140 uint16_t le_name_chunk; /* first chunk of the name */
136 141 uint16_t le_name_numints; /* ints in name (incl null) */
137 142 uint16_t le_value_chunk; /* first chunk of the value */
138 143 uint16_t le_value_numints; /* value length in ints */
139 144 uint32_t le_cd; /* collision differentiator */
140 145 uint64_t le_hash; /* hash value of the name */
141 146 } l_entry;
142 147 struct zap_leaf_array {
143 148 uint8_t la_type; /* always ZAP_CHUNK_ARRAY */
144 149 uint8_t la_array[ZAP_LEAF_ARRAY_BYTES];
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
145 150 uint16_t la_next; /* next blk or CHAIN_END */
146 151 } l_array;
147 152 struct zap_leaf_free {
148 153 uint8_t lf_type; /* always ZAP_CHUNK_FREE */
149 154 uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES];
150 155 uint16_t lf_next; /* next in free list, or CHAIN_END */
151 156 } l_free;
152 157 } zap_leaf_chunk_t;
153 158
154 159 typedef struct zap_leaf {
160 + dmu_buf_user_t db_evict;
155 161 krwlock_t l_rwlock;
156 162 uint64_t l_blkid; /* 1<<ZAP_BLOCK_SHIFT byte block off */
157 163 int l_bs; /* block size shift */
158 - dmu_buf_t *l_dbuf;
159 - zap_leaf_phys_t *l_phys;
164 + union {
165 + dmu_buf_t *l_dmu_db;
166 + zap_leaf_dbuf_t *l_db;
167 + } zl_db_u;
160 168 } zap_leaf_t;
161 169
170 +#define l_dbuf zl_db_u.l_dmu_db
171 +#define l_phys zl_db_u.l_db->zldb_data
162 172
163 173 typedef struct zap_entry_handle {
164 174 /* below is set by zap_leaf.c and is public to zap.c */
165 175 uint64_t zeh_num_integers;
166 176 uint64_t zeh_hash;
167 177 uint32_t zeh_cd;
168 178 uint8_t zeh_integer_size;
169 179
170 180 /* below is private to zap_leaf.c */
171 181 uint16_t zeh_fakechunk;
172 182 uint16_t *zeh_chunkp;
173 183 zap_leaf_t *zeh_leaf;
174 184 } zap_entry_handle_t;
175 185
176 186 /*
177 187 * Return a handle to the named entry, or ENOENT if not found. The hash
178 188 * value must equal zap_hash(name).
179 189 */
180 190 extern int zap_leaf_lookup(zap_leaf_t *l,
181 191 struct zap_name *zn, zap_entry_handle_t *zeh);
182 192
183 193 /*
184 194 * Return a handle to the entry with this hash+cd, or the entry with the
185 195 * next closest hash+cd.
186 196 */
187 197 extern int zap_leaf_lookup_closest(zap_leaf_t *l,
188 198 uint64_t hash, uint32_t cd, zap_entry_handle_t *zeh);
189 199
190 200 /*
191 201 * Read the first num_integers in the attribute. Integer size
192 202 * conversion will be done without sign extension. Return EINVAL if
193 203 * integer_size is too small. Return EOVERFLOW if there are more than
194 204 * num_integers in the attribute.
195 205 */
196 206 extern int zap_entry_read(const zap_entry_handle_t *zeh,
197 207 uint8_t integer_size, uint64_t num_integers, void *buf);
198 208
199 209 extern int zap_entry_read_name(struct zap *zap, const zap_entry_handle_t *zeh,
200 210 uint16_t buflen, char *buf);
201 211
202 212 /*
203 213 * Replace the value of an existing entry.
204 214 *
205 215 * zap_entry_update may fail if it runs out of space (ENOSPC).
206 216 */
207 217 extern int zap_entry_update(zap_entry_handle_t *zeh,
208 218 uint8_t integer_size, uint64_t num_integers, const void *buf);
209 219
210 220 /*
211 221 * Remove an entry.
212 222 */
213 223 extern void zap_entry_remove(zap_entry_handle_t *zeh);
214 224
215 225 /*
216 226 * Create an entry. An equal entry must not exist, and this entry must
217 227 * belong in this leaf (according to its hash value). Fills in the
218 228 * entry handle on success. Returns 0 on success or ENOSPC on failure.
219 229 */
220 230 extern int zap_entry_create(zap_leaf_t *l, struct zap_name *zn, uint32_t cd,
221 231 uint8_t integer_size, uint64_t num_integers, const void *buf,
222 232 zap_entry_handle_t *zeh);
223 233
224 234 /*
225 235 * Return true if there are additional entries with the same normalized
226 236 * form.
227 237 */
228 238 extern boolean_t zap_entry_normalization_conflict(zap_entry_handle_t *zeh,
229 239 struct zap_name *zn, const char *name, struct zap *zap);
230 240
231 241 /*
232 242 * Other stuff.
233 243 */
234 244
235 245 extern void zap_leaf_init(zap_leaf_t *l, boolean_t sort);
236 246 extern void zap_leaf_byteswap(zap_leaf_phys_t *buf, int len);
237 247 extern void zap_leaf_split(zap_leaf_t *l, zap_leaf_t *nl, boolean_t sort);
238 248 extern void zap_leaf_stats(struct zap *zap, zap_leaf_t *l,
239 249 struct zap_stats *zs);
240 250
241 251 #ifdef __cplusplus
242 252 }
243 253 #endif
244 254
245 255 #endif /* _SYS_ZAP_LEAF_H */
↓ open down ↓ |
74 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX