CVS commit: src/common/lib/libc/gen

2024-05-04 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sat May  4 17:58:24 UTC 2024

Modified Files:
src/common/lib/libc/gen: radixtree.c

Log Message:
radixtree: allocate memory with KM_NOSLEEP to prevent pagedaemon hangs

Revert the part of rev 1.32 (reapplying "Do away with separate pool_cache
for some kernel objects") that changed the memory allocation for radixtree
nodes from PR_NOWAIT to KM_SLEEP as part of changing from a pool to kmem.
uvm_pageinsert_tree() calls into the radixtree code while holding
the object's vmobjlock, but that same lock is taken by the pagedaemon
in the process of reclaiming pages, and if the pagedaemon happens to
choose the same object to reclaim from that uvm_pageinsert_tree()
is being called on, then these two threads will deadlock.
The previous code already handled memory allocation failures
in uvm_pageinsert_tree() so we can simply change it back to nosleep.

Fixes a hang reported by simonb@, and the fix was also tested by him.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/common/lib/libc/gen/radixtree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/common/lib/libc/gen/radixtree.c
diff -u src/common/lib/libc/gen/radixtree.c:1.33 src/common/lib/libc/gen/radixtree.c:1.34
--- src/common/lib/libc/gen/radixtree.c:1.33	Sat Sep 23 19:17:38 2023
+++ src/common/lib/libc/gen/radixtree.c	Sat May  4 17:58:24 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: radixtree.c,v 1.33 2023/09/23 19:17:38 ad Exp $	*/
+/*	$NetBSD: radixtree.c,v 1.34 2024/05/04 17:58:24 chs Exp $	*/
 
 /*-
  * Copyright (c)2011,2012,2013 YAMAMOTO Takashi,
@@ -112,7 +112,7 @@
 #include 
 
 #if defined(_KERNEL) || defined(_STANDALONE)
-__KERNEL_RCSID(0, "$NetBSD: radixtree.c,v 1.33 2023/09/23 19:17:38 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radixtree.c,v 1.34 2024/05/04 17:58:24 chs Exp $");
 #include 
 #include 
 #include 
@@ -122,7 +122,7 @@ __KERNEL_RCSID(0, "$NetBSD: radixtree.c,
 #include 
 #endif /* defined(_STANDALONE) */
 #else /* defined(_KERNEL) || defined(_STANDALONE) */
-__RCSID("$NetBSD: radixtree.c,v 1.33 2023/09/23 19:17:38 ad Exp $");
+__RCSID("$NetBSD: radixtree.c,v 1.34 2024/05/04 17:58:24 chs Exp $");
 #include 
 #include 
 #include 
@@ -410,9 +410,10 @@ radix_tree_alloc_node(void)
 
 #if defined(_KERNEL)
 	/*
-	 * note that kmem_alloc can block.
+	 * We must not block waiting for memory because this function
+	 * can be called in contexts where waiting for memory is illegal.
 	 */
-	n = kmem_intr_alloc(sizeof(struct radix_tree_node), KM_SLEEP);
+	n = kmem_intr_alloc(sizeof(struct radix_tree_node), KM_NOSLEEP);
 #elif defined(_STANDALONE)
 	n = alloc(sizeof(*n));
 #else /* defined(_STANDALONE) */



CVS commit: src/common/lib/libc/gen

2024-05-04 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sat May  4 17:58:24 UTC 2024

Modified Files:
src/common/lib/libc/gen: radixtree.c

Log Message:
radixtree: allocate memory with KM_NOSLEEP to prevent pagedaemon hangs

Revert the part of rev 1.32 (reapplying "Do away with separate pool_cache
for some kernel objects") that changed the memory allocation for radixtree
nodes from PR_NOWAIT to KM_SLEEP as part of changing from a pool to kmem.
uvm_pageinsert_tree() calls into the radixtree code while holding
the object's vmobjlock, but that same lock is taken by the pagedaemon
in the process of reclaiming pages, and if the pagedaemon happens to
choose the same object to reclaim from that uvm_pageinsert_tree()
is being called on, then these two threads will deadlock.
The previous code already handled memory allocation failures
in uvm_pageinsert_tree() so we can simply change it back to nosleep.

Fixes a hang reported by simonb@, and the fix was also tested by him.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/common/lib/libc/gen/radixtree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/common/lib/libc/gen

2023-09-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Sep 23 19:17:38 UTC 2023

Modified Files:
src/common/lib/libc/gen: radixtree.c

Log Message:
kmem_free() -> kmem_intr_free().  Spotted by rin@.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/common/lib/libc/gen/radixtree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/common/lib/libc/gen/radixtree.c
diff -u src/common/lib/libc/gen/radixtree.c:1.32 src/common/lib/libc/gen/radixtree.c:1.33
--- src/common/lib/libc/gen/radixtree.c:1.32	Sat Sep 23 18:21:11 2023
+++ src/common/lib/libc/gen/radixtree.c	Sat Sep 23 19:17:38 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: radixtree.c,v 1.32 2023/09/23 18:21:11 ad Exp $	*/
+/*	$NetBSD: radixtree.c,v 1.33 2023/09/23 19:17:38 ad Exp $	*/
 
 /*-
  * Copyright (c)2011,2012,2013 YAMAMOTO Takashi,
@@ -112,7 +112,7 @@
 #include 
 
 #if defined(_KERNEL) || defined(_STANDALONE)
-__KERNEL_RCSID(0, "$NetBSD: radixtree.c,v 1.32 2023/09/23 18:21:11 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radixtree.c,v 1.33 2023/09/23 19:17:38 ad Exp $");
 #include 
 #include 
 #include 
@@ -122,7 +122,7 @@ __KERNEL_RCSID(0, "$NetBSD: radixtree.c,
 #include 
 #endif /* defined(_STANDALONE) */
 #else /* defined(_KERNEL) || defined(_STANDALONE) */
-__RCSID("$NetBSD: radixtree.c,v 1.32 2023/09/23 18:21:11 ad Exp $");
+__RCSID("$NetBSD: radixtree.c,v 1.33 2023/09/23 19:17:38 ad Exp $");
 #include 
 #include 
 #include 
@@ -335,7 +335,7 @@ radix_tree_await_memory(void)
 		KM_SLEEP);
 	}
 	while (--i >= 0) {
-		kmem_free(nodes[i], sizeof(struct radix_tree_node));
+		kmem_intr_free(nodes[i], sizeof(struct radix_tree_node));
 	}
 }
 



CVS commit: src/common/lib/libc/gen

2023-09-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Sep 23 19:17:38 UTC 2023

Modified Files:
src/common/lib/libc/gen: radixtree.c

Log Message:
kmem_free() -> kmem_intr_free().  Spotted by rin@.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/common/lib/libc/gen/radixtree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/common/lib/libc/gen

2022-05-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May 26 15:23:33 UTC 2022

Modified Files:
src/common/lib/libc/gen: ptree.c

Log Message:
libc/ptree: remove CONSTCOND comments

Since 2021-01-31, lint does not need them anymore.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/common/lib/libc/gen/ptree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/common/lib/libc/gen/ptree.c
diff -u src/common/lib/libc/gen/ptree.c:1.11 src/common/lib/libc/gen/ptree.c:1.12
--- src/common/lib/libc/gen/ptree.c:1.11	Tue May 24 20:50:17 2022
+++ src/common/lib/libc/gen/ptree.c	Thu May 26 15:23:33 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ptree.c,v 1.11 2022/05/24 20:50:17 andvar Exp $	*/
+/*	$NetBSD: ptree.c,v 1.12 2022/05/26 15:23:33 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 #include 
 #include 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ptree.c,v 1.11 2022/05/24 20:50:17 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ptree.c,v 1.12 2022/05/26 15:23:33 rillig Exp $");
 #else
 #include 
 #include 
@@ -51,9 +51,9 @@ __KERNEL_RCSID(0, "$NetBSD: ptree.c,v 1.
 #include 
 #define	KASSERT(e)	assert(e)
 #else
-#define	KASSERT(e)	do { } while (/*CONSTCOND*/ 0)
+#define	KASSERT(e)	do { } while (0)
 #endif
-__RCSID("$NetBSD: ptree.c,v 1.11 2022/05/24 20:50:17 andvar Exp $");
+__RCSID("$NetBSD: ptree.c,v 1.12 2022/05/26 15:23:33 rillig Exp $");
 #endif /* _KERNEL || _STANDALONE */
 
 #ifdef _LIBC
@@ -115,7 +115,7 @@ bool ptree_check(const pt_tree_t *);
 #if PTCHECK > 1
 #define	PTREE_CHECK(pt)		ptree_check(pt)
 #else
-#define	PTREE_CHECK(pt)		do { } while (/*CONSTCOND*/ 0)
+#define	PTREE_CHECK(pt)		do { } while (0)
 #endif
 
 static inline bool



CVS commit: src/common/lib/libc/gen

2022-05-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May 26 15:23:33 UTC 2022

Modified Files:
src/common/lib/libc/gen: ptree.c

Log Message:
libc/ptree: remove CONSTCOND comments

Since 2021-01-31, lint does not need them anymore.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/common/lib/libc/gen/ptree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.