xref: /freebsd/sys/vm/vnode_pager.c (revision 420e2f8a74df4be1237244a4ef222d2ceae6823d)
1 /*-
2  * SPDX-License-Identifier: BSD-4-Clause
3  *
4  * Copyright (c) 1990 University of Utah.
5  * Copyright (c) 1991 The Regents of the University of California.
6  * All rights reserved.
7  * Copyright (c) 1993, 1994 John S. Dyson
8  * Copyright (c) 1995, David Greenman
9  *
10  * This code is derived from software contributed to Berkeley by
11  * the Systems Programming Group of the University of Utah Computer
12  * Science Department.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  * 3. All advertising materials mentioning features or use of this software
23  *    must display the following acknowledgement:
24  *	This product includes software developed by the University of
25  *	California, Berkeley and its contributors.
26  * 4. Neither the name of the University nor the names of its contributors
27  *    may be used to endorse or promote products derived from this software
28  *    without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40  * SUCH DAMAGE.
41  */
42 
43 /*
44  * Page to/from files (vnodes).
45  */
46 
47 /*
48  * TODO:
49  *	Implement VOP_GETPAGES/PUTPAGES interface for filesystems. Will
50  *	greatly re-simplify the vnode_pager.
51  */
52 
53 #include <sys/cdefs.h>
54 #include "opt_vm.h"
55 
56 #include <sys/param.h>
57 #include <sys/kernel.h>
58 #include <sys/systm.h>
59 #include <sys/sysctl.h>
60 #include <sys/proc.h>
61 #include <sys/vnode.h>
62 #include <sys/mount.h>
63 #include <sys/bio.h>
64 #include <sys/buf.h>
65 #include <sys/vmmeter.h>
66 #include <sys/ktr.h>
67 #include <sys/limits.h>
68 #include <sys/conf.h>
69 #include <sys/refcount.h>
70 #include <sys/rwlock.h>
71 #include <sys/sf_buf.h>
72 #include <sys/domainset.h>
73 #include <sys/user.h>
74 
75 #include <machine/atomic.h>
76 
77 #include <vm/vm.h>
78 #include <vm/vm_param.h>
79 #include <vm/vm_object.h>
80 #include <vm/vm_page.h>
81 #include <vm/vm_pager.h>
82 #include <vm/vm_map.h>
83 #include <vm/vnode_pager.h>
84 #include <vm/vm_extern.h>
85 #include <vm/uma.h>
86 
87 static int vnode_pager_addr(struct vnode *vp, vm_ooffset_t address,
88     daddr_t *rtaddress, int *run);
89 static int vnode_pager_input_smlfs(vm_object_t object, vm_page_t m);
90 static int vnode_pager_input_old(vm_object_t object, vm_page_t m);
91 static void vnode_pager_dealloc(vm_object_t);
92 static int vnode_pager_getpages(vm_object_t, vm_page_t *, int, int *, int *);
93 static int vnode_pager_getpages_async(vm_object_t, vm_page_t *, int, int *,
94     int *, vop_getpages_iodone_t, void *);
95 static void vnode_pager_putpages(vm_object_t, vm_page_t *, int, int, int *);
96 static boolean_t vnode_pager_haspage(vm_object_t, vm_pindex_t, int *, int *);
97 static vm_object_t vnode_pager_alloc(void *, vm_ooffset_t, vm_prot_t,
98     vm_ooffset_t, struct ucred *cred);
99 static int vnode_pager_generic_getpages_done(struct buf *);
100 static void vnode_pager_generic_getpages_done_async(struct buf *);
101 static void vnode_pager_update_writecount(vm_object_t, vm_offset_t,
102     vm_offset_t);
103 static void vnode_pager_release_writecount(vm_object_t, vm_offset_t,
104     vm_offset_t);
105 static void vnode_pager_getvp(vm_object_t, struct vnode **, bool *);
106 
107 const struct pagerops vnodepagerops = {
108 	.pgo_kvme_type = KVME_TYPE_VNODE,
109 	.pgo_alloc =	vnode_pager_alloc,
110 	.pgo_dealloc =	vnode_pager_dealloc,
111 	.pgo_getpages =	vnode_pager_getpages,
112 	.pgo_getpages_async = vnode_pager_getpages_async,
113 	.pgo_putpages =	vnode_pager_putpages,
114 	.pgo_haspage =	vnode_pager_haspage,
115 	.pgo_update_writecount = vnode_pager_update_writecount,
116 	.pgo_release_writecount = vnode_pager_release_writecount,
117 	.pgo_set_writeable_dirty = vm_object_set_writeable_dirty_,
118 	.pgo_mightbedirty = vm_object_mightbedirty_,
119 	.pgo_getvp = vnode_pager_getvp,
120 };
121 
122 static struct domainset *vnode_domainset = NULL;
123 
124 SYSCTL_PROC(_debug, OID_AUTO, vnode_domainset,
125     CTLTYPE_STRING | CTLFLAG_MPSAFE | CTLFLAG_RW, &vnode_domainset, 0,
126     sysctl_handle_domainset, "A", "Default vnode NUMA policy");
127 
128 static int nvnpbufs;
129 SYSCTL_INT(_vm, OID_AUTO, vnode_pbufs, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
130     &nvnpbufs, 0, "number of physical buffers allocated for vnode pager");
131 
132 static uma_zone_t vnode_pbuf_zone;
133 
134 static void
vnode_pager_init(void * dummy)135 vnode_pager_init(void *dummy)
136 {
137 
138 #ifdef __LP64__
139 	nvnpbufs = nswbuf * 2;
140 #else
141 	nvnpbufs = nswbuf / 2;
142 #endif
143 	TUNABLE_INT_FETCH("vm.vnode_pbufs", &nvnpbufs);
144 	vnode_pbuf_zone = pbuf_zsecond_create("vnpbuf", nvnpbufs);
145 }
146 SYSINIT(vnode_pager, SI_SUB_CPU, SI_ORDER_ANY, vnode_pager_init, NULL);
147 
148 /* Create the VM system backing object for this vnode */
149 static int
vnode_create_vobject_any(struct vnode * vp,off_t isize,struct thread * td)150 vnode_create_vobject_any(struct vnode *vp, off_t isize, struct thread *td)
151 {
152 	vm_object_t object;
153 	vm_ooffset_t size;
154 	bool last;
155 
156 	object = vp->v_object;
157 	if (object != NULL)
158 		return (0);
159 
160 	if (isize == VNODE_NO_SIZE) {
161 		if (vn_getsize_locked(vp, &size, td->td_ucred) != 0)
162 			return (0);
163 	} else {
164 		size = isize;
165 	}
166 
167 	object = vnode_pager_alloc(vp, size, 0, 0, td->td_ucred);
168 	/*
169 	 * Dereference the reference we just created.  This assumes
170 	 * that the object is associated with the vp.  We still have
171 	 * to serialize with vnode_pager_dealloc() for the last
172 	 * potential reference.
173 	 */
174 	VM_OBJECT_RLOCK(object);
175 	last = refcount_release(&object->ref_count);
176 	VM_OBJECT_RUNLOCK(object);
177 	if (last)
178 		vrele(vp);
179 
180 	VNASSERT(vp->v_object != NULL, vp, ("%s: NULL object", __func__));
181 
182 	return (0);
183 }
184 
185 int
vnode_create_vobject(struct vnode * vp,off_t isize,struct thread * td)186 vnode_create_vobject(struct vnode *vp, off_t isize, struct thread *td)
187 {
188 	VNASSERT(!vn_isdisk(vp), vp, ("%s: disk vnode", __func__));
189 	VNASSERT(isize == VNODE_NO_SIZE || isize >= 0, vp,
190 	    ("%s: invalid size (%jd)", __func__, (intmax_t)isize));
191 
192 	if (!vn_canvmio(vp))
193 		return (0);
194 
195 	return (vnode_create_vobject_any(vp, isize, td));
196 }
197 
198 int
vnode_create_disk_vobject(struct vnode * vp,off_t isize,struct thread * td)199 vnode_create_disk_vobject(struct vnode *vp, off_t isize, struct thread *td)
200 {
201 	VNASSERT(isize > 0, vp, ("%s: invalid size (%jd)", __func__,
202 	    (intmax_t)isize));
203 
204 	return (vnode_create_vobject_any(vp, isize, td));
205 }
206 
207 void
vnode_destroy_vobject(struct vnode * vp)208 vnode_destroy_vobject(struct vnode *vp)
209 {
210 	struct vm_object *obj;
211 
212 	obj = vp->v_object;
213 	if (obj == NULL || obj->handle != vp)
214 		return;
215 	ASSERT_VOP_ELOCKED(vp, "vnode_destroy_vobject");
216 	VM_OBJECT_WLOCK(obj);
217 	MPASS(obj->type == OBJT_VNODE);
218 	umtx_shm_object_terminated(obj);
219 	if (obj->ref_count == 0) {
220 		KASSERT((obj->flags & OBJ_DEAD) == 0,
221 		   ("vnode_destroy_vobject: Terminating dead object"));
222 		vm_object_set_flag(obj, OBJ_DEAD);
223 
224 		/*
225 		 * Clean pages and flush buffers.
226 		 */
227 		vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
228 		VM_OBJECT_WUNLOCK(obj);
229 
230 		vinvalbuf(vp, V_SAVE, 0, 0);
231 
232 		BO_LOCK(&vp->v_bufobj);
233 		vp->v_bufobj.bo_flag |= BO_DEAD;
234 		BO_UNLOCK(&vp->v_bufobj);
235 
236 		VM_OBJECT_WLOCK(obj);
237 		vm_object_terminate(obj);
238 	} else {
239 		/*
240 		 * Woe to the process that tries to page now :-).
241 		 */
242 		vm_pager_deallocate(obj);
243 		VM_OBJECT_WUNLOCK(obj);
244 	}
245 	KASSERT(vp->v_object == NULL, ("vp %p obj %p", vp, vp->v_object));
246 }
247 
248 /*
249  * Allocate (or lookup) pager for a vnode.
250  * Handle is a vnode pointer.
251  */
252 vm_object_t
vnode_pager_alloc(void * handle,vm_ooffset_t size,vm_prot_t prot,vm_ooffset_t offset,struct ucred * cred)253 vnode_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
254     vm_ooffset_t offset, struct ucred *cred)
255 {
256 	vm_object_t object;
257 	struct vnode *vp;
258 
259 	/*
260 	 * Pageout to vnode, no can do yet.
261 	 */
262 	if (handle == NULL)
263 		return (NULL);
264 
265 	vp = (struct vnode *)handle;
266 	ASSERT_VOP_LOCKED(vp, "vnode_pager_alloc");
267 	VNPASS(vp->v_usecount > 0, vp);
268 retry:
269 	object = vp->v_object;
270 
271 	if (object == NULL) {
272 		/*
273 		 * Add an object of the appropriate size
274 		 */
275 		object = vm_object_allocate(OBJT_VNODE,
276 		    OFF_TO_IDX(round_page(size)));
277 
278 		object->un_pager.vnp.vnp_size = size;
279 		object->un_pager.vnp.writemappings = 0;
280 		object->domain.dr_policy = vnode_domainset;
281 		object->handle = handle;
282 		if ((vp->v_vflag & VV_VMSIZEVNLOCK) != 0) {
283 			VM_OBJECT_WLOCK(object);
284 			vm_object_set_flag(object, OBJ_SIZEVNLOCK);
285 			VM_OBJECT_WUNLOCK(object);
286 		}
287 		VI_LOCK(vp);
288 		if (vp->v_object != NULL) {
289 			/*
290 			 * Object has been created while we were allocating.
291 			 */
292 			VI_UNLOCK(vp);
293 			VM_OBJECT_WLOCK(object);
294 			KASSERT(object->ref_count == 1,
295 			    ("leaked ref %p %d", object, object->ref_count));
296 			object->type = OBJT_DEAD;
297 			refcount_init(&object->ref_count, 0);
298 			VM_OBJECT_WUNLOCK(object);
299 			vm_object_destroy(object);
300 			goto retry;
301 		}
302 		vp->v_object = object;
303 		VI_UNLOCK(vp);
304 		vrefact(vp);
305 	} else {
306 		vm_object_reference(object);
307 #if VM_NRESERVLEVEL > 0
308 		if ((object->flags & OBJ_COLORED) == 0) {
309 			VM_OBJECT_WLOCK(object);
310 			vm_object_color(object, 0);
311 			VM_OBJECT_WUNLOCK(object);
312 		}
313 #endif
314 	}
315 	return (object);
316 }
317 
318 /*
319  *	The object must be locked.
320  */
321 static void
vnode_pager_dealloc(vm_object_t object)322 vnode_pager_dealloc(vm_object_t object)
323 {
324 	struct vnode *vp;
325 	int refs;
326 
327 	vp = object->handle;
328 	if (vp == NULL)
329 		panic("vnode_pager_dealloc: pager already dealloced");
330 
331 	VM_OBJECT_ASSERT_WLOCKED(object);
332 	vm_object_pip_wait(object, "vnpdea");
333 	refs = object->ref_count;
334 
335 	object->handle = NULL;
336 	object->type = OBJT_DEAD;
337 	ASSERT_VOP_ELOCKED(vp, "vnode_pager_dealloc");
338 	if (object->un_pager.vnp.writemappings > 0) {
339 		object->un_pager.vnp.writemappings = 0;
340 		VOP_ADD_WRITECOUNT_CHECKED(vp, -1);
341 		CTR3(KTR_VFS, "%s: vp %p v_writecount decreased to %d",
342 		    __func__, vp, vp->v_writecount);
343 	}
344 	vp->v_object = NULL;
345 	VI_LOCK(vp);
346 
347 	/*
348 	 * vm_map_entry_set_vnode_text() cannot reach this vnode by
349 	 * following object->handle.  Clear all text references now.
350 	 * This also clears the transient references from
351 	 * kern_execve(), which is fine because dead_vnodeops uses nop
352 	 * for VOP_UNSET_TEXT().
353 	 */
354 	if (vp->v_writecount < 0)
355 		vp->v_writecount = 0;
356 	VI_UNLOCK(vp);
357 	VM_OBJECT_WUNLOCK(object);
358 	if (refs > 0)
359 		vunref(vp);
360 	VM_OBJECT_WLOCK(object);
361 }
362 
363 static boolean_t
vnode_pager_haspage(vm_object_t object,vm_pindex_t pindex,int * before,int * after)364 vnode_pager_haspage(vm_object_t object, vm_pindex_t pindex, int *before,
365     int *after)
366 {
367 	struct vnode *vp = object->handle;
368 	daddr_t bn;
369 	uintptr_t lockstate;
370 	int err;
371 	daddr_t reqblock;
372 	int poff;
373 	int bsize;
374 	int pagesperblock, blocksperpage;
375 
376 	VM_OBJECT_ASSERT_LOCKED(object);
377 	/*
378 	 * If no vp or vp is doomed or marked transparent to VM, we do not
379 	 * have the page.
380 	 */
381 	if (vp == NULL || VN_IS_DOOMED(vp))
382 		return FALSE;
383 	/*
384 	 * If the offset is beyond end of file we do
385 	 * not have the page.
386 	 */
387 	if (IDX_TO_OFF(pindex) >= object->un_pager.vnp.vnp_size)
388 		return FALSE;
389 
390 	bsize = vp->v_mount->mnt_stat.f_iosize;
391 	pagesperblock = bsize / PAGE_SIZE;
392 	blocksperpage = 0;
393 	if (pagesperblock > 0) {
394 		reqblock = pindex / pagesperblock;
395 	} else {
396 		blocksperpage = (PAGE_SIZE / bsize);
397 		reqblock = pindex * blocksperpage;
398 	}
399 	lockstate = VM_OBJECT_DROP(object);
400 	err = VOP_BMAP(vp, reqblock, NULL, &bn, after, before);
401 	VM_OBJECT_PICKUP(object, lockstate);
402 	if (err)
403 		return TRUE;
404 	if (bn == -1)
405 		return FALSE;
406 	if (pagesperblock > 0) {
407 		poff = pindex - (reqblock * pagesperblock);
408 		if (before) {
409 			*before *= pagesperblock;
410 			*before += poff;
411 		}
412 		if (after) {
413 			/*
414 			 * The BMAP vop can report a partial block in the
415 			 * 'after', but must not report blocks after EOF.
416 			 * Assert the latter, and truncate 'after' in case
417 			 * of the former.
418 			 */
419 			KASSERT((reqblock + *after) * pagesperblock <
420 			    roundup2(object->size, pagesperblock),
421 			    ("%s: reqblock %jd after %d size %ju", __func__,
422 			    (intmax_t )reqblock, *after,
423 			    (uintmax_t )object->size));
424 			*after *= pagesperblock;
425 			*after += pagesperblock - (poff + 1);
426 			if (pindex + *after >= object->size)
427 				*after = object->size - 1 - pindex;
428 		}
429 	} else {
430 		if (before) {
431 			*before /= blocksperpage;
432 		}
433 
434 		if (after) {
435 			*after /= blocksperpage;
436 		}
437 	}
438 	return TRUE;
439 }
440 
441 /*
442  * Internal routine clearing partial-page content
443  */
444 static void
vnode_pager_subpage_purge(struct vm_page * m,int base,int end)445 vnode_pager_subpage_purge(struct vm_page *m, int base, int end)
446 {
447 	int size;
448 
449 	KASSERT(end > base && end <= PAGE_SIZE,
450 	    ("%s: start %d end %d", __func__, base, end));
451 	size = end - base;
452 
453 	/*
454 	 * Clear out partial-page garbage in case
455 	 * the page has been mapped.
456 	 */
457 	pmap_zero_page_area(m, base, size);
458 
459 	/*
460 	 * Update the valid bits to reflect the blocks
461 	 * that have been zeroed.  Some of these valid
462 	 * bits may have already been set.
463 	 */
464 	vm_page_set_valid_range(m, base, size);
465 
466 	/*
467 	 * Round up "base" to the next block boundary so
468 	 * that the dirty bit for a partially zeroed
469 	 * block is not cleared.
470 	 */
471 	base = roundup2(base, DEV_BSIZE);
472 	end = rounddown2(end, DEV_BSIZE);
473 
474 	if (end > base) {
475 		/*
476 		 * Clear out partial-page dirty bits.
477 		 *
478 		 * note that we do not clear out the
479 		 * valid bits.  This would prevent
480 		 * bogus_page replacement from working
481 		 * properly.
482 		 */
483 		vm_page_clear_dirty(m, base, end - base);
484 	}
485 
486 }
487 
488 /*
489  * Lets the VM system know about a change in size for a file.
490  * We adjust our own internal size and flush any cached pages in
491  * the associated object that are affected by the size change.
492  *
493  * Note: this routine may be invoked as a result of a pager put
494  * operation (possibly at object termination time), so we must be careful.
495  */
496 void
vnode_pager_setsize(struct vnode * vp,vm_ooffset_t nsize)497 vnode_pager_setsize(struct vnode *vp, vm_ooffset_t nsize)
498 {
499 	vm_object_t object;
500 	vm_page_t m;
501 	vm_pindex_t nobjsize;
502 
503 	if ((object = vp->v_object) == NULL)
504 		return;
505 #ifdef DEBUG_VFS_LOCKS
506 	{
507 		struct mount *mp;
508 
509 		mp = vp->v_mount;
510 		if (mp != NULL && (mp->mnt_kern_flag & MNTK_VMSETSIZE_BUG) == 0)
511 			assert_vop_elocked(vp,
512 			    "vnode_pager_setsize and not locked vnode");
513 	}
514 #endif
515 	VM_OBJECT_WLOCK(object);
516 	if (object->type == OBJT_DEAD) {
517 		VM_OBJECT_WUNLOCK(object);
518 		return;
519 	}
520 	KASSERT(object->type == OBJT_VNODE,
521 	    ("not vnode-backed object %p", object));
522 	if (nsize == object->un_pager.vnp.vnp_size) {
523 		/*
524 		 * Hasn't changed size
525 		 */
526 		VM_OBJECT_WUNLOCK(object);
527 		return;
528 	}
529 	nobjsize = OFF_TO_IDX(nsize + PAGE_MASK);
530 	if (nsize < object->un_pager.vnp.vnp_size) {
531 		/*
532 		 * File has shrunk. Toss any cached pages beyond the new EOF.
533 		 */
534 		if (nobjsize < object->size)
535 			vm_object_page_remove(object, nobjsize, object->size,
536 			    0);
537 		/*
538 		 * this gets rid of garbage at the end of a page that is now
539 		 * only partially backed by the vnode.
540 		 *
541 		 * XXX for some reason (I don't know yet), if we take a
542 		 * completely invalid page and mark it partially valid
543 		 * it can screw up NFS reads, so we don't allow the case.
544 		 */
545 		if (!(nsize & PAGE_MASK))
546 			goto out;
547 		m = vm_page_grab(object, OFF_TO_IDX(nsize), VM_ALLOC_NOCREAT);
548 		if (m == NULL)
549 			goto out;
550 		if (!vm_page_none_valid(m))
551 			vnode_pager_subpage_purge(m, (int)nsize & PAGE_MASK,
552 			    PAGE_SIZE);
553 		vm_page_xunbusy(m);
554 	}
555 out:
556 #if defined(__powerpc__) && !defined(__powerpc64__)
557 	object->un_pager.vnp.vnp_size = nsize;
558 #else
559 	atomic_store_64(&object->un_pager.vnp.vnp_size, nsize);
560 #endif
561 	object->size = nobjsize;
562 	VM_OBJECT_WUNLOCK(object);
563 }
564 
565 /*
566  * Lets the VM system know about the purged range for a file. We toss away any
567  * cached pages in the associated object that are affected by the purge
568  * operation. Partial-page area not aligned to page boundaries will be zeroed
569  * and the dirty blocks in DEV_BSIZE unit within a page will not be flushed.
570  */
571 void
vnode_pager_purge_range(struct vnode * vp,vm_ooffset_t start,vm_ooffset_t end)572 vnode_pager_purge_range(struct vnode *vp, vm_ooffset_t start, vm_ooffset_t end)
573 {
574 	struct vm_page *m;
575 	struct vm_object *object;
576 	vm_pindex_t pi, pistart, piend;
577 	bool same_page;
578 	int base, pend;
579 
580 	ASSERT_VOP_LOCKED(vp, "vnode_pager_purge_range");
581 
582 	object = vp->v_object;
583 	pi = start + PAGE_MASK < start ? OBJ_MAX_SIZE :
584 	    OFF_TO_IDX(start + PAGE_MASK);
585 	pistart = OFF_TO_IDX(start);
586 	piend = end == 0 ? OBJ_MAX_SIZE : OFF_TO_IDX(end);
587 	same_page = pistart == piend;
588 	if ((end != 0 && end <= start) || object == NULL)
589 		return;
590 
591 	VM_OBJECT_WLOCK(object);
592 
593 	if (pi < piend)
594 		vm_object_page_remove(object, pi, piend, 0);
595 
596 	if ((start & PAGE_MASK) != 0) {
597 		base = (int)start & PAGE_MASK;
598 		pend = same_page ? (int)end & PAGE_MASK : PAGE_SIZE;
599 		m = vm_page_grab(object, pistart, VM_ALLOC_NOCREAT);
600 		if (m != NULL) {
601 			if (!vm_page_none_valid(m))
602 				vnode_pager_subpage_purge(m, base, pend);
603 			vm_page_xunbusy(m);
604 		}
605 		if (same_page)
606 			goto out;
607 	}
608 	if ((end & PAGE_MASK) != 0) {
609 		base = same_page ? (int)start & PAGE_MASK : 0 ;
610 		pend = (int)end & PAGE_MASK;
611 		m = vm_page_grab(object, piend, VM_ALLOC_NOCREAT);
612 		if (m != NULL) {
613 			if (!vm_page_none_valid(m))
614 				vnode_pager_subpage_purge(m, base, pend);
615 			vm_page_xunbusy(m);
616 		}
617 	}
618 out:
619 	VM_OBJECT_WUNLOCK(object);
620 }
621 
622 /*
623  * calculate the linear (byte) disk address of specified virtual
624  * file address
625  */
626 static int
vnode_pager_addr(struct vnode * vp,vm_ooffset_t address,daddr_t * rtaddress,int * run)627 vnode_pager_addr(struct vnode *vp, vm_ooffset_t address, daddr_t *rtaddress,
628     int *run)
629 {
630 	int bsize;
631 	int err;
632 	daddr_t vblock;
633 	daddr_t voffset;
634 
635 	if (VN_IS_DOOMED(vp))
636 		return -1;
637 
638 	bsize = vp->v_mount->mnt_stat.f_iosize;
639 	vblock = address / bsize;
640 	voffset = address % bsize;
641 
642 	err = VOP_BMAP(vp, vblock, NULL, rtaddress, run, NULL);
643 	if (err == 0) {
644 		if (*rtaddress != -1)
645 			*rtaddress += voffset / DEV_BSIZE;
646 		if (run) {
647 			*run += 1;
648 			*run *= bsize / PAGE_SIZE;
649 			*run -= voffset / PAGE_SIZE;
650 		}
651 	}
652 
653 	return (err);
654 }
655 
656 static void
vnode_pager_input_bdone(struct buf * bp)657 vnode_pager_input_bdone(struct buf *bp)
658 {
659 	runningbufwakeup(bp);
660 	bdone(bp);
661 }
662 
663 /*
664  * small block filesystem vnode pager input
665  */
666 static int
vnode_pager_input_smlfs(vm_object_t object,vm_page_t m)667 vnode_pager_input_smlfs(vm_object_t object, vm_page_t m)
668 {
669 	struct vnode *vp;
670 	struct bufobj *bo;
671 	struct buf *bp;
672 	struct sf_buf *sf;
673 	daddr_t fileaddr;
674 	vm_offset_t bsize;
675 	vm_page_bits_t bits;
676 	int error, i;
677 
678 	error = 0;
679 	vp = object->handle;
680 	if (VN_IS_DOOMED(vp))
681 		return VM_PAGER_BAD;
682 
683 	bsize = vp->v_mount->mnt_stat.f_iosize;
684 
685 	VOP_BMAP(vp, 0, &bo, 0, NULL, NULL);
686 
687 	sf = sf_buf_alloc(m, 0);
688 
689 	for (i = 0; i < PAGE_SIZE / bsize; i++) {
690 		vm_ooffset_t address;
691 
692 		bits = vm_page_bits(i * bsize, bsize);
693 		if (m->valid & bits)
694 			continue;
695 
696 		address = IDX_TO_OFF(m->pindex) + i * bsize;
697 		if (address >= object->un_pager.vnp.vnp_size) {
698 			fileaddr = -1;
699 		} else {
700 			error = vnode_pager_addr(vp, address, &fileaddr, NULL);
701 			if (error)
702 				break;
703 		}
704 		if (fileaddr != -1) {
705 			bp = uma_zalloc(vnode_pbuf_zone, M_WAITOK);
706 
707 			/* build a minimal buffer header */
708 			bp->b_iocmd = BIO_READ;
709 			bp->b_iodone = vnode_pager_input_bdone;
710 			KASSERT(bp->b_rcred == NOCRED, ("leaking read ucred"));
711 			KASSERT(bp->b_wcred == NOCRED, ("leaking write ucred"));
712 			bp->b_rcred = crhold(curthread->td_ucred);
713 			bp->b_wcred = crhold(curthread->td_ucred);
714 			bp->b_data = (caddr_t)sf_buf_kva(sf) + i * bsize;
715 			bp->b_blkno = fileaddr;
716 			pbgetbo(bo, bp);
717 			bp->b_vp = vp;
718 			bp->b_bcount = bsize;
719 			bp->b_bufsize = bsize;
720 			(void)runningbufclaim(bp, bp->b_bufsize);
721 
722 			/* do the input */
723 			bp->b_iooffset = dbtob(bp->b_blkno);
724 			bstrategy(bp);
725 
726 			bwait(bp, PVM, "vnsrd");
727 
728 			if ((bp->b_ioflags & BIO_ERROR) != 0) {
729 				KASSERT(bp->b_error != 0,
730 				    ("%s: buf error but b_error == 0\n", __func__));
731 				error = bp->b_error;
732 			}
733 
734 			/*
735 			 * free the buffer header back to the swap buffer pool
736 			 */
737 			bp->b_vp = NULL;
738 			pbrelbo(bp);
739 			uma_zfree(vnode_pbuf_zone, bp);
740 			if (error)
741 				break;
742 		} else
743 			bzero((caddr_t)sf_buf_kva(sf) + i * bsize, bsize);
744 		KASSERT((m->dirty & bits) == 0,
745 		    ("vnode_pager_input_smlfs: page %p is dirty", m));
746 		vm_page_bits_set(m, &m->valid, bits);
747 	}
748 	sf_buf_free(sf);
749 	if (error) {
750 		return VM_PAGER_ERROR;
751 	}
752 	return VM_PAGER_OK;
753 }
754 
755 /*
756  * old style vnode pager input routine
757  */
758 static int
vnode_pager_input_old(vm_object_t object,vm_page_t m)759 vnode_pager_input_old(vm_object_t object, vm_page_t m)
760 {
761 	struct uio auio;
762 	struct iovec aiov;
763 	int error;
764 	int size;
765 	struct sf_buf *sf;
766 	struct vnode *vp;
767 
768 	VM_OBJECT_ASSERT_WLOCKED(object);
769 	error = 0;
770 
771 	/*
772 	 * Return failure if beyond current EOF
773 	 */
774 	if (IDX_TO_OFF(m->pindex) >= object->un_pager.vnp.vnp_size) {
775 		return VM_PAGER_BAD;
776 	} else {
777 		size = PAGE_SIZE;
778 		if (IDX_TO_OFF(m->pindex) + size > object->un_pager.vnp.vnp_size)
779 			size = object->un_pager.vnp.vnp_size - IDX_TO_OFF(m->pindex);
780 		vp = object->handle;
781 		VM_OBJECT_WUNLOCK(object);
782 
783 		/*
784 		 * Allocate a kernel virtual address and initialize so that
785 		 * we can use VOP_READ/WRITE routines.
786 		 */
787 		sf = sf_buf_alloc(m, 0);
788 
789 		aiov.iov_base = (caddr_t)sf_buf_kva(sf);
790 		aiov.iov_len = size;
791 		auio.uio_iov = &aiov;
792 		auio.uio_iovcnt = 1;
793 		auio.uio_offset = IDX_TO_OFF(m->pindex);
794 		auio.uio_segflg = UIO_SYSSPACE;
795 		auio.uio_rw = UIO_READ;
796 		auio.uio_resid = size;
797 		auio.uio_td = curthread;
798 
799 		error = VOP_READ(vp, &auio, 0, curthread->td_ucred);
800 		if (!error) {
801 			int count = size - auio.uio_resid;
802 
803 			if (count == 0)
804 				error = EINVAL;
805 			else if (count != PAGE_SIZE)
806 				bzero((caddr_t)sf_buf_kva(sf) + count,
807 				    PAGE_SIZE - count);
808 		}
809 		sf_buf_free(sf);
810 
811 		VM_OBJECT_WLOCK(object);
812 	}
813 	KASSERT(m->dirty == 0, ("vnode_pager_input_old: page %p is dirty", m));
814 	if (!error)
815 		vm_page_valid(m);
816 	return error ? VM_PAGER_ERROR : VM_PAGER_OK;
817 }
818 
819 /*
820  * generic vnode pager input routine
821  */
822 
823 /*
824  * Local media VFS's that do not implement their own VOP_GETPAGES
825  * should have their VOP_GETPAGES call to vnode_pager_generic_getpages()
826  * to implement the previous behaviour.
827  *
828  * All other FS's should use the bypass to get to the local media
829  * backing vp's VOP_GETPAGES.
830  */
831 static int
vnode_pager_getpages(vm_object_t object,vm_page_t * m,int count,int * rbehind,int * rahead)832 vnode_pager_getpages(vm_object_t object, vm_page_t *m, int count, int *rbehind,
833     int *rahead)
834 {
835 	struct vnode *vp;
836 	int rtval;
837 
838 	/* Handle is stable with paging in progress. */
839 	vp = object->handle;
840 	rtval = VOP_GETPAGES(vp, m, count, rbehind, rahead);
841 	KASSERT(rtval != EOPNOTSUPP,
842 	    ("vnode_pager: FS getpages not implemented\n"));
843 	return rtval;
844 }
845 
846 static int
vnode_pager_getpages_async(vm_object_t object,vm_page_t * m,int count,int * rbehind,int * rahead,vop_getpages_iodone_t iodone,void * arg)847 vnode_pager_getpages_async(vm_object_t object, vm_page_t *m, int count,
848     int *rbehind, int *rahead, vop_getpages_iodone_t iodone, void *arg)
849 {
850 	struct vnode *vp;
851 	int rtval;
852 
853 	vp = object->handle;
854 	rtval = VOP_GETPAGES_ASYNC(vp, m, count, rbehind, rahead, iodone, arg);
855 	KASSERT(rtval != EOPNOTSUPP,
856 	    ("vnode_pager: FS getpages_async not implemented\n"));
857 	return (rtval);
858 }
859 
860 /*
861  * The implementation of VOP_GETPAGES() and VOP_GETPAGES_ASYNC() for
862  * local filesystems, where partially valid pages can only occur at
863  * the end of file.
864  */
865 int
vnode_pager_local_getpages(struct vop_getpages_args * ap)866 vnode_pager_local_getpages(struct vop_getpages_args *ap)
867 {
868 
869 	return (vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
870 	    ap->a_rbehind, ap->a_rahead, NULL, NULL));
871 }
872 
873 int
vnode_pager_local_getpages_async(struct vop_getpages_async_args * ap)874 vnode_pager_local_getpages_async(struct vop_getpages_async_args *ap)
875 {
876 	int error;
877 
878 	error = vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
879 	    ap->a_rbehind, ap->a_rahead, ap->a_iodone, ap->a_arg);
880 	if (error != 0 && ap->a_iodone != NULL)
881 		ap->a_iodone(ap->a_arg, ap->a_m, ap->a_count, error);
882 	return (error);
883 }
884 
885 /*
886  * This is now called from local media FS's to operate against their
887  * own vnodes if they fail to implement VOP_GETPAGES.
888  */
889 int
vnode_pager_generic_getpages(struct vnode * vp,vm_page_t * m,int count,int * a_rbehind,int * a_rahead,vop_getpages_iodone_t iodone,void * arg)890 vnode_pager_generic_getpages(struct vnode *vp, vm_page_t *m, int count,
891     int *a_rbehind, int *a_rahead, vop_getpages_iodone_t iodone, void *arg)
892 {
893 	vm_object_t object;
894 	struct bufobj *bo;
895 	struct buf *bp;
896 	off_t foff;
897 #ifdef INVARIANTS
898 	off_t blkno0;
899 #endif
900 	int bsize, pagesperblock;
901 	int error, before, after, rbehind, rahead, poff, i;
902 	int bytecount, secmask;
903 
904 	KASSERT(vp->v_type != VCHR && vp->v_type != VBLK,
905 	    ("%s does not support devices", __func__));
906 
907 	if (VN_IS_DOOMED(vp))
908 		return (VM_PAGER_BAD);
909 
910 	object = vp->v_object;
911 	foff = IDX_TO_OFF(m[0]->pindex);
912 	bsize = vp->v_mount->mnt_stat.f_iosize;
913 	pagesperblock = bsize / PAGE_SIZE;
914 
915 	KASSERT(foff < object->un_pager.vnp.vnp_size,
916 	    ("%s: page %p offset beyond vp %p size", __func__, m[0], vp));
917 	KASSERT(count <= atop(maxphys),
918 	    ("%s: requested %d pages", __func__, count));
919 
920 	/*
921 	 * The last page has valid blocks.  Invalid part can only
922 	 * exist at the end of file, and the page is made fully valid
923 	 * by zeroing in vm_pager_get_pages().
924 	 */
925 	if (!vm_page_none_valid(m[count - 1]) && --count == 0) {
926 		if (iodone != NULL)
927 			iodone(arg, m, 1, 0);
928 		return (VM_PAGER_OK);
929 	}
930 
931 	bp = uma_zalloc(vnode_pbuf_zone, M_WAITOK);
932 	MPASS((bp->b_flags & B_MAXPHYS) != 0);
933 
934 	/*
935 	 * Get the underlying device blocks for the file with VOP_BMAP().
936 	 * If the file system doesn't support VOP_BMAP, use old way of
937 	 * getting pages via VOP_READ.
938 	 */
939 	error = VOP_BMAP(vp, foff / bsize, &bo, &bp->b_blkno, &after, &before);
940 	if (error == EOPNOTSUPP) {
941 		uma_zfree(vnode_pbuf_zone, bp);
942 		VM_OBJECT_WLOCK(object);
943 		for (i = 0; i < count; i++) {
944 			VM_CNT_INC(v_vnodein);
945 			VM_CNT_INC(v_vnodepgsin);
946 			error = vnode_pager_input_old(object, m[i]);
947 			if (error)
948 				break;
949 		}
950 		VM_OBJECT_WUNLOCK(object);
951 		return (error);
952 	} else if (error != 0) {
953 		uma_zfree(vnode_pbuf_zone, bp);
954 		return (VM_PAGER_ERROR);
955 	}
956 
957 	/*
958 	 * If the file system supports BMAP, but blocksize is smaller
959 	 * than a page size, then use special small filesystem code.
960 	 */
961 	if (pagesperblock == 0) {
962 		uma_zfree(vnode_pbuf_zone, bp);
963 		for (i = 0; i < count; i++) {
964 			VM_CNT_INC(v_vnodein);
965 			VM_CNT_INC(v_vnodepgsin);
966 			error = vnode_pager_input_smlfs(object, m[i]);
967 			if (error)
968 				break;
969 		}
970 		return (error);
971 	}
972 
973 	/*
974 	 * A sparse file can be encountered only for a single page request,
975 	 * which may not be preceded by call to vm_pager_haspage().
976 	 */
977 	if (bp->b_blkno == -1) {
978 		KASSERT(count == 1,
979 		    ("%s: array[%d] request to a sparse file %p", __func__,
980 		    count, vp));
981 		uma_zfree(vnode_pbuf_zone, bp);
982 		pmap_zero_page(m[0]);
983 		KASSERT(m[0]->dirty == 0, ("%s: page %p is dirty",
984 		    __func__, m[0]));
985 		vm_page_valid(m[0]);
986 		return (VM_PAGER_OK);
987 	}
988 
989 #ifdef INVARIANTS
990 	blkno0 = bp->b_blkno;
991 #endif
992 	bp->b_blkno += (foff % bsize) / DEV_BSIZE;
993 
994 	/* Recalculate blocks available after/before to pages. */
995 	poff = (foff % bsize) / PAGE_SIZE;
996 	before *= pagesperblock;
997 	before += poff;
998 	after *= pagesperblock;
999 	after += pagesperblock - (poff + 1);
1000 	if (m[0]->pindex + after >= object->size)
1001 		after = object->size - 1 - m[0]->pindex;
1002 	KASSERT(count <= after + 1, ("%s: %d pages asked, can do only %d",
1003 	    __func__, count, after + 1));
1004 	after -= count - 1;
1005 
1006 	/* Trim requested rbehind/rahead to possible values. */
1007 	rbehind = a_rbehind ? *a_rbehind : 0;
1008 	rahead = a_rahead ? *a_rahead : 0;
1009 	rbehind = min(rbehind, before);
1010 	rbehind = min(rbehind, m[0]->pindex);
1011 	rahead = min(rahead, after);
1012 	rahead = min(rahead, object->size - m[count - 1]->pindex);
1013 	/*
1014 	 * Check that total amount of pages fit into buf.  Trim rbehind and
1015 	 * rahead evenly if not.
1016 	 */
1017 	if (rbehind + rahead + count > atop(maxphys)) {
1018 		int trim, sum;
1019 
1020 		trim = rbehind + rahead + count - atop(maxphys) + 1;
1021 		sum = rbehind + rahead;
1022 		if (rbehind == before) {
1023 			/* Roundup rbehind trim to block size. */
1024 			rbehind -= roundup(trim * rbehind / sum, pagesperblock);
1025 			if (rbehind < 0)
1026 				rbehind = 0;
1027 		} else
1028 			rbehind -= trim * rbehind / sum;
1029 		rahead -= trim * rahead / sum;
1030 	}
1031 	KASSERT(rbehind + rahead + count <= atop(maxphys),
1032 	    ("%s: behind %d ahead %d count %d maxphys %lu", __func__,
1033 	    rbehind, rahead, count, maxphys));
1034 
1035 	/*
1036 	 * Fill in the bp->b_pages[] array with requested and optional
1037 	 * read behind or read ahead pages.  Read behind pages are looked
1038 	 * up in a backward direction, down to a first cached page.  Same
1039 	 * for read ahead pages, but there is no need to shift the array
1040 	 * in case of encountering a cached page.
1041 	 */
1042 	i = bp->b_npages = 0;
1043 	if (rbehind) {
1044 		vm_pindex_t startpindex, tpindex;
1045 		vm_page_t mpred, p;
1046 
1047 		VM_OBJECT_WLOCK(object);
1048 		tpindex = m[0]->pindex;
1049 		startpindex = MAX(tpindex, rbehind) - rbehind;
1050 		if ((mpred = TAILQ_PREV(m[0], pglist, listq)) != NULL)
1051 			startpindex = MAX(startpindex, mpred->pindex + 1);
1052 
1053 		/* Stepping backward from pindex, mpred doesn't change. */
1054 		for (; tpindex-- > startpindex; i++) {
1055 			p = vm_page_alloc_after(object, tpindex,
1056 			    VM_ALLOC_NORMAL, mpred);
1057 			if (p == NULL) {
1058 				/* Shift the array. */
1059 				for (int j = 0; j < i; j++)
1060 					bp->b_pages[j] = bp->b_pages[j +
1061 					    tpindex + 1 - startpindex];
1062 				break;
1063 			}
1064 			bp->b_pages[tpindex - startpindex] = p;
1065 		}
1066 
1067 		bp->b_pgbefore = i;
1068 		bp->b_npages += i;
1069 		bp->b_blkno -= IDX_TO_OFF(i) / DEV_BSIZE;
1070 	} else
1071 		bp->b_pgbefore = 0;
1072 
1073 	/* Requested pages. */
1074 	for (int j = 0; j < count; j++, i++)
1075 		bp->b_pages[i] = m[j];
1076 	bp->b_npages += count;
1077 
1078 	if (rahead) {
1079 		vm_pindex_t endpindex, tpindex;
1080 		vm_page_t p;
1081 
1082 		if (!VM_OBJECT_WOWNED(object))
1083 			VM_OBJECT_WLOCK(object);
1084 		endpindex = m[count - 1]->pindex + rahead + 1;
1085 		if ((p = TAILQ_NEXT(m[count - 1], listq)) != NULL &&
1086 		    p->pindex < endpindex)
1087 			endpindex = p->pindex;
1088 		if (endpindex > object->size)
1089 			endpindex = object->size;
1090 
1091 		p = m[count - 1];
1092 		for (tpindex = p->pindex + 1;
1093 		    tpindex < endpindex; i++, tpindex++) {
1094 			p = vm_page_alloc_after(object, tpindex,
1095 			    VM_ALLOC_NORMAL, p);
1096 			if (p == NULL)
1097 				break;
1098 			bp->b_pages[i] = p;
1099 		}
1100 
1101 		bp->b_pgafter = i - bp->b_npages;
1102 		bp->b_npages = i;
1103 	} else
1104 		bp->b_pgafter = 0;
1105 
1106 	if (VM_OBJECT_WOWNED(object))
1107 		VM_OBJECT_WUNLOCK(object);
1108 
1109 	/* Report back actual behind/ahead read. */
1110 	if (a_rbehind)
1111 		*a_rbehind = bp->b_pgbefore;
1112 	if (a_rahead)
1113 		*a_rahead = bp->b_pgafter;
1114 
1115 #ifdef INVARIANTS
1116 	KASSERT(bp->b_npages <= atop(maxphys),
1117 	    ("%s: buf %p overflowed", __func__, bp));
1118 	for (int j = 1, prev = 0; j < bp->b_npages; j++) {
1119 		if (bp->b_pages[j] == bogus_page)
1120 			continue;
1121 		KASSERT(bp->b_pages[j]->pindex - bp->b_pages[prev]->pindex ==
1122 		    j - prev, ("%s: pages array not consecutive, bp %p",
1123 		     __func__, bp));
1124 		prev = j;
1125 	}
1126 #endif
1127 
1128 	/*
1129 	 * Recalculate first offset and bytecount with regards to read behind.
1130 	 * Truncate bytecount to vnode real size and round up physical size
1131 	 * for real devices.
1132 	 */
1133 	foff = IDX_TO_OFF(bp->b_pages[0]->pindex);
1134 	bytecount = bp->b_npages << PAGE_SHIFT;
1135 	if ((foff + bytecount) > object->un_pager.vnp.vnp_size)
1136 		bytecount = object->un_pager.vnp.vnp_size - foff;
1137 	secmask = bo->bo_bsize - 1;
1138 	KASSERT(secmask < PAGE_SIZE && secmask > 0,
1139 	    ("%s: sector size %d too large", __func__, secmask + 1));
1140 	bytecount = (bytecount + secmask) & ~secmask;
1141 
1142 	/*
1143 	 * And map the pages to be read into the kva, if the filesystem
1144 	 * requires mapped buffers.
1145 	 */
1146 	if ((vp->v_mount->mnt_kern_flag & MNTK_UNMAPPED_BUFS) != 0 &&
1147 	    unmapped_buf_allowed) {
1148 		bp->b_data = unmapped_buf;
1149 		bp->b_offset = 0;
1150 	} else {
1151 		bp->b_data = bp->b_kvabase;
1152 		pmap_qenter((vm_offset_t)bp->b_data, bp->b_pages, bp->b_npages);
1153 	}
1154 
1155 	/* Build a minimal buffer header. */
1156 	bp->b_iocmd = BIO_READ;
1157 	KASSERT(bp->b_rcred == NOCRED, ("leaking read ucred"));
1158 	KASSERT(bp->b_wcred == NOCRED, ("leaking write ucred"));
1159 	bp->b_rcred = crhold(curthread->td_ucred);
1160 	bp->b_wcred = crhold(curthread->td_ucred);
1161 	pbgetbo(bo, bp);
1162 	bp->b_vp = vp;
1163 	bp->b_bcount = bp->b_bufsize = bytecount;
1164 	bp->b_iooffset = dbtob(bp->b_blkno);
1165 	KASSERT(IDX_TO_OFF(m[0]->pindex - bp->b_pages[0]->pindex) ==
1166 	    (blkno0 - bp->b_blkno) * DEV_BSIZE +
1167 	    IDX_TO_OFF(m[0]->pindex) % bsize,
1168 	    ("wrong offsets bsize %d m[0] %ju b_pages[0] %ju "
1169 	    "blkno0 %ju b_blkno %ju", bsize,
1170 	    (uintmax_t)m[0]->pindex, (uintmax_t)bp->b_pages[0]->pindex,
1171 	    (uintmax_t)blkno0, (uintmax_t)bp->b_blkno));
1172 
1173 	(void)runningbufclaim(bp, bp->b_bufsize);
1174 
1175 	VM_CNT_INC(v_vnodein);
1176 	VM_CNT_ADD(v_vnodepgsin, bp->b_npages);
1177 
1178 	if (iodone != NULL) { /* async */
1179 		bp->b_pgiodone = iodone;
1180 		bp->b_caller1 = arg;
1181 		bp->b_iodone = vnode_pager_generic_getpages_done_async;
1182 		bp->b_flags |= B_ASYNC;
1183 		BUF_KERNPROC(bp);
1184 		bstrategy(bp);
1185 		return (VM_PAGER_OK);
1186 	} else {
1187 		bp->b_iodone = bdone;
1188 		bstrategy(bp);
1189 		bwait(bp, PVM, "vnread");
1190 		error = vnode_pager_generic_getpages_done(bp);
1191 		for (i = 0; i < bp->b_npages; i++)
1192 			bp->b_pages[i] = NULL;
1193 		bp->b_vp = NULL;
1194 		pbrelbo(bp);
1195 		uma_zfree(vnode_pbuf_zone, bp);
1196 		return (error != 0 ? VM_PAGER_ERROR : VM_PAGER_OK);
1197 	}
1198 }
1199 
1200 static void
vnode_pager_generic_getpages_done_async(struct buf * bp)1201 vnode_pager_generic_getpages_done_async(struct buf *bp)
1202 {
1203 	int error;
1204 
1205 	error = vnode_pager_generic_getpages_done(bp);
1206 	/* Run the iodone upon the requested range. */
1207 	bp->b_pgiodone(bp->b_caller1, bp->b_pages + bp->b_pgbefore,
1208 	    bp->b_npages - bp->b_pgbefore - bp->b_pgafter, error);
1209 	for (int i = 0; i < bp->b_npages; i++)
1210 		bp->b_pages[i] = NULL;
1211 	bp->b_vp = NULL;
1212 	pbrelbo(bp);
1213 	uma_zfree(vnode_pbuf_zone, bp);
1214 }
1215 
1216 static int
vnode_pager_generic_getpages_done(struct buf * bp)1217 vnode_pager_generic_getpages_done(struct buf *bp)
1218 {
1219 	vm_object_t object;
1220 	off_t tfoff, nextoff;
1221 	int i, error;
1222 
1223 	KASSERT((bp->b_ioflags & BIO_ERROR) == 0 || bp->b_error != 0,
1224 	    ("%s: buf error but b_error == 0\n", __func__));
1225 	error = (bp->b_ioflags & BIO_ERROR) != 0 ? bp->b_error : 0;
1226 	object = bp->b_vp->v_object;
1227 
1228 	runningbufwakeup(bp);
1229 
1230 	if (error == 0 && bp->b_bcount != bp->b_npages * PAGE_SIZE) {
1231 		if (!buf_mapped(bp)) {
1232 			bp->b_data = bp->b_kvabase;
1233 			pmap_qenter((vm_offset_t)bp->b_data, bp->b_pages,
1234 			    bp->b_npages);
1235 		}
1236 		bzero(bp->b_data + bp->b_bcount,
1237 		    PAGE_SIZE * bp->b_npages - bp->b_bcount);
1238 	}
1239 	if (buf_mapped(bp)) {
1240 		pmap_qremove((vm_offset_t)bp->b_data, bp->b_npages);
1241 		bp->b_data = unmapped_buf;
1242 	}
1243 
1244 	/*
1245 	 * If the read failed, we must free any read ahead/behind pages here.
1246 	 * The requested pages are freed by the caller (for sync requests)
1247 	 * or by the bp->b_pgiodone callback (for async requests).
1248 	 */
1249 	if (error != 0) {
1250 		VM_OBJECT_WLOCK(object);
1251 		for (i = 0; i < bp->b_pgbefore; i++)
1252 			vm_page_free_invalid(bp->b_pages[i]);
1253 		for (i = bp->b_npages - bp->b_pgafter; i < bp->b_npages; i++)
1254 			vm_page_free_invalid(bp->b_pages[i]);
1255 		VM_OBJECT_WUNLOCK(object);
1256 		return (error);
1257 	}
1258 
1259 	/* Read lock to protect size. */
1260 	VM_OBJECT_RLOCK(object);
1261 	for (i = 0, tfoff = IDX_TO_OFF(bp->b_pages[0]->pindex);
1262 	    i < bp->b_npages; i++, tfoff = nextoff) {
1263 		vm_page_t mt;
1264 
1265 		nextoff = tfoff + PAGE_SIZE;
1266 		mt = bp->b_pages[i];
1267 		if (mt == bogus_page)
1268 			continue;
1269 
1270 		if (nextoff <= object->un_pager.vnp.vnp_size) {
1271 			/*
1272 			 * Read filled up entire page.
1273 			 */
1274 			vm_page_valid(mt);
1275 			KASSERT(mt->dirty == 0,
1276 			    ("%s: page %p is dirty", __func__, mt));
1277 			KASSERT(!pmap_page_is_mapped(mt),
1278 			    ("%s: page %p is mapped", __func__, mt));
1279 		} else {
1280 			/*
1281 			 * Read did not fill up entire page.
1282 			 *
1283 			 * Currently we do not set the entire page valid,
1284 			 * we just try to clear the piece that we couldn't
1285 			 * read.
1286 			 */
1287 			vm_page_set_valid_range(mt, 0,
1288 			    object->un_pager.vnp.vnp_size - tfoff);
1289 			KASSERT((mt->dirty & vm_page_bits(0,
1290 			    object->un_pager.vnp.vnp_size - tfoff)) == 0,
1291 			    ("%s: page %p is dirty", __func__, mt));
1292 		}
1293 
1294 		if (i < bp->b_pgbefore || i >= bp->b_npages - bp->b_pgafter)
1295 			vm_page_readahead_finish(mt);
1296 	}
1297 	VM_OBJECT_RUNLOCK(object);
1298 
1299 	return (error);
1300 }
1301 
1302 /*
1303  * EOPNOTSUPP is no longer legal.  For local media VFS's that do not
1304  * implement their own VOP_PUTPAGES, their VOP_PUTPAGES should call to
1305  * vnode_pager_generic_putpages() to implement the previous behaviour.
1306  *
1307  * All other FS's should use the bypass to get to the local media
1308  * backing vp's VOP_PUTPAGES.
1309  */
1310 static void
vnode_pager_putpages(vm_object_t object,vm_page_t * m,int count,int flags,int * rtvals)1311 vnode_pager_putpages(vm_object_t object, vm_page_t *m, int count,
1312     int flags, int *rtvals)
1313 {
1314 	int rtval __diagused;
1315 	struct vnode *vp;
1316 	int bytes = count * PAGE_SIZE;
1317 
1318 	/*
1319 	 * Force synchronous operation if we are extremely low on memory
1320 	 * to prevent a low-memory deadlock.  VOP operations often need to
1321 	 * allocate more memory to initiate the I/O ( i.e. do a BMAP
1322 	 * operation ).  The swapper handles the case by limiting the amount
1323 	 * of asynchronous I/O, but that sort of solution doesn't scale well
1324 	 * for the vnode pager without a lot of work.
1325 	 *
1326 	 * Also, the backing vnode's iodone routine may not wake the pageout
1327 	 * daemon up.  This should be probably be addressed XXX.
1328 	 */
1329 
1330 	if (vm_page_count_min())
1331 		flags |= VM_PAGER_PUT_SYNC;
1332 
1333 	/*
1334 	 * Call device-specific putpages function
1335 	 */
1336 	vp = object->handle;
1337 	VM_OBJECT_WUNLOCK(object);
1338 	rtval = VOP_PUTPAGES(vp, m, bytes, flags, rtvals);
1339 	KASSERT(rtval != EOPNOTSUPP,
1340 	    ("vnode_pager: stale FS putpages\n"));
1341 	VM_OBJECT_WLOCK(object);
1342 }
1343 
1344 static int
vn_off2bidx(vm_ooffset_t offset)1345 vn_off2bidx(vm_ooffset_t offset)
1346 {
1347 
1348 	return ((offset & PAGE_MASK) / DEV_BSIZE);
1349 }
1350 
1351 static bool
vn_dirty_blk(vm_page_t m,vm_ooffset_t offset)1352 vn_dirty_blk(vm_page_t m, vm_ooffset_t offset)
1353 {
1354 
1355 	KASSERT(IDX_TO_OFF(m->pindex) <= offset &&
1356 	    offset < IDX_TO_OFF(m->pindex + 1),
1357 	    ("page %p pidx %ju offset %ju", m, (uintmax_t)m->pindex,
1358 	    (uintmax_t)offset));
1359 	return ((m->dirty & ((vm_page_bits_t)1 << vn_off2bidx(offset))) != 0);
1360 }
1361 
1362 /*
1363  * This is now called from local media FS's to operate against their
1364  * own vnodes if they fail to implement VOP_PUTPAGES.
1365  *
1366  * This is typically called indirectly via the pageout daemon and
1367  * clustering has already typically occurred, so in general we ask the
1368  * underlying filesystem to write the data out asynchronously rather
1369  * then delayed.
1370  */
1371 int
vnode_pager_generic_putpages(struct vnode * vp,vm_page_t * ma,int bytecount,int flags,int * rtvals)1372 vnode_pager_generic_putpages(struct vnode *vp, vm_page_t *ma, int bytecount,
1373     int flags, int *rtvals)
1374 {
1375 	vm_object_t object;
1376 	vm_page_t m;
1377 	vm_ooffset_t max_offset, next_offset, poffset, prev_offset;
1378 	struct uio auio;
1379 	struct iovec aiov;
1380 	off_t prev_resid, wrsz;
1381 	int count, error, i, maxsize, ncount, pgoff, ppscheck;
1382 	bool in_hole;
1383 	static struct timeval lastfail;
1384 	static int curfail;
1385 
1386 	object = vp->v_object;
1387 	count = bytecount / PAGE_SIZE;
1388 
1389 	for (i = 0; i < count; i++)
1390 		rtvals[i] = VM_PAGER_ERROR;
1391 
1392 	if ((int64_t)ma[0]->pindex < 0) {
1393 		printf("vnode_pager_generic_putpages: "
1394 		    "attempt to write meta-data 0x%jx(%lx)\n",
1395 		    (uintmax_t)ma[0]->pindex, (u_long)ma[0]->dirty);
1396 		rtvals[0] = VM_PAGER_BAD;
1397 		return (VM_PAGER_BAD);
1398 	}
1399 
1400 	maxsize = count * PAGE_SIZE;
1401 	ncount = count;
1402 
1403 	poffset = IDX_TO_OFF(ma[0]->pindex);
1404 
1405 	/*
1406 	 * If the page-aligned write is larger then the actual file we
1407 	 * have to invalidate pages occurring beyond the file EOF.  However,
1408 	 * there is an edge case where a file may not be page-aligned where
1409 	 * the last page is partially invalid.  In this case the filesystem
1410 	 * may not properly clear the dirty bits for the entire page (which
1411 	 * could be VM_PAGE_BITS_ALL due to the page having been mmap()d).
1412 	 * With the page busied we are free to fix up the dirty bits here.
1413 	 *
1414 	 * We do not under any circumstances truncate the valid bits, as
1415 	 * this will screw up bogus page replacement.
1416 	 */
1417 	VM_OBJECT_RLOCK(object);
1418 	if (maxsize + poffset > object->un_pager.vnp.vnp_size) {
1419 		if (object->un_pager.vnp.vnp_size > poffset) {
1420 			maxsize = object->un_pager.vnp.vnp_size - poffset;
1421 			ncount = btoc(maxsize);
1422 			if ((pgoff = (int)maxsize & PAGE_MASK) != 0) {
1423 				pgoff = roundup2(pgoff, DEV_BSIZE);
1424 
1425 				/*
1426 				 * If the page is busy and the following
1427 				 * conditions hold, then the page's dirty
1428 				 * field cannot be concurrently changed by a
1429 				 * pmap operation.
1430 				 */
1431 				m = ma[ncount - 1];
1432 				vm_page_assert_sbusied(m);
1433 				KASSERT(!pmap_page_is_write_mapped(m),
1434 		("vnode_pager_generic_putpages: page %p is not read-only", m));
1435 				MPASS(m->dirty != 0);
1436 				vm_page_clear_dirty(m, pgoff, PAGE_SIZE -
1437 				    pgoff);
1438 			}
1439 		} else {
1440 			maxsize = 0;
1441 			ncount = 0;
1442 		}
1443 		for (i = ncount; i < count; i++)
1444 			rtvals[i] = VM_PAGER_BAD;
1445 	}
1446 	VM_OBJECT_RUNLOCK(object);
1447 
1448 	auio.uio_iov = &aiov;
1449 	auio.uio_segflg = UIO_NOCOPY;
1450 	auio.uio_rw = UIO_WRITE;
1451 	auio.uio_td = NULL;
1452 	max_offset = roundup2(poffset + maxsize, DEV_BSIZE);
1453 
1454 	for (prev_offset = poffset; prev_offset < max_offset;) {
1455 		/* Skip clean blocks. */
1456 		for (in_hole = true; in_hole && prev_offset < max_offset;) {
1457 			m = ma[OFF_TO_IDX(prev_offset - poffset)];
1458 			for (i = vn_off2bidx(prev_offset);
1459 			    i < sizeof(vm_page_bits_t) * NBBY &&
1460 			    prev_offset < max_offset; i++) {
1461 				if (vn_dirty_blk(m, prev_offset)) {
1462 					in_hole = false;
1463 					break;
1464 				}
1465 				prev_offset += DEV_BSIZE;
1466 			}
1467 		}
1468 		if (in_hole)
1469 			goto write_done;
1470 
1471 		/* Find longest run of dirty blocks. */
1472 		for (next_offset = prev_offset; next_offset < max_offset;) {
1473 			m = ma[OFF_TO_IDX(next_offset - poffset)];
1474 			for (i = vn_off2bidx(next_offset);
1475 			    i < sizeof(vm_page_bits_t) * NBBY &&
1476 			    next_offset < max_offset; i++) {
1477 				if (!vn_dirty_blk(m, next_offset))
1478 					goto start_write;
1479 				next_offset += DEV_BSIZE;
1480 			}
1481 		}
1482 start_write:
1483 		if (next_offset > poffset + maxsize)
1484 			next_offset = poffset + maxsize;
1485 		if (prev_offset == next_offset)
1486 			goto write_done;
1487 
1488 		/*
1489 		 * Getting here requires finding a dirty block in the
1490 		 * 'skip clean blocks' loop.
1491 		 */
1492 
1493 		aiov.iov_base = NULL;
1494 		auio.uio_iovcnt = 1;
1495 		auio.uio_offset = prev_offset;
1496 		prev_resid = auio.uio_resid = aiov.iov_len = next_offset -
1497 		    prev_offset;
1498 		error = VOP_WRITE(vp, &auio,
1499 		    vnode_pager_putpages_ioflags(flags), curthread->td_ucred);
1500 
1501 		wrsz = prev_resid - auio.uio_resid;
1502 		if (wrsz == 0) {
1503 			if (ppsratecheck(&lastfail, &curfail, 1) != 0) {
1504 				vn_printf(vp, "vnode_pager_putpages: "
1505 				    "zero-length write at %ju resid %zd\n",
1506 				    auio.uio_offset, auio.uio_resid);
1507 			}
1508 			break;
1509 		}
1510 
1511 		/* Adjust the starting offset for next iteration. */
1512 		prev_offset += wrsz;
1513 		MPASS(auio.uio_offset == prev_offset);
1514 
1515 		ppscheck = 0;
1516 		if (error != 0 && (ppscheck = ppsratecheck(&lastfail,
1517 		    &curfail, 1)) != 0)
1518 			vn_printf(vp, "vnode_pager_putpages: I/O error %d\n",
1519 			    error);
1520 		if (auio.uio_resid != 0 && (ppscheck != 0 ||
1521 		    ppsratecheck(&lastfail, &curfail, 1) != 0))
1522 			vn_printf(vp, "vnode_pager_putpages: residual I/O %zd "
1523 			    "at %ju\n", auio.uio_resid,
1524 			    (uintmax_t)ma[0]->pindex);
1525 		if (error != 0 || auio.uio_resid != 0)
1526 			break;
1527 	}
1528 write_done:
1529 	/* Mark completely processed pages. */
1530 	for (i = 0; i < OFF_TO_IDX(prev_offset - poffset); i++)
1531 		rtvals[i] = VM_PAGER_OK;
1532 	/* Mark partial EOF page. */
1533 	if (prev_offset == poffset + maxsize && (prev_offset & PAGE_MASK) != 0)
1534 		rtvals[i++] = VM_PAGER_OK;
1535 	/* Unwritten pages in range, free bonus if the page is clean. */
1536 	for (; i < ncount; i++)
1537 		rtvals[i] = ma[i]->dirty == 0 ? VM_PAGER_OK : VM_PAGER_ERROR;
1538 	VM_CNT_ADD(v_vnodepgsout, i);
1539 	VM_CNT_INC(v_vnodeout);
1540 	return (rtvals[0]);
1541 }
1542 
1543 int
vnode_pager_putpages_ioflags(int pager_flags)1544 vnode_pager_putpages_ioflags(int pager_flags)
1545 {
1546 	int ioflags;
1547 
1548 	/*
1549 	 * Pageouts are already clustered, use IO_ASYNC to force a
1550 	 * bawrite() rather then a bdwrite() to prevent paging I/O
1551 	 * from saturating the buffer cache.  Dummy-up the sequential
1552 	 * heuristic to cause large ranges to cluster.  If neither
1553 	 * IO_SYNC or IO_ASYNC is set, the system decides how to
1554 	 * cluster.
1555 	 */
1556 	ioflags = IO_VMIO;
1557 	if ((pager_flags & (VM_PAGER_PUT_SYNC | VM_PAGER_PUT_INVAL)) != 0)
1558 		ioflags |= IO_SYNC;
1559 	else if ((pager_flags & VM_PAGER_CLUSTER_OK) == 0)
1560 		ioflags |= IO_ASYNC;
1561 	ioflags |= (pager_flags & VM_PAGER_PUT_INVAL) != 0 ? IO_INVAL: 0;
1562 	ioflags |= (pager_flags & VM_PAGER_PUT_NOREUSE) != 0 ? IO_NOREUSE : 0;
1563 	ioflags |= IO_SEQMAX << IO_SEQSHIFT;
1564 	return (ioflags);
1565 }
1566 
1567 /*
1568  * vnode_pager_undirty_pages().
1569  *
1570  * A helper to mark pages as clean after pageout that was possibly
1571  * done with a short write.  The lpos argument specifies the page run
1572  * length in bytes, and the written argument specifies how many bytes
1573  * were actually written.  eof is the offset past the last valid byte
1574  * in the vnode using the absolute file position of the first byte in
1575  * the run as the base from which it is computed.
1576  */
1577 void
vnode_pager_undirty_pages(vm_page_t * ma,int * rtvals,int written,off_t eof,int lpos)1578 vnode_pager_undirty_pages(vm_page_t *ma, int *rtvals, int written, off_t eof,
1579     int lpos)
1580 {
1581 	int i, pos, pos_devb;
1582 
1583 	if (written == 0 && eof >= lpos)
1584 		return;
1585 	for (i = 0, pos = 0; pos < written; i++, pos += PAGE_SIZE) {
1586 		if (pos < trunc_page(written)) {
1587 			rtvals[i] = VM_PAGER_OK;
1588 			vm_page_undirty(ma[i]);
1589 		} else {
1590 			/* Partially written page. */
1591 			rtvals[i] = VM_PAGER_AGAIN;
1592 			vm_page_clear_dirty(ma[i], 0, written & PAGE_MASK);
1593 		}
1594 	}
1595 	if (eof >= lpos) /* avoid truncation */
1596 		return;
1597 	for (pos = eof, i = OFF_TO_IDX(trunc_page(pos)); pos < lpos; i++) {
1598 		if (pos != trunc_page(pos)) {
1599 			/*
1600 			 * The page contains the last valid byte in
1601 			 * the vnode, mark the rest of the page as
1602 			 * clean, potentially making the whole page
1603 			 * clean.
1604 			 */
1605 			pos_devb = roundup2(pos & PAGE_MASK, DEV_BSIZE);
1606 			vm_page_clear_dirty(ma[i], pos_devb, PAGE_SIZE -
1607 			    pos_devb);
1608 
1609 			/*
1610 			 * If the page was cleaned, report the pageout
1611 			 * on it as successful.  msync() no longer
1612 			 * needs to write out the page, endlessly
1613 			 * creating write requests and dirty buffers.
1614 			 */
1615 			if (ma[i]->dirty == 0)
1616 				rtvals[i] = VM_PAGER_OK;
1617 
1618 			pos = round_page(pos);
1619 		} else {
1620 			/* vm_pageout_flush() clears dirty */
1621 			rtvals[i] = VM_PAGER_BAD;
1622 			pos += PAGE_SIZE;
1623 		}
1624 	}
1625 }
1626 
1627 static void
vnode_pager_update_writecount(vm_object_t object,vm_offset_t start,vm_offset_t end)1628 vnode_pager_update_writecount(vm_object_t object, vm_offset_t start,
1629     vm_offset_t end)
1630 {
1631 	struct vnode *vp;
1632 	vm_ooffset_t old_wm;
1633 
1634 	VM_OBJECT_WLOCK(object);
1635 	if (object->type != OBJT_VNODE) {
1636 		VM_OBJECT_WUNLOCK(object);
1637 		return;
1638 	}
1639 	old_wm = object->un_pager.vnp.writemappings;
1640 	object->un_pager.vnp.writemappings += (vm_ooffset_t)end - start;
1641 	vp = object->handle;
1642 	if (old_wm == 0 && object->un_pager.vnp.writemappings != 0) {
1643 		ASSERT_VOP_LOCKED(vp, "v_writecount inc");
1644 		VOP_ADD_WRITECOUNT_CHECKED(vp, 1);
1645 		CTR3(KTR_VFS, "%s: vp %p v_writecount increased to %d",
1646 		    __func__, vp, vp->v_writecount);
1647 	} else if (old_wm != 0 && object->un_pager.vnp.writemappings == 0) {
1648 		ASSERT_VOP_LOCKED(vp, "v_writecount dec");
1649 		VOP_ADD_WRITECOUNT_CHECKED(vp, -1);
1650 		CTR3(KTR_VFS, "%s: vp %p v_writecount decreased to %d",
1651 		    __func__, vp, vp->v_writecount);
1652 	}
1653 	VM_OBJECT_WUNLOCK(object);
1654 }
1655 
1656 static void
vnode_pager_release_writecount(vm_object_t object,vm_offset_t start,vm_offset_t end)1657 vnode_pager_release_writecount(vm_object_t object, vm_offset_t start,
1658     vm_offset_t end)
1659 {
1660 	struct vnode *vp;
1661 	struct mount *mp;
1662 	vm_offset_t inc;
1663 
1664 	VM_OBJECT_WLOCK(object);
1665 
1666 	/*
1667 	 * First, recheck the object type to account for the race when
1668 	 * the vnode is reclaimed.
1669 	 */
1670 	if (object->type != OBJT_VNODE) {
1671 		VM_OBJECT_WUNLOCK(object);
1672 		return;
1673 	}
1674 
1675 	/*
1676 	 * Optimize for the case when writemappings is not going to
1677 	 * zero.
1678 	 */
1679 	inc = end - start;
1680 	if (object->un_pager.vnp.writemappings != inc) {
1681 		object->un_pager.vnp.writemappings -= inc;
1682 		VM_OBJECT_WUNLOCK(object);
1683 		return;
1684 	}
1685 
1686 	vp = object->handle;
1687 	vhold(vp);
1688 	VM_OBJECT_WUNLOCK(object);
1689 	mp = NULL;
1690 	vn_start_write(vp, &mp, V_WAIT);
1691 	vn_lock(vp, LK_SHARED | LK_RETRY);
1692 
1693 	/*
1694 	 * Decrement the object's writemappings, by swapping the start
1695 	 * and end arguments for vnode_pager_update_writecount().  If
1696 	 * there was not a race with vnode reclaimation, then the
1697 	 * vnode's v_writecount is decremented.
1698 	 */
1699 	vnode_pager_update_writecount(object, end, start);
1700 	VOP_UNLOCK(vp);
1701 	vdrop(vp);
1702 	if (mp != NULL)
1703 		vn_finished_write(mp);
1704 }
1705 
1706 static void
vnode_pager_getvp(vm_object_t object,struct vnode ** vpp,bool * vp_heldp)1707 vnode_pager_getvp(vm_object_t object, struct vnode **vpp, bool *vp_heldp)
1708 {
1709 	*vpp = object->handle;
1710 }
1711 
1712 static void
vnode_pager_clean1(struct vnode * vp,int sync_flags)1713 vnode_pager_clean1(struct vnode *vp, int sync_flags)
1714 {
1715 	struct vm_object *obj;
1716 
1717 	ASSERT_VOP_LOCKED(vp, "needs lock for writes");
1718 	obj = vp->v_object;
1719 	if (obj == NULL)
1720 		return;
1721 
1722 	VM_OBJECT_WLOCK(obj);
1723 	vm_object_page_clean(obj, 0, 0, sync_flags);
1724 	VM_OBJECT_WUNLOCK(obj);
1725 }
1726 
1727 void
vnode_pager_clean_sync(struct vnode * vp)1728 vnode_pager_clean_sync(struct vnode *vp)
1729 {
1730 	vnode_pager_clean1(vp, OBJPC_SYNC);
1731 }
1732 
1733 void
vnode_pager_clean_async(struct vnode * vp)1734 vnode_pager_clean_async(struct vnode *vp)
1735 {
1736 	vnode_pager_clean1(vp, 0);
1737 }
1738