| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: radixtree.c,v 1.21 2020/01/12 20:00:41 para Exp $ */ | | 1 | /* $NetBSD: radixtree.c,v 1.22 2020/01/28 16:33:34 ad Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c)2011,2012,2013 YAMAMOTO Takashi, | | 4 | * Copyright (c)2011,2012,2013 YAMAMOTO Takashi, |
5 | * All rights reserved. | | 5 | * 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. |
| @@ -102,37 +102,37 @@ | | | @@ -102,37 +102,37 @@ |
102 | * leaf nodes with the given tag. To reduce amount of nodes to visit for | | 102 | * leaf nodes with the given tag. To reduce amount of nodes to visit for |
103 | * these functions, this implementation keeps tagging information in internal | | 103 | * these functions, this implementation keeps tagging information in internal |
104 | * intermediate nodes and quickly skips uninterested parts of a tree. | | 104 | * intermediate nodes and quickly skips uninterested parts of a tree. |
105 | * | | 105 | * |
106 | * A tree has RADIX_TREE_TAG_ID_MAX independent tag spaces, each of which are | | 106 | * A tree has RADIX_TREE_TAG_ID_MAX independent tag spaces, each of which are |
107 | * identified by an zero-origin numbers, tagid. For the current implementation, | | 107 | * identified by an zero-origin numbers, tagid. For the current implementation, |
108 | * RADIX_TREE_TAG_ID_MAX is 2. A set of tags is described as a bitmask tagmask, | | 108 | * RADIX_TREE_TAG_ID_MAX is 2. A set of tags is described as a bitmask tagmask, |
109 | * which is a bitwise OR of (1 << tagid). | | 109 | * which is a bitwise OR of (1 << tagid). |
110 | */ | | 110 | */ |
111 | | | 111 | |
112 | #include <sys/cdefs.h> | | 112 | #include <sys/cdefs.h> |
113 | | | 113 | |
114 | #if defined(_KERNEL) || defined(_STANDALONE) | | 114 | #if defined(_KERNEL) || defined(_STANDALONE) |
115 | __KERNEL_RCSID(0, "$NetBSD: radixtree.c,v 1.21 2020/01/12 20:00:41 para Exp $"); | | 115 | __KERNEL_RCSID(0, "$NetBSD: radixtree.c,v 1.22 2020/01/28 16:33:34 ad Exp $"); |
116 | #include <sys/param.h> | | 116 | #include <sys/param.h> |
117 | #include <sys/errno.h> | | 117 | #include <sys/errno.h> |
118 | #include <sys/pool.h> | | 118 | #include <sys/pool.h> |
119 | #include <sys/radixtree.h> | | 119 | #include <sys/radixtree.h> |
120 | #include <lib/libkern/libkern.h> | | 120 | #include <lib/libkern/libkern.h> |
121 | #if defined(_STANDALONE) | | 121 | #if defined(_STANDALONE) |
122 | #include <lib/libsa/stand.h> | | 122 | #include <lib/libsa/stand.h> |
123 | #endif /* defined(_STANDALONE) */ | | 123 | #endif /* defined(_STANDALONE) */ |
124 | #else /* defined(_KERNEL) || defined(_STANDALONE) */ | | 124 | #else /* defined(_KERNEL) || defined(_STANDALONE) */ |
125 | __RCSID("$NetBSD: radixtree.c,v 1.21 2020/01/12 20:00:41 para Exp $"); | | 125 | __RCSID("$NetBSD: radixtree.c,v 1.22 2020/01/28 16:33:34 ad Exp $"); |
126 | #include <assert.h> | | 126 | #include <assert.h> |
127 | #include <errno.h> | | 127 | #include <errno.h> |
128 | #include <stdbool.h> | | 128 | #include <stdbool.h> |
129 | #include <stdlib.h> | | 129 | #include <stdlib.h> |
130 | #include <string.h> | | 130 | #include <string.h> |
131 | #if 1 | | 131 | #if 1 |
132 | #define KASSERT assert | | 132 | #define KASSERT assert |
133 | #else | | 133 | #else |
134 | #define KASSERT(a) /* nothing */ | | 134 | #define KASSERT(a) /* nothing */ |
135 | #endif | | 135 | #endif |
136 | #endif /* defined(_KERNEL) || defined(_STANDALONE) */ | | 136 | #endif /* defined(_KERNEL) || defined(_STANDALONE) */ |
137 | | | 137 | |
138 | #include <sys/radixtree.h> | | 138 | #include <sys/radixtree.h> |
| @@ -339,26 +339,43 @@ radix_tree_node_ctor(void *dummy, void * | | | @@ -339,26 +339,43 @@ radix_tree_node_ctor(void *dummy, void * |
339 | * | | 339 | * |
340 | * initialize the subsystem. | | 340 | * initialize the subsystem. |
341 | */ | | 341 | */ |
342 | | | 342 | |
343 | void | | 343 | void |
344 | radix_tree_init(void) | | 344 | radix_tree_init(void) |
345 | { | | 345 | { |
346 | | | 346 | |
347 | radix_tree_node_cache = pool_cache_init(sizeof(struct radix_tree_node), | | 347 | radix_tree_node_cache = pool_cache_init(sizeof(struct radix_tree_node), |
348 | coherency_unit, 0, PR_LARGECACHE, "radixnode", NULL, IPL_NONE, | | 348 | coherency_unit, 0, PR_LARGECACHE, "radixnode", NULL, IPL_NONE, |
349 | radix_tree_node_ctor, NULL, NULL); | | 349 | radix_tree_node_ctor, NULL, NULL); |
350 | KASSERT(radix_tree_node_cache != NULL); | | 350 | KASSERT(radix_tree_node_cache != NULL); |
351 | } | | 351 | } |
| | | 352 | |
| | | 353 | /* |
| | | 354 | * radix_tree_await_memory: |
| | | 355 | * |
| | | 356 | * after an insert has failed with ENOMEM, wait for memory to become |
| | | 357 | * available, so the caller can retry. |
| | | 358 | */ |
| | | 359 | |
| | | 360 | void |
| | | 361 | radix_tree_await_memory(void) |
| | | 362 | { |
| | | 363 | struct radix_tree_node *n; |
| | | 364 | |
| | | 365 | n = pool_cache_get(radix_tree_node_cache, PR_WAITOK); |
| | | 366 | pool_cache_put(radix_tree_node_cache, n); |
| | | 367 | } |
| | | 368 | |
352 | #endif /* defined(_KERNEL) */ | | 369 | #endif /* defined(_KERNEL) */ |
353 | | | 370 | |
354 | static bool __unused | | 371 | static bool __unused |
355 | radix_tree_node_clean_p(const struct radix_tree_node *n) | | 372 | radix_tree_node_clean_p(const struct radix_tree_node *n) |
356 | { | | 373 | { |
357 | #if RADIX_TREE_PTR_PER_NODE > 16 | | 374 | #if RADIX_TREE_PTR_PER_NODE > 16 |
358 | unsigned int i; | | 375 | unsigned int i; |
359 | | | 376 | |
360 | for (i = 0; i < RADIX_TREE_PTR_PER_NODE; i++) { | | 377 | for (i = 0; i < RADIX_TREE_PTR_PER_NODE; i++) { |
361 | if (n->n_ptrs[i] != NULL) { | | 378 | if (n->n_ptrs[i] != NULL) { |
362 | return false; | | 379 | return false; |
363 | } | | 380 | } |
364 | } | | 381 | } |