Index | Thread | Search

From:
Martin Pieuchot <mpi@grenadille.net>
Subject:
ci_idepth & in_pagedaemon()
To:
tech@openbsd.org
Date:
Tue, 5 Nov 2024 16:46:25 +0100

Download raw body.

Thread
Here's my last diff to ensure memory reserved for the page daemon isn't
stolen by allocations in interrupt context.

All architectures but sparc64 now have `ci_idepth'.  I'd like to commit
the diff below.

ok?

Index: uvm/uvm_pmemrange.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_pmemrange.c,v
diff -u -p -r1.68 uvm_pmemrange.c
--- uvm/uvm_pmemrange.c	2 Oct 2024 10:17:28 -0000	1.68
+++ uvm/uvm_pmemrange.c	5 Nov 2024 15:40:37 -0000
@@ -81,6 +81,20 @@ int	uvm_pmr_pg_to_memtype(struct vm_page
 void	uvm_pmr_print(void);
 #endif
 
+static inline int
+in_pagedaemon(int allowsyncer)
+{
+#if !defined(__sparc64__)
+	if (curcpu()->ci_idepth > 0)
+		return 0;
+#endif
+	if (curproc == uvm.pagedaemon_proc)
+		return 1;
+	if (allowsyncer && (curproc == syncerproc))
+		return 1;
+	return 0;
+}
+
 /*
  * Memory types. The page flags are used to derive what the current memory
  * type of a page is.
@@ -967,8 +981,7 @@ again:
 	}
 
 	if ((uvmexp.free <= (uvmexp.reserve_pagedaemon + count)) &&
-	    (curproc != uvm.pagedaemon_proc) && (curproc != syncerproc)) {
-		uvm_unlock_fpageq();
+	    !in_pagedaemon(1)) {
 		if (flags & UVM_PLA_WAITOK) {
 			uvm_wait("uvm_pmr_getpages");
 			goto again;
@@ -2094,6 +2107,10 @@ uvm_wait_pla(paddr_t low, paddr_t high, 
 {
 	struct uvm_pmalloc pma;
 	const char *wmsg = "pmrwait";
+
+#if !defined(__sparc64__)
+	KASSERT(curcpu()->ci_idepth == 0);
+#endif
 
 	if (curproc == uvm.pagedaemon_proc) {
 		/*