summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2022-03-17 10:15:14 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2022-03-17 10:15:14 +0000
commite16d80be4565ffa838f3a3f97a0fd619f9621ff8 (patch)
treef217a0e33332f22608c5e16ef5de0b5b4a2455f9 /sys
parent7891e799f720d9191f7b4b562895fb46ca272b2b (diff)
In swap_io() allocate the buffer before doing encryption.
If the allocation fails due to memory pressure no time is wasted doing encryption. This also simplify the error path. Tested by sthen@. ok kn@, miod@, kettenis@, tb@
Diffstat (limited to 'sys')
-rw-r--r--sys/uvm/uvm_swap.c51
1 files changed, 21 insertions, 30 deletions
diff --git a/sys/uvm/uvm_swap.c b/sys/uvm/uvm_swap.c
index 13e1e02f6dd..bee6ac91f61 100644
--- a/sys/uvm/uvm_swap.c
+++ b/sys/uvm/uvm_swap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_swap.c,v 1.153 2022/02/22 01:15:02 guenther Exp $ */
+/* $OpenBSD: uvm_swap.c,v 1.154 2022/03/17 10:15:13 mpi Exp $ */
/* $NetBSD: uvm_swap.c,v 1.40 2000/11/17 11:39:39 mrg Exp $ */
/*
@@ -1690,6 +1690,26 @@ uvm_swap_io(struct vm_page **pps, int startslot, int npages, int flags)
}
}
+ /*
+ * now allocate a buf for the i/o.
+ * [make sure we don't put the pagedaemon to sleep...]
+ */
+ pflag = (async || curproc == uvm.pagedaemon_proc) ? PR_NOWAIT :
+ PR_WAITOK;
+ bp = pool_get(&bufpool, pflag | PR_ZERO);
+
+ /*
+ * if we failed to get a swapbuf, return "try again"
+ */
+ if (bp == NULL) {
+ if (bounce) {
+ uvm_pagermapout(bouncekva, npages);
+ uvm_swap_freepages(tpps, npages);
+ }
+ uvm_pagermapout(kva, npages);
+ return (VM_PAGER_AGAIN);
+ }
+
/* encrypt to swap */
if (write && bounce) {
int i, opages;
@@ -1732,35 +1752,6 @@ uvm_swap_io(struct vm_page **pps, int startslot, int npages, int flags)
}
/*
- * now allocate a buf for the i/o.
- * [make sure we don't put the pagedaemon to sleep...]
- */
- pflag = (async || curproc == uvm.pagedaemon_proc) ? PR_NOWAIT :
- PR_WAITOK;
- bp = pool_get(&bufpool, pflag | PR_ZERO);
-
- /*
- * if we failed to get a swapbuf, return "try again"
- */
- if (bp == NULL) {
- if (write && bounce) {
-#ifdef UVM_SWAP_ENCRYPT
- int i;
-
- /* swap encrypt needs cleanup */
- if (encrypt)
- for (i = 0; i < npages; i++)
- SWAP_KEY_PUT(sdp, SWD_KEY(sdp,
- startslot + i));
-#endif
-
- uvm_pagermapout(kva, npages);
- uvm_swap_freepages(tpps, npages);
- }
- return (VM_PAGER_AGAIN);
- }
-
- /*
* prevent ASYNC reads.
* uvm_swap_io is only called from uvm_swap_get, uvm_swap_get
* assumes that all gets are SYNCIO. Just make sure here.