uvm_pager.c revision 1.16.4.7 1 1.16.4.7 chs /* $NetBSD: uvm_pager.c,v 1.16.4.7 1999/08/09 00:05:56 chs Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg *
5 1.1 mrg * Copyright (c) 1997 Charles D. Cranor and Washington University.
6 1.1 mrg * All rights reserved.
7 1.1 mrg *
8 1.1 mrg * Redistribution and use in source and binary forms, with or without
9 1.1 mrg * modification, are permitted provided that the following conditions
10 1.1 mrg * are met:
11 1.1 mrg * 1. Redistributions of source code must retain the above copyright
12 1.1 mrg * notice, this list of conditions and the following disclaimer.
13 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 mrg * notice, this list of conditions and the following disclaimer in the
15 1.1 mrg * documentation and/or other materials provided with the distribution.
16 1.1 mrg * 3. All advertising materials mentioning features or use of this software
17 1.1 mrg * must display the following acknowledgement:
18 1.1 mrg * This product includes software developed by Charles D. Cranor and
19 1.1 mrg * Washington University.
20 1.1 mrg * 4. The name of the author may not be used to endorse or promote products
21 1.1 mrg * derived from this software without specific prior written permission.
22 1.1 mrg *
23 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.1 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.1 mrg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.1 mrg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.1 mrg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.1 mrg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.1 mrg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.3 mrg *
34 1.3 mrg * from: Id: uvm_pager.c,v 1.1.2.23 1998/02/02 20:38:06 chuck Exp
35 1.1 mrg */
36 1.1 mrg
37 1.5 mrg #include "opt_pmap_new.h"
38 1.16.4.5 chs #include "opt_uvmhist.h"
39 1.5 mrg
40 1.1 mrg /*
41 1.1 mrg * uvm_pager.c: generic functions used to assist the pagers.
42 1.1 mrg */
43 1.1 mrg
44 1.1 mrg #include <sys/param.h>
45 1.1 mrg #include <sys/systm.h>
46 1.1 mrg #include <sys/proc.h>
47 1.1 mrg #include <sys/malloc.h>
48 1.16.4.1 chs #include <sys/pool.h>
49 1.16.4.3 chs #include <sys/vnode.h>
50 1.1 mrg
51 1.1 mrg #include <vm/vm.h>
52 1.1 mrg #include <vm/vm_page.h>
53 1.1 mrg #include <vm/vm_kern.h>
54 1.1 mrg
55 1.1 mrg #define UVM_PAGER
56 1.1 mrg #include <uvm/uvm.h>
57 1.1 mrg
58 1.16.4.1 chs struct pool *uvm_aiobuf_pool;
59 1.16.4.1 chs
60 1.1 mrg /*
61 1.1 mrg * list of uvm pagers in the system
62 1.1 mrg */
63 1.1 mrg
64 1.10 thorpej extern struct uvm_pagerops aobj_pager;
65 1.1 mrg extern struct uvm_pagerops uvm_deviceops;
66 1.1 mrg extern struct uvm_pagerops uvm_vnodeops;
67 1.16.4.1 chs extern struct uvm_pagerops ubc_pager;
68 1.1 mrg
69 1.1 mrg struct uvm_pagerops *uvmpagerops[] = {
70 1.10 thorpej &aobj_pager,
71 1.6 mrg &uvm_deviceops,
72 1.6 mrg &uvm_vnodeops,
73 1.16.4.1 chs &ubc_pager,
74 1.1 mrg };
75 1.1 mrg
76 1.1 mrg /*
77 1.1 mrg * the pager map: provides KVA for I/O
78 1.1 mrg */
79 1.1 mrg
80 1.1 mrg #define PAGER_MAP_SIZE (4 * 1024 * 1024)
81 1.1 mrg vm_map_t pager_map; /* XXX */
82 1.1 mrg simple_lock_data_t pager_map_wanted_lock;
83 1.1 mrg boolean_t pager_map_wanted; /* locked by pager map */
84 1.1 mrg
85 1.1 mrg
86 1.1 mrg /*
87 1.1 mrg * uvm_pager_init: init pagers (at boot time)
88 1.1 mrg */
89 1.1 mrg
90 1.6 mrg void
91 1.6 mrg uvm_pager_init()
92 1.6 mrg {
93 1.6 mrg int lcv;
94 1.1 mrg
95 1.6 mrg /*
96 1.6 mrg * init pager map
97 1.6 mrg */
98 1.6 mrg
99 1.16.4.1 chs pager_map = uvm_km_suballoc(kernel_map, &uvm.pager_sva, &uvm.pager_eva,
100 1.16.4.2 thorpej PAGER_MAP_SIZE, 0, FALSE, NULL);
101 1.16.4.1 chs simple_lock_init(&pager_map_wanted_lock);
102 1.16.4.1 chs pager_map_wanted = FALSE;
103 1.6 mrg
104 1.6 mrg /*
105 1.6 mrg * init ASYNC I/O queue
106 1.6 mrg */
107 1.6 mrg
108 1.6 mrg TAILQ_INIT(&uvm.aio_done);
109 1.1 mrg
110 1.6 mrg /*
111 1.6 mrg * call pager init functions
112 1.6 mrg */
113 1.6 mrg for (lcv = 0 ; lcv < sizeof(uvmpagerops)/sizeof(struct uvm_pagerops *);
114 1.6 mrg lcv++) {
115 1.6 mrg if (uvmpagerops[lcv]->pgo_init)
116 1.6 mrg uvmpagerops[lcv]->pgo_init();
117 1.6 mrg }
118 1.1 mrg }
119 1.1 mrg
120 1.1 mrg /*
121 1.1 mrg * uvm_pagermapin: map pages into KVA (pager_map) for I/O that needs mappings
122 1.1 mrg *
123 1.1 mrg * we basically just map in a blank map entry to reserve the space in the
124 1.1 mrg * map and then use pmap_enter() to put the mappings in by hand.
125 1.16.4.2 thorpej *
126 1.16.4.2 thorpej * XXX It would be nice to know the direction of the I/O, so that we can
127 1.16.4.2 thorpej * XXX map only what is necessary.
128 1.1 mrg */
129 1.1 mrg
130 1.9 eeh vaddr_t
131 1.16.4.3 chs uvm_pagermapin(pps, npages, waitf)
132 1.6 mrg struct vm_page **pps;
133 1.6 mrg int npages;
134 1.6 mrg int waitf;
135 1.1 mrg {
136 1.9 eeh vsize_t size;
137 1.9 eeh vaddr_t kva;
138 1.9 eeh vaddr_t cva;
139 1.6 mrg struct vm_page *pp;
140 1.6 mrg UVMHIST_FUNC("uvm_pagermapin"); UVMHIST_CALLED(maphist);
141 1.1 mrg
142 1.16.4.3 chs UVMHIST_LOG(maphist,"(pps=0x%x, npages=%d, waitf=%d)",
143 1.16.4.3 chs pps, npages, waitf, 0);
144 1.1 mrg
145 1.1 mrg ReStart:
146 1.12 chs size = npages << PAGE_SHIFT;
147 1.6 mrg kva = NULL; /* let system choose VA */
148 1.1 mrg
149 1.6 mrg if (uvm_map(pager_map, &kva, size, NULL,
150 1.1 mrg UVM_UNKNOWN_OFFSET, UVM_FLAG_NOMERGE) != KERN_SUCCESS) {
151 1.6 mrg if (waitf == M_NOWAIT) {
152 1.6 mrg UVMHIST_LOG(maphist,"<- NOWAIT failed", 0,0,0,0);
153 1.16.4.3 chs return(0);
154 1.6 mrg }
155 1.6 mrg simple_lock(&pager_map_wanted_lock);
156 1.6 mrg pager_map_wanted = TRUE;
157 1.6 mrg UVMHIST_LOG(maphist, " SLEEPING on pager_map",0,0,0,0);
158 1.6 mrg UVM_UNLOCK_AND_WAIT(pager_map, &pager_map_wanted_lock, FALSE,
159 1.6 mrg "pager_map",0);
160 1.6 mrg goto ReStart;
161 1.6 mrg }
162 1.1 mrg
163 1.6 mrg /* got it */
164 1.6 mrg for (cva = kva ; size != 0 ; size -= PAGE_SIZE, cva += PAGE_SIZE) {
165 1.6 mrg pp = *pps++;
166 1.1 mrg #ifdef DEBUG
167 1.6 mrg if ((pp->flags & PG_BUSY) == 0)
168 1.6 mrg panic("uvm_pagermapin: page not busy");
169 1.1 mrg #endif
170 1.1 mrg
171 1.16.4.2 thorpej /*
172 1.16.4.2 thorpej * XXX VM_PROT_DEFAULT includes VM_PROT_EXEC; is that
173 1.16.4.2 thorpej * XXX really necessary? It could lead to unnecessary
174 1.16.4.2 thorpej * XXX instruction cache flushes.
175 1.16.4.2 thorpej */
176 1.6 mrg pmap_enter(vm_map_pmap(pager_map), cva, VM_PAGE_TO_PHYS(pp),
177 1.16.4.2 thorpej VM_PROT_DEFAULT, TRUE,
178 1.16.4.2 thorpej VM_PROT_READ | VM_PROT_WRITE);
179 1.6 mrg }
180 1.1 mrg
181 1.6 mrg UVMHIST_LOG(maphist, "<- done (KVA=0x%x)", kva,0,0,0);
182 1.6 mrg return(kva);
183 1.1 mrg }
184 1.1 mrg
185 1.1 mrg /*
186 1.1 mrg * uvm_pagermapout: remove pager_map mapping
187 1.1 mrg *
188 1.1 mrg * we remove our mappings by hand and then remove the mapping (waking
189 1.1 mrg * up anyone wanting space).
190 1.1 mrg */
191 1.1 mrg
192 1.6 mrg void
193 1.6 mrg uvm_pagermapout(kva, npages)
194 1.9 eeh vaddr_t kva;
195 1.6 mrg int npages;
196 1.6 mrg {
197 1.12 chs vsize_t size = npages << PAGE_SHIFT;
198 1.6 mrg vm_map_entry_t entries;
199 1.6 mrg UVMHIST_FUNC("uvm_pagermapout"); UVMHIST_CALLED(maphist);
200 1.6 mrg UVMHIST_LOG(maphist, " (kva=0x%x, npages=%d)", kva, npages,0,0);
201 1.1 mrg
202 1.6 mrg /*
203 1.6 mrg * duplicate uvm_unmap, but add in pager_map_wanted handling.
204 1.6 mrg */
205 1.6 mrg
206 1.6 mrg vm_map_lock(pager_map);
207 1.11 chuck (void) uvm_unmap_remove(pager_map, kva, kva + size, &entries);
208 1.6 mrg simple_lock(&pager_map_wanted_lock);
209 1.6 mrg if (pager_map_wanted) {
210 1.6 mrg pager_map_wanted = FALSE;
211 1.6 mrg wakeup(pager_map);
212 1.6 mrg }
213 1.6 mrg simple_unlock(&pager_map_wanted_lock);
214 1.6 mrg vm_map_unlock(pager_map);
215 1.16.4.5 chs pmap_remove(pmap_kernel(), kva, kva + (npages << PAGE_SHIFT));
216 1.6 mrg if (entries)
217 1.6 mrg uvm_unmap_detach(entries, 0);
218 1.1 mrg
219 1.6 mrg UVMHIST_LOG(maphist,"<- done",0,0,0,0);
220 1.1 mrg }
221 1.1 mrg
222 1.1 mrg /*
223 1.1 mrg * uvm_mk_pcluster
224 1.1 mrg *
225 1.1 mrg * generic "make 'pager put' cluster" function. a pager can either
226 1.1 mrg * [1] set pgo_mk_pcluster to NULL (never cluster), [2] set it to this
227 1.1 mrg * generic function, or [3] set it to a pager specific function.
228 1.1 mrg *
229 1.1 mrg * => caller must lock object _and_ pagequeues (since we need to look
230 1.1 mrg * at active vs. inactive bits, etc.)
231 1.1 mrg * => caller must make center page busy and write-protect it
232 1.1 mrg * => we mark all cluster pages busy for the caller
233 1.1 mrg * => the caller must unbusy all pages (and check wanted/released
234 1.1 mrg * status if it drops the object lock)
235 1.1 mrg * => flags:
236 1.1 mrg * PGO_ALLPAGES: all pages in object are valid targets
237 1.1 mrg * !PGO_ALLPAGES: use "lo" and "hi" to limit range of cluster
238 1.1 mrg * PGO_DOACTCLUST: include active pages in cluster.
239 1.1 mrg * NOTE: the caller should clear PG_CLEANCHK bits if PGO_DOACTCLUST.
240 1.1 mrg * PG_CLEANCHK is only a hint, but clearing will help reduce
241 1.1 mrg * the number of calls we make to the pmap layer.
242 1.1 mrg */
243 1.1 mrg
244 1.6 mrg struct vm_page **
245 1.6 mrg uvm_mk_pcluster(uobj, pps, npages, center, flags, mlo, mhi)
246 1.6 mrg struct uvm_object *uobj; /* IN */
247 1.6 mrg struct vm_page **pps, *center; /* IN/OUT, IN */
248 1.6 mrg int *npages, flags; /* IN/OUT, IN */
249 1.16.4.7 chs voff_t mlo, mhi; /* IN (if !PGO_ALLPAGES) */
250 1.1 mrg {
251 1.6 mrg struct vm_page **ppsp, *pclust;
252 1.16.4.7 chs voff_t lo, hi, curoff;
253 1.16.4.1 chs int center_idx, forward, incr;
254 1.6 mrg UVMHIST_FUNC("uvm_mk_pcluster"); UVMHIST_CALLED(maphist);
255 1.6 mrg
256 1.6 mrg /*
257 1.6 mrg * center page should already be busy and write protected. XXX:
258 1.6 mrg * suppose page is wired? if we lock, then a process could
259 1.6 mrg * fault/block on it. if we don't lock, a process could write the
260 1.6 mrg * pages in the middle of an I/O. (consider an msync()). let's
261 1.6 mrg * lock it for now (better to delay than corrupt data?).
262 1.6 mrg */
263 1.6 mrg
264 1.6 mrg /*
265 1.6 mrg * get cluster boundaries, check sanity, and apply our limits as well.
266 1.6 mrg */
267 1.6 mrg
268 1.6 mrg uobj->pgops->pgo_cluster(uobj, center->offset, &lo, &hi);
269 1.6 mrg if ((flags & PGO_ALLPAGES) == 0) {
270 1.6 mrg if (lo < mlo)
271 1.6 mrg lo = mlo;
272 1.6 mrg if (hi > mhi)
273 1.6 mrg hi = mhi;
274 1.6 mrg }
275 1.16.4.1 chs if ((hi - lo) >> PAGE_SHIFT > *npages) { /* pps too small, bail out! */
276 1.1 mrg #ifdef DIAGNOSTIC
277 1.16.4.7 chs printf("uvm_mk_pcluster uobj %p npages %d lo 0x%llx hi 0x%llx "
278 1.16.4.7 chs "flags 0x%x\n", uobj, *npages, (long long)lo,
279 1.16.4.7 chs (long long)hi, flags);
280 1.1 mrg #endif
281 1.6 mrg pps[0] = center;
282 1.6 mrg *npages = 1;
283 1.6 mrg return(pps);
284 1.6 mrg }
285 1.6 mrg
286 1.6 mrg /*
287 1.6 mrg * now determine the center and attempt to cluster around the
288 1.6 mrg * edges
289 1.6 mrg */
290 1.6 mrg
291 1.12 chs center_idx = (center->offset - lo) >> PAGE_SHIFT;
292 1.6 mrg pps[center_idx] = center; /* plug in the center page */
293 1.6 mrg ppsp = &pps[center_idx];
294 1.6 mrg *npages = 1;
295 1.16.4.1 chs
296 1.6 mrg /*
297 1.6 mrg * attempt to cluster around the left [backward], and then
298 1.6 mrg * the right side [forward].
299 1.6 mrg *
300 1.6 mrg * note that for inactive pages (pages that have been deactivated)
301 1.6 mrg * there are no valid mappings and PG_CLEAN should be up to date.
302 1.6 mrg * [i.e. there is no need to query the pmap with pmap_is_modified
303 1.6 mrg * since there are no mappings].
304 1.6 mrg */
305 1.6 mrg
306 1.6 mrg for (forward = 0 ; forward <= 1 ; forward++) {
307 1.16.4.1 chs incr = forward ? PAGE_SIZE : -PAGE_SIZE;
308 1.16.4.1 chs curoff = center->offset + incr;
309 1.6 mrg for ( ;(forward == 0 && curoff >= lo) ||
310 1.12 chs (forward && curoff < hi);
311 1.16.4.1 chs curoff += incr) {
312 1.6 mrg
313 1.6 mrg pclust = uvm_pagelookup(uobj, curoff); /* lookup page */
314 1.16.4.1 chs if (pclust == NULL) {
315 1.6 mrg break; /* no page */
316 1.16.4.1 chs }
317 1.6 mrg /* handle active pages */
318 1.6 mrg /* NOTE: inactive pages don't have pmap mappings */
319 1.6 mrg if ((pclust->pqflags & PQ_INACTIVE) == 0) {
320 1.16.4.1 chs if ((flags & PGO_DOACTCLUST) == 0) {
321 1.6 mrg /* dont want mapped pages at all */
322 1.6 mrg break;
323 1.16.4.1 chs }
324 1.6 mrg
325 1.6 mrg /* make sure "clean" bit is sync'd */
326 1.6 mrg if ((pclust->flags & PG_CLEANCHK) == 0) {
327 1.6 mrg if ((pclust->flags & (PG_CLEAN|PG_BUSY))
328 1.6 mrg == PG_CLEAN &&
329 1.6 mrg pmap_is_modified(PMAP_PGARG(pclust)))
330 1.6 mrg pclust->flags &= ~PG_CLEAN;
331 1.6 mrg /* now checked */
332 1.6 mrg pclust->flags |= PG_CLEANCHK;
333 1.6 mrg }
334 1.6 mrg }
335 1.16.4.1 chs
336 1.6 mrg /* is page available for cleaning and does it need it */
337 1.16.4.1 chs if ((pclust->flags & (PG_CLEAN|PG_BUSY)) != 0) {
338 1.6 mrg break; /* page is already clean or is busy */
339 1.16.4.1 chs }
340 1.16.4.1 chs
341 1.6 mrg /* yes! enroll the page in our array */
342 1.6 mrg pclust->flags |= PG_BUSY; /* busy! */
343 1.6 mrg UVM_PAGE_OWN(pclust, "uvm_mk_pcluster");
344 1.16.4.1 chs
345 1.6 mrg /* XXX: protect wired page? see above comment. */
346 1.6 mrg pmap_page_protect(PMAP_PGARG(pclust), VM_PROT_READ);
347 1.6 mrg if (!forward) {
348 1.6 mrg ppsp--; /* back up one page */
349 1.6 mrg *ppsp = pclust;
350 1.6 mrg } else {
351 1.6 mrg /* move forward one page */
352 1.6 mrg ppsp[*npages] = pclust;
353 1.6 mrg }
354 1.16.4.1 chs (*npages)++;
355 1.6 mrg }
356 1.6 mrg }
357 1.6 mrg
358 1.6 mrg /*
359 1.6 mrg * done! return the cluster array to the caller!!!
360 1.6 mrg */
361 1.1 mrg
362 1.6 mrg UVMHIST_LOG(maphist, "<- done",0,0,0,0);
363 1.6 mrg return(ppsp);
364 1.1 mrg }
365 1.1 mrg
366 1.1 mrg
367 1.1 mrg /*
368 1.1 mrg * uvm_shareprot: generic share protect routine
369 1.1 mrg *
370 1.1 mrg * => caller must lock map entry's map
371 1.1 mrg * => caller must lock object pointed to by map entry
372 1.1 mrg */
373 1.1 mrg
374 1.6 mrg void
375 1.6 mrg uvm_shareprot(entry, prot)
376 1.6 mrg vm_map_entry_t entry;
377 1.6 mrg vm_prot_t prot;
378 1.1 mrg {
379 1.6 mrg struct uvm_object *uobj = entry->object.uvm_obj;
380 1.6 mrg struct vm_page *pp;
381 1.16.4.7 chs voff_t start, stop;
382 1.6 mrg UVMHIST_FUNC("uvm_shareprot"); UVMHIST_CALLED(maphist);
383 1.6 mrg
384 1.11 chuck if (UVM_ET_ISSUBMAP(entry))
385 1.6 mrg panic("uvm_shareprot: non-object attached");
386 1.6 mrg
387 1.6 mrg start = entry->offset;
388 1.6 mrg stop = start + (entry->end - entry->start);
389 1.6 mrg
390 1.6 mrg /*
391 1.6 mrg * traverse list of pages in object. if page in range, pmap_prot it
392 1.6 mrg */
393 1.6 mrg
394 1.6 mrg for (pp = uobj->memq.tqh_first ; pp != NULL ; pp = pp->listq.tqe_next) {
395 1.6 mrg if (pp->offset >= start && pp->offset < stop)
396 1.6 mrg pmap_page_protect(PMAP_PGARG(pp), prot);
397 1.6 mrg }
398 1.6 mrg UVMHIST_LOG(maphist, "<- done",0,0,0,0);
399 1.1 mrg }
400 1.1 mrg
401 1.1 mrg /*
402 1.1 mrg * uvm_pager_put: high level pageout routine
403 1.1 mrg *
404 1.1 mrg * we want to pageout page "pg" to backing store, clustering if
405 1.1 mrg * possible.
406 1.1 mrg *
407 1.1 mrg * => page queues must be locked by caller
408 1.1 mrg * => if page is not swap-backed, then "uobj" points to the object
409 1.1 mrg * backing it. this object should be locked by the caller.
410 1.1 mrg * => if page is swap-backed, then "uobj" should be NULL.
411 1.1 mrg * => "pg" should be PG_BUSY (by caller), and !PG_CLEAN
412 1.1 mrg * for swap-backed memory, "pg" can be NULL if there is no page
413 1.1 mrg * of interest [sometimes the case for the pagedaemon]
414 1.1 mrg * => "ppsp_ptr" should point to an array of npages vm_page pointers
415 1.1 mrg * for possible cluster building
416 1.1 mrg * => flags (first two for non-swap-backed pages)
417 1.1 mrg * PGO_ALLPAGES: all pages in uobj are valid targets
418 1.1 mrg * PGO_DOACTCLUST: include "PQ_ACTIVE" pages as valid targets
419 1.1 mrg * PGO_SYNCIO: do SYNC I/O (no async)
420 1.1 mrg * PGO_PDFREECLUST: pagedaemon: drop cluster on successful I/O
421 1.1 mrg * => start/stop: if (uobj && !PGO_ALLPAGES) limit targets to this range
422 1.1 mrg * if (!uobj) start is the (daddr_t) of the starting swapblk
423 1.1 mrg * => return state:
424 1.1 mrg * 1. we return the VM_PAGER status code of the pageout
425 1.1 mrg * 2. we return with the page queues unlocked
426 1.1 mrg * 3. if (uobj != NULL) [!swap_backed] we return with
427 1.1 mrg * uobj locked _only_ if PGO_PDFREECLUST is set
428 1.1 mrg * AND result != VM_PAGER_PEND. in all other cases
429 1.1 mrg * we return with uobj unlocked. [this is a hack
430 1.1 mrg * that allows the pagedaemon to save one lock/unlock
431 1.1 mrg * pair in the !swap_backed case since we have to
432 1.1 mrg * lock the uobj to drop the cluster anyway]
433 1.1 mrg * 4. on errors we always drop the cluster. thus, if we return
434 1.1 mrg * !PEND, !OK, then the caller only has to worry about
435 1.1 mrg * un-busying the main page (not the cluster pages).
436 1.1 mrg * 5. on success, if !PGO_PDFREECLUST, we return the cluster
437 1.1 mrg * with all pages busy (caller must un-busy and check
438 1.1 mrg * wanted/released flags).
439 1.1 mrg */
440 1.1 mrg
441 1.6 mrg int
442 1.6 mrg uvm_pager_put(uobj, pg, ppsp_ptr, npages, flags, start, stop)
443 1.6 mrg struct uvm_object *uobj; /* IN */
444 1.6 mrg struct vm_page *pg, ***ppsp_ptr;/* IN, IN/OUT */
445 1.6 mrg int *npages; /* IN/OUT */
446 1.6 mrg int flags; /* IN */
447 1.16.4.7 chs voff_t start, stop; /* IN, IN */
448 1.6 mrg {
449 1.6 mrg int result;
450 1.6 mrg daddr_t swblk;
451 1.6 mrg struct vm_page **ppsp = *ppsp_ptr;
452 1.6 mrg
453 1.6 mrg /*
454 1.6 mrg * note that uobj is null if we are doing a swap-backed pageout.
455 1.6 mrg * note that uobj is !null if we are doing normal object pageout.
456 1.6 mrg * note that the page queues must be locked to cluster.
457 1.6 mrg */
458 1.6 mrg
459 1.6 mrg if (uobj) { /* if !swap-backed */
460 1.6 mrg
461 1.6 mrg /*
462 1.6 mrg * attempt to build a cluster for pageout using its
463 1.6 mrg * make-put-cluster function (if it has one).
464 1.6 mrg */
465 1.6 mrg
466 1.6 mrg if (uobj->pgops->pgo_mk_pcluster) {
467 1.6 mrg ppsp = uobj->pgops->pgo_mk_pcluster(uobj, ppsp,
468 1.6 mrg npages, pg, flags, start, stop);
469 1.6 mrg *ppsp_ptr = ppsp; /* update caller's pointer */
470 1.6 mrg } else {
471 1.6 mrg ppsp[0] = pg;
472 1.6 mrg *npages = 1;
473 1.16.4.1 chs }
474 1.6 mrg
475 1.6 mrg swblk = 0; /* XXX: keep gcc happy */
476 1.1 mrg
477 1.6 mrg } else {
478 1.1 mrg
479 1.6 mrg /*
480 1.6 mrg * for swap-backed pageout, the caller (the pagedaemon) has
481 1.6 mrg * already built the cluster for us. the starting swap
482 1.6 mrg * block we are writing to has been passed in as "start."
483 1.6 mrg * "pg" could be NULL if there is no page we are especially
484 1.6 mrg * interested in (in which case the whole cluster gets dropped
485 1.6 mrg * in the event of an error or a sync "done").
486 1.6 mrg */
487 1.6 mrg swblk = (daddr_t) start;
488 1.6 mrg /* ppsp and npages should be ok */
489 1.6 mrg }
490 1.1 mrg
491 1.6 mrg /* now that we've clustered we can unlock the page queues */
492 1.6 mrg uvm_unlock_pageq();
493 1.1 mrg
494 1.6 mrg /*
495 1.6 mrg * now attempt the I/O. if we have a failure and we are
496 1.6 mrg * clustered, we will drop the cluster and try again.
497 1.6 mrg */
498 1.1 mrg
499 1.1 mrg ReTry:
500 1.6 mrg if (uobj) {
501 1.6 mrg /* object is locked */
502 1.16.4.1 chs result = uobj->pgops->pgo_put(uobj, ppsp, *npages, flags);
503 1.6 mrg /* object is now unlocked */
504 1.6 mrg } else {
505 1.6 mrg /* nothing locked */
506 1.16.4.1 chs result = uvm_swap_put(swblk, ppsp, *npages, flags);
507 1.6 mrg /* nothing locked */
508 1.6 mrg }
509 1.6 mrg
510 1.6 mrg /*
511 1.6 mrg * we have attempted the I/O.
512 1.6 mrg *
513 1.6 mrg * if the I/O was a success then:
514 1.6 mrg * if !PGO_PDFREECLUST, we return the cluster to the
515 1.6 mrg * caller (who must un-busy all pages)
516 1.6 mrg * else we un-busy cluster pages for the pagedaemon
517 1.6 mrg *
518 1.6 mrg * if I/O is pending (async i/o) then we return the pending code.
519 1.6 mrg * [in this case the async i/o done function must clean up when
520 1.6 mrg * i/o is done...]
521 1.6 mrg */
522 1.6 mrg
523 1.6 mrg if (result == VM_PAGER_PEND || result == VM_PAGER_OK) {
524 1.6 mrg if (result == VM_PAGER_OK && (flags & PGO_PDFREECLUST)) {
525 1.6 mrg /*
526 1.6 mrg * drop cluster and relock object (only if I/O is
527 1.6 mrg * not pending)
528 1.6 mrg */
529 1.6 mrg if (uobj)
530 1.6 mrg /* required for dropcluster */
531 1.6 mrg simple_lock(&uobj->vmobjlock);
532 1.6 mrg if (*npages > 1 || pg == NULL)
533 1.6 mrg uvm_pager_dropcluster(uobj, pg, ppsp, npages,
534 1.6 mrg PGO_PDFREECLUST, 0);
535 1.6 mrg /* if (uobj): object still locked, as per
536 1.6 mrg * return-state item #3 */
537 1.6 mrg }
538 1.6 mrg return (result);
539 1.6 mrg }
540 1.6 mrg
541 1.6 mrg /*
542 1.6 mrg * a pager error occured. if we have clustered, we drop the
543 1.6 mrg * cluster and try again.
544 1.6 mrg */
545 1.6 mrg
546 1.6 mrg if (*npages > 1 || pg == NULL) {
547 1.6 mrg if (uobj)
548 1.6 mrg simple_lock(&uobj->vmobjlock);
549 1.6 mrg uvm_pager_dropcluster(uobj, pg, ppsp, npages, PGO_REALLOCSWAP,
550 1.6 mrg swblk);
551 1.6 mrg if (pg != NULL)
552 1.6 mrg goto ReTry;
553 1.6 mrg }
554 1.6 mrg
555 1.6 mrg /*
556 1.6 mrg * a pager error occured (even after dropping the cluster, if there
557 1.6 mrg * was one). give up! the caller only has one page ("pg")
558 1.6 mrg * to worry about.
559 1.6 mrg */
560 1.6 mrg
561 1.6 mrg if (uobj && (flags & PGO_PDFREECLUST) != 0)
562 1.6 mrg simple_lock(&uobj->vmobjlock);
563 1.6 mrg return(result);
564 1.1 mrg }
565 1.1 mrg
566 1.1 mrg /*
567 1.1 mrg * uvm_pager_dropcluster: drop a cluster we have built (because we
568 1.1 mrg * got an error, or, if PGO_PDFREECLUST we are un-busying the
569 1.1 mrg * cluster pages on behalf of the pagedaemon).
570 1.1 mrg *
571 1.1 mrg * => uobj, if non-null, is a non-swap-backed object that is
572 1.1 mrg * locked by the caller. we return with this object still
573 1.1 mrg * locked.
574 1.1 mrg * => page queues are not locked
575 1.1 mrg * => pg is our page of interest (the one we clustered around, can be null)
576 1.1 mrg * => ppsp/npages is our current cluster
577 1.1 mrg * => flags: PGO_PDFREECLUST: pageout was a success: un-busy cluster
578 1.1 mrg * pages on behalf of the pagedaemon.
579 1.1 mrg * PGO_REALLOCSWAP: drop previously allocated swap slots for
580 1.1 mrg * clustered swap-backed pages (except for "pg" if !NULL)
581 1.1 mrg * "swblk" is the start of swap alloc (e.g. for ppsp[0])
582 1.1 mrg * [only meaningful if swap-backed (uobj == NULL)]
583 1.1 mrg */
584 1.1 mrg
585 1.1 mrg
586 1.16.4.1 chs void
587 1.16.4.1 chs uvm_pager_dropcluster(uobj, pg, ppsp, npages, flags, swblk)
588 1.16.4.1 chs struct uvm_object *uobj; /* IN */
589 1.16.4.1 chs struct vm_page *pg, **ppsp; /* IN, IN/OUT */
590 1.16.4.1 chs int *npages; /* IN/OUT */
591 1.16.4.1 chs int flags;
592 1.16.4.1 chs int swblk; /* valid if (uobj == NULL &&
593 1.16.4.1 chs PGO_REALLOCSWAP) */
594 1.1 mrg {
595 1.6 mrg int lcv;
596 1.6 mrg boolean_t obj_is_alive;
597 1.7 chuck struct uvm_object *saved_uobj;
598 1.1 mrg
599 1.6 mrg /*
600 1.6 mrg * if we need to reallocate swap space for the cluster we are dropping
601 1.6 mrg * (true if swap-backed and PGO_REALLOCSWAP) then free the old
602 1.6 mrg * allocation now. save a block for "pg" if it is non-NULL.
603 1.6 mrg *
604 1.6 mrg * note that we will zap the object's pointer to swap in the "for" loop
605 1.6 mrg * below...
606 1.6 mrg */
607 1.6 mrg
608 1.6 mrg if (uobj == NULL && (flags & PGO_REALLOCSWAP)) {
609 1.6 mrg if (pg)
610 1.6 mrg uvm_swap_free(swblk + 1, *npages - 1);
611 1.6 mrg else
612 1.6 mrg uvm_swap_free(swblk, *npages);
613 1.6 mrg }
614 1.6 mrg
615 1.6 mrg /*
616 1.6 mrg * drop all pages but "pg"
617 1.6 mrg */
618 1.1 mrg
619 1.6 mrg for (lcv = 0 ; lcv < *npages ; lcv++) {
620 1.1 mrg
621 1.16.4.1 chs /* skip "pg" or empty slot */
622 1.16.4.1 chs if (ppsp[lcv] == pg || ppsp[lcv] == NULL)
623 1.6 mrg continue;
624 1.1 mrg
625 1.6 mrg /*
626 1.6 mrg * if swap-backed, gain lock on object that owns page. note
627 1.6 mrg * that PQ_ANON bit can't change as long as we are holding
628 1.6 mrg * the PG_BUSY bit (so there is no need to lock the page
629 1.6 mrg * queues to test it).
630 1.6 mrg *
631 1.6 mrg * once we have the lock, dispose of the pointer to swap, if
632 1.6 mrg * requested
633 1.6 mrg */
634 1.6 mrg if (!uobj) {
635 1.6 mrg if (ppsp[lcv]->pqflags & PQ_ANON) {
636 1.6 mrg simple_lock(&ppsp[lcv]->uanon->an_lock);
637 1.6 mrg if (flags & PGO_REALLOCSWAP)
638 1.6 mrg /* zap swap block */
639 1.6 mrg ppsp[lcv]->uanon->an_swslot = 0;
640 1.6 mrg } else {
641 1.6 mrg simple_lock(&ppsp[lcv]->uobject->vmobjlock);
642 1.6 mrg if (flags & PGO_REALLOCSWAP)
643 1.6 mrg uao_set_swslot(ppsp[lcv]->uobject,
644 1.12 chs ppsp[lcv]->offset >> PAGE_SHIFT, 0);
645 1.6 mrg }
646 1.6 mrg }
647 1.6 mrg
648 1.6 mrg /* did someone want the page while we had it busy-locked? */
649 1.16.4.1 chs if (ppsp[lcv]->flags & PG_WANTED) {
650 1.6 mrg /* still holding obj lock */
651 1.16.4.1 chs wakeup(ppsp[lcv]);
652 1.16.4.1 chs }
653 1.6 mrg
654 1.6 mrg /* if page was released, release it. otherwise un-busy it */
655 1.6 mrg if (ppsp[lcv]->flags & PG_RELEASED) {
656 1.6 mrg
657 1.6 mrg if (ppsp[lcv]->pqflags & PQ_ANON) {
658 1.6 mrg /* so that anfree will free */
659 1.6 mrg ppsp[lcv]->flags &= ~(PG_BUSY);
660 1.6 mrg UVM_PAGE_OWN(ppsp[lcv], NULL);
661 1.6 mrg
662 1.6 mrg pmap_page_protect(PMAP_PGARG(ppsp[lcv]),
663 1.6 mrg VM_PROT_NONE); /* be safe */
664 1.13 chs simple_unlock(&ppsp[lcv]->uanon->an_lock);
665 1.6 mrg /* kills anon and frees pg */
666 1.13 chs uvm_anfree(ppsp[lcv]->uanon);
667 1.6 mrg
668 1.6 mrg continue;
669 1.6 mrg }
670 1.6 mrg
671 1.6 mrg /*
672 1.6 mrg * pgo_releasepg will dump the page for us
673 1.6 mrg */
674 1.1 mrg
675 1.1 mrg #ifdef DIAGNOSTIC
676 1.6 mrg if (ppsp[lcv]->uobject->pgops->pgo_releasepg == NULL)
677 1.6 mrg panic("uvm_pager_dropcluster: no releasepg "
678 1.6 mrg "function");
679 1.1 mrg #endif
680 1.7 chuck saved_uobj = ppsp[lcv]->uobject;
681 1.6 mrg obj_is_alive =
682 1.7 chuck saved_uobj->pgops->pgo_releasepg(ppsp[lcv], NULL);
683 1.6 mrg
684 1.1 mrg #ifdef DIAGNOSTIC
685 1.6 mrg /* for normal objects, "pg" is still PG_BUSY by us,
686 1.6 mrg * so obj can't die */
687 1.6 mrg if (uobj && !obj_is_alive)
688 1.6 mrg panic("uvm_pager_dropcluster: object died "
689 1.6 mrg "with active page");
690 1.1 mrg #endif
691 1.7 chuck /* only unlock the object if it is still alive... */
692 1.7 chuck if (obj_is_alive && saved_uobj != uobj)
693 1.7 chuck simple_unlock(&saved_uobj->vmobjlock);
694 1.7 chuck
695 1.7 chuck /*
696 1.7 chuck * XXXCDC: suppose uobj died in the pgo_releasepg?
697 1.7 chuck * how pass that
698 1.7 chuck * info up to caller. we are currently ignoring it...
699 1.7 chuck */
700 1.7 chuck
701 1.7 chuck continue; /* next page */
702 1.1 mrg
703 1.6 mrg } else {
704 1.16.4.1 chs ppsp[lcv]->flags &= ~(PG_BUSY|PG_WANTED|PG_FAKE);
705 1.6 mrg UVM_PAGE_OWN(ppsp[lcv], NULL);
706 1.6 mrg }
707 1.6 mrg
708 1.6 mrg /*
709 1.6 mrg * if we are operating on behalf of the pagedaemon and we
710 1.6 mrg * had a successful pageout update the page!
711 1.6 mrg */
712 1.6 mrg if (flags & PGO_PDFREECLUST) {
713 1.6 mrg pmap_clear_reference(PMAP_PGARG(ppsp[lcv]));
714 1.6 mrg pmap_clear_modify(PMAP_PGARG(ppsp[lcv]));
715 1.6 mrg ppsp[lcv]->flags |= PG_CLEAN;
716 1.6 mrg }
717 1.6 mrg
718 1.6 mrg /* if anonymous cluster, unlock object and move on */
719 1.6 mrg if (!uobj) {
720 1.6 mrg if (ppsp[lcv]->pqflags & PQ_ANON)
721 1.6 mrg simple_unlock(&ppsp[lcv]->uanon->an_lock);
722 1.6 mrg else
723 1.6 mrg simple_unlock(&ppsp[lcv]->uobject->vmobjlock);
724 1.6 mrg }
725 1.1 mrg
726 1.6 mrg }
727 1.6 mrg
728 1.6 mrg /*
729 1.6 mrg * drop to a cluster of 1 page ("pg") if requested
730 1.6 mrg */
731 1.6 mrg
732 1.6 mrg if (pg && (flags & PGO_PDFREECLUST) == 0) {
733 1.6 mrg /*
734 1.6 mrg * if we are not a successful pageout, we make a 1 page cluster.
735 1.6 mrg */
736 1.6 mrg ppsp[0] = pg;
737 1.6 mrg *npages = 1;
738 1.6 mrg
739 1.6 mrg /*
740 1.6 mrg * assign new swap block to new cluster, if anon backed
741 1.6 mrg */
742 1.6 mrg if (uobj == NULL && (flags & PGO_REALLOCSWAP)) {
743 1.6 mrg if (pg->pqflags & PQ_ANON) {
744 1.6 mrg simple_lock(&pg->uanon->an_lock);
745 1.6 mrg pg->uanon->an_swslot = swblk; /* reassign */
746 1.6 mrg simple_unlock(&pg->uanon->an_lock);
747 1.6 mrg } else {
748 1.6 mrg simple_lock(&pg->uobject->vmobjlock);
749 1.6 mrg uao_set_swslot(pg->uobject,
750 1.12 chs pg->offset >> PAGE_SHIFT, swblk);
751 1.6 mrg simple_unlock(&pg->uobject->vmobjlock);
752 1.6 mrg }
753 1.6 mrg }
754 1.6 mrg }
755 1.16.4.1 chs }
756 1.16.4.1 chs
757 1.16.4.4 chs /*
758 1.16.4.4 chs * interrupt-context iodone handler for nested i/o bufs.
759 1.16.4.4 chs *
760 1.16.4.4 chs * => must be at splbio().
761 1.16.4.4 chs */
762 1.16.4.4 chs
763 1.16.4.1 chs void
764 1.16.4.3 chs uvm_aio_biodone1(bp)
765 1.16.4.3 chs struct buf *bp;
766 1.16.4.3 chs {
767 1.16.4.3 chs struct buf *mbp = bp->b_private;
768 1.16.4.3 chs
769 1.16.4.4 chs #ifdef DIAGNOSTIC
770 1.16.4.3 chs if (mbp == bp) {
771 1.16.4.3 chs panic("uvm_aio_biodone1: mbp == bp %p", bp);
772 1.16.4.3 chs }
773 1.16.4.4 chs #endif
774 1.16.4.3 chs
775 1.16.4.3 chs if (bp->b_flags & B_ERROR) {
776 1.16.4.3 chs mbp->b_flags |= B_ERROR;
777 1.16.4.3 chs mbp->b_error = bp->b_error;
778 1.16.4.3 chs }
779 1.16.4.4 chs mbp->b_resid -= bp->b_bcount;
780 1.16.4.3 chs pool_put(&bufpool, bp);
781 1.16.4.4 chs if (mbp->b_resid == 0) {
782 1.16.4.3 chs biodone(mbp);
783 1.16.4.3 chs }
784 1.16.4.3 chs }
785 1.16.4.3 chs
786 1.16.4.4 chs /*
787 1.16.4.4 chs * interrupt-context iodone handler for single-buf i/os
788 1.16.4.4 chs * or the top-level buf of a nested-buf i/o.
789 1.16.4.4 chs *
790 1.16.4.4 chs * => must be at splbio().
791 1.16.4.4 chs */
792 1.16.4.4 chs
793 1.16.4.3 chs void
794 1.16.4.1 chs uvm_aio_biodone(bp)
795 1.16.4.1 chs struct buf *bp;
796 1.16.4.1 chs {
797 1.16.4.4 chs /* reset b_iodone for when this is a single-buf i/o. */
798 1.16.4.3 chs bp->b_iodone = uvm_aio_aiodone;
799 1.16.4.1 chs
800 1.16.4.1 chs simple_lock(&uvm.aiodoned_lock); /* locks uvm.aio_done */
801 1.16.4.3 chs TAILQ_INSERT_TAIL(&uvm.aio_done, bp, b_freelist);
802 1.16.4.1 chs wakeup(&uvm.aiodoned);
803 1.16.4.1 chs simple_unlock(&uvm.aiodoned_lock);
804 1.16.4.1 chs }
805 1.16.4.1 chs
806 1.16.4.4 chs /*
807 1.16.4.5 chs * uvm_aio_aiodone: do iodone processing for async i/os.
808 1.16.4.4 chs * this should be called in thread context, not interrupt context.
809 1.16.4.4 chs */
810 1.16.4.4 chs
811 1.16.4.1 chs void
812 1.16.4.3 chs uvm_aio_aiodone(bp)
813 1.16.4.3 chs struct buf *bp;
814 1.16.4.1 chs {
815 1.16.4.5 chs int npages = bp->b_bufsize >> PAGE_SHIFT;
816 1.16.4.5 chs struct vm_page *pg, *pgs[npages];
817 1.16.4.5 chs struct uvm_object *uobj;
818 1.16.4.1 chs int s, i;
819 1.16.4.5 chs boolean_t release, write, swap;
820 1.16.4.5 chs UVMHIST_FUNC("uvm_aio_aiodone"); UVMHIST_CALLED(ubchist);
821 1.16.4.5 chs UVMHIST_LOG(ubchist, "bp %p", bp, 0,0,0);
822 1.16.4.1 chs
823 1.16.4.3 chs release = (bp->b_flags & (B_ERROR|B_READ)) == (B_ERROR|B_READ);
824 1.16.4.5 chs write = (bp->b_flags & B_READ) == 0;
825 1.16.4.5 chs uobj = NULL;
826 1.16.4.5 chs for (i = 0; i < npages; i++) {
827 1.16.4.3 chs pgs[i] = uvm_pageratop((vaddr_t)bp->b_data + (i << PAGE_SHIFT));
828 1.16.4.5 chs }
829 1.16.4.5 chs uvm_pagermapout((vaddr_t)bp->b_data, npages);
830 1.16.4.5 chs for (i = 0; i < npages; i++) {
831 1.16.4.5 chs pg = pgs[i];
832 1.16.4.5 chs
833 1.16.4.5 chs if (i == 0) {
834 1.16.4.5 chs swap = (pg->pqflags & PQ_SWAPBACKED) != 0;
835 1.16.4.5 chs if (!swap) {
836 1.16.4.5 chs uobj = pg->uobject;
837 1.16.4.5 chs simple_lock(&uobj->vmobjlock);
838 1.16.4.5 chs }
839 1.16.4.5 chs }
840 1.16.4.5 chs #ifdef DIAGNOSTIC
841 1.16.4.5 chs if (!swap && pg->uobject != uobj) {
842 1.16.4.5 chs panic("uvm_aio_aiodone: mismatched pg %d %p uobj %p",
843 1.16.4.5 chs i, pg, uobj);
844 1.16.4.5 chs }
845 1.16.4.5 chs #endif
846 1.16.4.5 chs
847 1.16.4.5 chs if (swap) {
848 1.16.4.5 chs if (pg->pqflags & PQ_ANON) {
849 1.16.4.5 chs simple_lock(&pg->uanon->an_lock);
850 1.16.4.5 chs } else {
851 1.16.4.5 chs simple_lock(&pg->uobject->vmobjlock);
852 1.16.4.5 chs }
853 1.16.4.5 chs }
854 1.16.4.1 chs
855 1.16.4.1 chs /*
856 1.16.4.5 chs * if this is a read and we got an error, mark the pages
857 1.16.4.5 chs * PG_RELEASED so that uvm_page_unbusy() will free them.
858 1.16.4.1 chs */
859 1.16.4.1 chs
860 1.16.4.1 chs if (release) {
861 1.16.4.5 chs if (pg->pqflags & PQ_ANON) {
862 1.16.4.5 chs pg->flags &= ~(PG_BUSY);
863 1.16.4.5 chs UVM_PAGE_OWN(pg, NULL);
864 1.16.4.5 chs simple_unlock(&pg->uanon->an_lock);
865 1.16.4.5 chs uvm_anfree(pg->uanon);
866 1.16.4.5 chs } else {
867 1.16.4.5 chs uobj->pgops->pgo_releasepg(pg, NULL);
868 1.16.4.5 chs if (swap) {
869 1.16.4.5 chs simple_unlock(&pg->uobject->vmobjlock);
870 1.16.4.5 chs }
871 1.16.4.5 chs }
872 1.16.4.5 chs continue;
873 1.16.4.5 chs }
874 1.16.4.5 chs
875 1.16.4.5 chs #ifdef DIAGNOSTIC
876 1.16.4.5 chs if (write && pgs[i]->flags & PG_FAKE) {
877 1.16.4.5 chs panic("uvm_aio_aiodone: wrote PG_FAKE page %p", pgs[i]);
878 1.16.4.5 chs }
879 1.16.4.5 chs #endif
880 1.16.4.5 chs
881 1.16.4.5 chs /*
882 1.16.4.5 chs * if this is a read and the page is PG_FAKE
883 1.16.4.5 chs * or this was a write, mark the page PG_CLEAN and not PG_FAKE.
884 1.16.4.5 chs */
885 1.16.4.5 chs
886 1.16.4.5 chs if (pgs[i]->flags & PG_FAKE || write) {
887 1.16.4.5 chs pmap_clear_reference(PMAP_PGARG(pgs[i]));
888 1.16.4.5 chs pmap_clear_modify(PMAP_PGARG(pgs[i]));
889 1.16.4.5 chs pgs[i]->flags |= PG_CLEAN;
890 1.16.4.5 chs pgs[i]->flags &= ~PG_FAKE;
891 1.16.4.1 chs }
892 1.16.4.5 chs if (swap) {
893 1.16.4.5 chs if (pg->pqflags & PQ_ANON) {
894 1.16.4.5 chs simple_unlock(&pg->uanon->an_lock);
895 1.16.4.5 chs } else {
896 1.16.4.5 chs simple_unlock(&pg->uobject->vmobjlock);
897 1.16.4.5 chs }
898 1.16.4.5 chs }
899 1.16.4.5 chs }
900 1.16.4.5 chs uvm_page_unbusy(pgs, npages);
901 1.16.4.5 chs if (!swap) {
902 1.16.4.5 chs simple_unlock(&uobj->vmobjlock);
903 1.16.4.1 chs }
904 1.16.4.1 chs
905 1.16.4.1 chs s = splbio();
906 1.16.4.3 chs pool_put(&bufpool, bp);
907 1.16.4.1 chs splx(s);
908 1.16.4.4 chs }
909 1.16.4.4 chs
910 1.16.4.4 chs /*
911 1.16.4.4 chs * translate unix errno values to VM_PAGER_*.
912 1.16.4.4 chs */
913 1.16.4.4 chs
914 1.16.4.4 chs int
915 1.16.4.4 chs uvm_errno2vmerror(errno)
916 1.16.4.4 chs int errno;
917 1.16.4.4 chs {
918 1.16.4.4 chs switch (errno) {
919 1.16.4.4 chs case 0:
920 1.16.4.4 chs return VM_PAGER_OK;
921 1.16.4.4 chs case EINVAL:
922 1.16.4.4 chs return VM_PAGER_BAD;
923 1.16.4.4 chs case EINPROGRESS:
924 1.16.4.4 chs return VM_PAGER_PEND;
925 1.16.4.4 chs case EIO:
926 1.16.4.4 chs return VM_PAGER_ERROR;
927 1.16.4.4 chs case EAGAIN:
928 1.16.4.4 chs return VM_PAGER_AGAIN;
929 1.16.4.4 chs case EBUSY:
930 1.16.4.4 chs return VM_PAGER_UNLOCK;
931 1.16.4.4 chs default:
932 1.16.4.4 chs return VM_PAGER_ERROR;
933 1.16.4.4 chs }
934 1.1 mrg }
935