Tue Jan 28 16:33:34 2020 UTC ()
Add a radix_tree_await_memory(), for kernel use.


(ad)
diff -r1.21 -r1.22 src/common/lib/libc/gen/radixtree.c
diff -r1.6 -r1.7 src/sys/sys/radixtree.h

cvs diff -r1.21 -r1.22 src/common/lib/libc/gen/radixtree.c (expand / switch to unified diff)

--- src/common/lib/libc/gen/radixtree.c 2020/01/12 20:00:41 1.21
+++ src/common/lib/libc/gen/radixtree.c 2020/01/28 16:33:34 1.22
@@ -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
343void 343void
344radix_tree_init(void) 344radix_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
 360void
 361radix_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
354static bool __unused 371static bool __unused
355radix_tree_node_clean_p(const struct radix_tree_node *n) 372radix_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 }

cvs diff -r1.6 -r1.7 src/sys/sys/radixtree.h (expand / switch to unified diff)

--- src/sys/sys/radixtree.h 2019/12/05 18:32:25 1.6
+++ src/sys/sys/radixtree.h 2020/01/28 16:33:34 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: radixtree.h,v 1.6 2019/12/05 18:32:25 ad Exp $ */ 1/* $NetBSD: radixtree.h,v 1.7 2020/01/28 16:33:34 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2011 YAMAMOTO Takashi, 4 * Copyright (c)2011 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.
@@ -37,26 +37,27 @@ struct radix_tree { @@ -37,26 +37,27 @@ struct radix_tree {
37#if defined(_KERNEL) || defined(_STANDALONE) 37#if defined(_KERNEL) || defined(_STANDALONE)
38#include <sys/types.h> 38#include <sys/types.h>
39#else /* defined(_KERNEL) || defined(_STANDALONE) */ 39#else /* defined(_KERNEL) || defined(_STANDALONE) */
40#include <stdbool.h> 40#include <stdbool.h>
41#include <stdint.h> 41#include <stdint.h>
42#endif /* defined(_KERNEL) || defined(_STANDALONE) */ 42#endif /* defined(_KERNEL) || defined(_STANDALONE) */
43 43
44/* 44/*
45 * subsystem 45 * subsystem
46 */ 46 */
47 47
48#if defined(_KERNEL) 48#if defined(_KERNEL)
49void radix_tree_init(void); 49void radix_tree_init(void);
 50void radix_tree_await_memory(void);
50#endif /* defined(_KERNEL) */ 51#endif /* defined(_KERNEL) */
51 52
52/* 53/*
53 * tree 54 * tree
54 */ 55 */
55 56
56void radix_tree_init_tree(struct radix_tree *); 57void radix_tree_init_tree(struct radix_tree *);
57void radix_tree_fini_tree(struct radix_tree *); 58void radix_tree_fini_tree(struct radix_tree *);
58bool radix_tree_empty_tree_p(struct radix_tree *); 59bool radix_tree_empty_tree_p(struct radix_tree *);
59 60
60/* 61/*
61 * node 62 * node
62 */ 63 */