2 * SPDX-License-Identifier: BSD-4-Clause
4 * Copyright (c) 1990 University of Utah.
5 * Copyright (c) 1991 The Regents of the University of California.
7 * Copyright (c) 1993, 1994 John S. Dyson
8 * Copyright (c) 1995, David Greenman
10 * This code is derived from software contributed to Berkeley by
11 * the Systems Programming Group of the University of Utah Computer
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
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.
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
42 * from: @(#)vnode_pager.c 7.5 (Berkeley) 4/20/91
46 * Page to/from files (vnodes).
51 * Implement VOP_GETPAGES/PUTPAGES interface for filesystems. Will
52 * greatly re-simplify the vnode_pager.
55 #include <sys/cdefs.h>
56 __FBSDID("$FreeBSD$");
60 #include <sys/param.h>
61 #include <sys/systm.h>
62 #include <sys/sysctl.h>
64 #include <sys/vnode.h>
65 #include <sys/mount.h>
68 #include <sys/vmmeter.h>
69 #include <sys/limits.h>
71 #include <sys/rwlock.h>
72 #include <sys/sf_buf.h>
73 #include <sys/domainset.h>
75 #include <machine/atomic.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>
86 static int vnode_pager_addr(struct vnode *vp, vm_ooffset_t address,
87 daddr_t *rtaddress, int *run);
88 static int vnode_pager_input_smlfs(vm_object_t object, vm_page_t m);
89 static int vnode_pager_input_old(vm_object_t object, vm_page_t m);
90 static void vnode_pager_dealloc(vm_object_t);
91 static int vnode_pager_getpages(vm_object_t, vm_page_t *, int, int *, int *);
92 static int vnode_pager_getpages_async(vm_object_t, vm_page_t *, int, int *,
93 int *, vop_getpages_iodone_t, void *);
94 static void vnode_pager_putpages(vm_object_t, vm_page_t *, int, int, int *);
95 static boolean_t vnode_pager_haspage(vm_object_t, vm_pindex_t, int *, int *);
96 static vm_object_t vnode_pager_alloc(void *, vm_ooffset_t, vm_prot_t,
97 vm_ooffset_t, struct ucred *cred);
98 static int vnode_pager_generic_getpages_done(struct buf *);
99 static void vnode_pager_generic_getpages_done_async(struct buf *);
101 struct pagerops vnodepagerops = {
102 .pgo_alloc = vnode_pager_alloc,
103 .pgo_dealloc = vnode_pager_dealloc,
104 .pgo_getpages = vnode_pager_getpages,
105 .pgo_getpages_async = vnode_pager_getpages_async,
106 .pgo_putpages = vnode_pager_putpages,
107 .pgo_haspage = vnode_pager_haspage,
110 int vnode_pbuf_freecnt;
111 int vnode_async_pbuf_freecnt;
113 static struct domainset *vnode_domainset = NULL;
115 SYSCTL_PROC(_debug, OID_AUTO, vnode_domainset, CTLTYPE_STRING | CTLFLAG_RW,
116 &vnode_domainset, 0, sysctl_handle_domainset, "A",
117 "Default vnode NUMA policy");
119 /* Create the VM system backing object for this vnode */
121 vnode_create_vobject(struct vnode *vp, off_t isize, struct thread *td)
124 vm_ooffset_t size = isize;
127 if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE)
130 while ((object = vp->v_object) != NULL) {
131 VM_OBJECT_WLOCK(object);
132 if (!(object->flags & OBJ_DEAD)) {
133 VM_OBJECT_WUNLOCK(object);
137 vm_object_set_flag(object, OBJ_DISCONNECTWNT);
138 VM_OBJECT_SLEEP(object, object, PDROP | PVM, "vodead", 0);
139 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
143 if (vn_isdisk(vp, NULL)) {
144 size = IDX_TO_OFF(INT_MAX);
146 if (VOP_GETATTR(vp, &va, td->td_ucred))
152 object = vnode_pager_alloc(vp, size, 0, 0, td->td_ucred);
154 * Dereference the reference we just created. This assumes
155 * that the object is associated with the vp.
157 VM_OBJECT_WLOCK(object);
159 VM_OBJECT_WUNLOCK(object);
162 KASSERT(vp->v_object != NULL, ("vnode_create_vobject: NULL object"));
168 vnode_destroy_vobject(struct vnode *vp)
170 struct vm_object *obj;
175 ASSERT_VOP_ELOCKED(vp, "vnode_destroy_vobject");
176 VM_OBJECT_WLOCK(obj);
177 umtx_shm_object_terminated(obj);
178 if (obj->ref_count == 0) {
180 * don't double-terminate the object
182 if ((obj->flags & OBJ_DEAD) == 0) {
183 vm_object_terminate(obj);
186 * Waiters were already handled during object
187 * termination. The exclusive vnode lock hopefully
188 * prevented new waiters from referencing the dying
191 KASSERT((obj->flags & OBJ_DISCONNECTWNT) == 0,
192 ("OBJ_DISCONNECTWNT set obj %p flags %x",
195 VM_OBJECT_WUNLOCK(obj);
199 * Woe to the process that tries to page now :-).
201 vm_pager_deallocate(obj);
202 VM_OBJECT_WUNLOCK(obj);
204 KASSERT(vp->v_object == NULL, ("vp %p obj %p", vp, vp->v_object));
209 * Allocate (or lookup) pager for a vnode.
210 * Handle is a vnode pointer.
215 vnode_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
216 vm_ooffset_t offset, struct ucred *cred)
222 * Pageout to vnode, no can do yet.
227 vp = (struct vnode *) handle;
230 * If the object is being terminated, wait for it to
234 while ((object = vp->v_object) != NULL) {
235 VM_OBJECT_WLOCK(object);
236 if ((object->flags & OBJ_DEAD) == 0)
238 vm_object_set_flag(object, OBJ_DISCONNECTWNT);
239 VM_OBJECT_SLEEP(object, object, PDROP | PVM, "vadead", 0);
242 KASSERT(vp->v_usecount != 0, ("vnode_pager_alloc: no vnode reference"));
244 if (object == NULL) {
246 * Add an object of the appropriate size
248 object = vm_object_allocate(OBJT_VNODE, OFF_TO_IDX(round_page(size)));
250 object->un_pager.vnp.vnp_size = size;
251 object->un_pager.vnp.writemappings = 0;
252 object->domain.dr_policy = vnode_domainset;
254 object->handle = handle;
256 if (vp->v_object != NULL) {
258 * Object has been created while we were sleeping
261 VM_OBJECT_WLOCK(object);
262 KASSERT(object->ref_count == 1,
263 ("leaked ref %p %d", object, object->ref_count));
264 object->type = OBJT_DEAD;
265 object->ref_count = 0;
266 VM_OBJECT_WUNLOCK(object);
267 vm_object_destroy(object);
270 vp->v_object = object;
274 #if VM_NRESERVLEVEL > 0
275 vm_object_color(object, 0);
277 VM_OBJECT_WUNLOCK(object);
284 * The object must be locked.
287 vnode_pager_dealloc(vm_object_t object)
294 panic("vnode_pager_dealloc: pager already dealloced");
296 VM_OBJECT_ASSERT_WLOCKED(object);
297 vm_object_pip_wait(object, "vnpdea");
298 refs = object->ref_count;
300 object->handle = NULL;
301 object->type = OBJT_DEAD;
302 if (object->flags & OBJ_DISCONNECTWNT) {
303 vm_object_clear_flag(object, OBJ_DISCONNECTWNT);
306 ASSERT_VOP_ELOCKED(vp, "vnode_pager_dealloc");
307 if (object->un_pager.vnp.writemappings > 0) {
308 object->un_pager.vnp.writemappings = 0;
309 VOP_ADD_WRITECOUNT_CHECKED(vp, -1);
310 CTR3(KTR_VFS, "%s: vp %p v_writecount decreased to %d",
311 __func__, vp, vp->v_writecount);
317 * vm_map_entry_set_vnode_text() cannot reach this vnode by
318 * following object->handle. Clear all text references now.
319 * This also clears the transient references from
320 * kern_execve(), which is fine because dead_vnodeops uses nop
321 * for VOP_UNSET_TEXT().
323 if (vp->v_writecount < 0)
324 vp->v_writecount = 0;
326 VM_OBJECT_WUNLOCK(object);
329 VM_OBJECT_WLOCK(object);
333 vnode_pager_haspage(vm_object_t object, vm_pindex_t pindex, int *before,
336 struct vnode *vp = object->handle;
342 int pagesperblock, blocksperpage;
344 VM_OBJECT_ASSERT_WLOCKED(object);
346 * If no vp or vp is doomed or marked transparent to VM, we do not
349 if (vp == NULL || vp->v_iflag & VI_DOOMED)
352 * If the offset is beyond end of file we do
355 if (IDX_TO_OFF(pindex) >= object->un_pager.vnp.vnp_size)
358 bsize = vp->v_mount->mnt_stat.f_iosize;
359 pagesperblock = bsize / PAGE_SIZE;
361 if (pagesperblock > 0) {
362 reqblock = pindex / pagesperblock;
364 blocksperpage = (PAGE_SIZE / bsize);
365 reqblock = pindex * blocksperpage;
367 VM_OBJECT_WUNLOCK(object);
368 err = VOP_BMAP(vp, reqblock, NULL, &bn, after, before);
369 VM_OBJECT_WLOCK(object);
374 if (pagesperblock > 0) {
375 poff = pindex - (reqblock * pagesperblock);
377 *before *= pagesperblock;
382 * The BMAP vop can report a partial block in the
383 * 'after', but must not report blocks after EOF.
384 * Assert the latter, and truncate 'after' in case
387 KASSERT((reqblock + *after) * pagesperblock <
388 roundup2(object->size, pagesperblock),
389 ("%s: reqblock %jd after %d size %ju", __func__,
390 (intmax_t )reqblock, *after,
391 (uintmax_t )object->size));
392 *after *= pagesperblock;
393 *after += pagesperblock - (poff + 1);
394 if (pindex + *after >= object->size)
395 *after = object->size - 1 - pindex;
399 *before /= blocksperpage;
403 *after /= blocksperpage;
410 * Lets the VM system know about a change in size for a file.
411 * We adjust our own internal size and flush any cached pages in
412 * the associated object that are affected by the size change.
414 * Note: this routine may be invoked as a result of a pager put
415 * operation (possibly at object termination time), so we must be careful.
418 vnode_pager_setsize(struct vnode *vp, vm_ooffset_t nsize)
422 vm_pindex_t nobjsize;
424 if ((object = vp->v_object) == NULL)
426 /* ASSERT_VOP_ELOCKED(vp, "vnode_pager_setsize and not locked vnode"); */
427 VM_OBJECT_WLOCK(object);
428 if (object->type == OBJT_DEAD) {
429 VM_OBJECT_WUNLOCK(object);
432 KASSERT(object->type == OBJT_VNODE,
433 ("not vnode-backed object %p", object));
434 if (nsize == object->un_pager.vnp.vnp_size) {
436 * Hasn't changed size
438 VM_OBJECT_WUNLOCK(object);
441 nobjsize = OFF_TO_IDX(nsize + PAGE_MASK);
442 if (nsize < object->un_pager.vnp.vnp_size) {
444 * File has shrunk. Toss any cached pages beyond the new EOF.
446 if (nobjsize < object->size)
447 vm_object_page_remove(object, nobjsize, object->size,
450 * this gets rid of garbage at the end of a page that is now
451 * only partially backed by the vnode.
453 * XXX for some reason (I don't know yet), if we take a
454 * completely invalid page and mark it partially valid
455 * it can screw up NFS reads, so we don't allow the case.
457 if ((nsize & PAGE_MASK) &&
458 (m = vm_page_lookup(object, OFF_TO_IDX(nsize))) != NULL &&
460 int base = (int)nsize & PAGE_MASK;
461 int size = PAGE_SIZE - base;
464 * Clear out partial-page garbage in case
465 * the page has been mapped.
467 pmap_zero_page_area(m, base, size);
470 * Update the valid bits to reflect the blocks that
471 * have been zeroed. Some of these valid bits may
472 * have already been set.
474 vm_page_set_valid_range(m, base, size);
477 * Round "base" to the next block boundary so that the
478 * dirty bit for a partially zeroed block is not
481 base = roundup2(base, DEV_BSIZE);
484 * Clear out partial-page dirty bits.
486 * note that we do not clear out the valid
487 * bits. This would prevent bogus_page
488 * replacement from working properly.
490 vm_page_clear_dirty(m, base, PAGE_SIZE - base);
493 object->un_pager.vnp.vnp_size = nsize;
494 object->size = nobjsize;
495 VM_OBJECT_WUNLOCK(object);
499 * calculate the linear (byte) disk address of specified virtual
503 vnode_pager_addr(struct vnode *vp, vm_ooffset_t address, daddr_t *rtaddress,
514 if (vp->v_iflag & VI_DOOMED)
517 bsize = vp->v_mount->mnt_stat.f_iosize;
518 vblock = address / bsize;
519 voffset = address % bsize;
521 err = VOP_BMAP(vp, vblock, NULL, rtaddress, run, NULL);
523 if (*rtaddress != -1)
524 *rtaddress += voffset / DEV_BSIZE;
527 *run *= bsize/PAGE_SIZE;
528 *run -= voffset/PAGE_SIZE;
536 * small block filesystem vnode pager input
539 vnode_pager_input_smlfs(vm_object_t object, vm_page_t m)
552 if (vp->v_iflag & VI_DOOMED)
555 bsize = vp->v_mount->mnt_stat.f_iosize;
557 VOP_BMAP(vp, 0, &bo, 0, NULL, NULL);
559 sf = sf_buf_alloc(m, 0);
561 for (i = 0; i < PAGE_SIZE / bsize; i++) {
562 vm_ooffset_t address;
564 bits = vm_page_bits(i * bsize, bsize);
568 address = IDX_TO_OFF(m->pindex) + i * bsize;
569 if (address >= object->un_pager.vnp.vnp_size) {
572 error = vnode_pager_addr(vp, address, &fileaddr, NULL);
576 if (fileaddr != -1) {
577 bp = getpbuf(&vnode_pbuf_freecnt);
579 /* build a minimal buffer header */
580 bp->b_iocmd = BIO_READ;
581 bp->b_iodone = bdone;
582 KASSERT(bp->b_rcred == NOCRED, ("leaking read ucred"));
583 KASSERT(bp->b_wcred == NOCRED, ("leaking write ucred"));
584 bp->b_rcred = crhold(curthread->td_ucred);
585 bp->b_wcred = crhold(curthread->td_ucred);
586 bp->b_data = (caddr_t)sf_buf_kva(sf) + i * bsize;
587 bp->b_blkno = fileaddr;
590 bp->b_bcount = bsize;
591 bp->b_bufsize = bsize;
592 bp->b_runningbufspace = bp->b_bufsize;
593 atomic_add_long(&runningbufspace, bp->b_runningbufspace);
596 bp->b_iooffset = dbtob(bp->b_blkno);
599 bwait(bp, PVM, "vnsrd");
601 if ((bp->b_ioflags & BIO_ERROR) != 0)
605 * free the buffer header back to the swap buffer pool
609 relpbuf(bp, &vnode_pbuf_freecnt);
613 bzero((caddr_t)sf_buf_kva(sf) + i * bsize, bsize);
614 KASSERT((m->dirty & bits) == 0,
615 ("vnode_pager_input_smlfs: page %p is dirty", m));
616 VM_OBJECT_WLOCK(object);
618 VM_OBJECT_WUNLOCK(object);
622 return VM_PAGER_ERROR;
628 * old style vnode pager input routine
631 vnode_pager_input_old(vm_object_t object, vm_page_t m)
640 VM_OBJECT_ASSERT_WLOCKED(object);
644 * Return failure if beyond current EOF
646 if (IDX_TO_OFF(m->pindex) >= object->un_pager.vnp.vnp_size) {
650 if (IDX_TO_OFF(m->pindex) + size > object->un_pager.vnp.vnp_size)
651 size = object->un_pager.vnp.vnp_size - IDX_TO_OFF(m->pindex);
653 VM_OBJECT_WUNLOCK(object);
656 * Allocate a kernel virtual address and initialize so that
657 * we can use VOP_READ/WRITE routines.
659 sf = sf_buf_alloc(m, 0);
661 aiov.iov_base = (caddr_t)sf_buf_kva(sf);
663 auio.uio_iov = &aiov;
665 auio.uio_offset = IDX_TO_OFF(m->pindex);
666 auio.uio_segflg = UIO_SYSSPACE;
667 auio.uio_rw = UIO_READ;
668 auio.uio_resid = size;
669 auio.uio_td = curthread;
671 error = VOP_READ(vp, &auio, 0, curthread->td_ucred);
673 int count = size - auio.uio_resid;
677 else if (count != PAGE_SIZE)
678 bzero((caddr_t)sf_buf_kva(sf) + count,
683 VM_OBJECT_WLOCK(object);
685 KASSERT(m->dirty == 0, ("vnode_pager_input_old: page %p is dirty", m));
687 m->valid = VM_PAGE_BITS_ALL;
688 return error ? VM_PAGER_ERROR : VM_PAGER_OK;
692 * generic vnode pager input routine
696 * Local media VFS's that do not implement their own VOP_GETPAGES
697 * should have their VOP_GETPAGES call to vnode_pager_generic_getpages()
698 * to implement the previous behaviour.
700 * All other FS's should use the bypass to get to the local media
701 * backing vp's VOP_GETPAGES.
704 vnode_pager_getpages(vm_object_t object, vm_page_t *m, int count, int *rbehind,
711 VM_OBJECT_WUNLOCK(object);
712 rtval = VOP_GETPAGES(vp, m, count, rbehind, rahead);
713 KASSERT(rtval != EOPNOTSUPP,
714 ("vnode_pager: FS getpages not implemented\n"));
715 VM_OBJECT_WLOCK(object);
720 vnode_pager_getpages_async(vm_object_t object, vm_page_t *m, int count,
721 int *rbehind, int *rahead, vop_getpages_iodone_t iodone, void *arg)
727 VM_OBJECT_WUNLOCK(object);
728 rtval = VOP_GETPAGES_ASYNC(vp, m, count, rbehind, rahead, iodone, arg);
729 KASSERT(rtval != EOPNOTSUPP,
730 ("vnode_pager: FS getpages_async not implemented\n"));
731 VM_OBJECT_WLOCK(object);
736 * The implementation of VOP_GETPAGES() and VOP_GETPAGES_ASYNC() for
737 * local filesystems, where partially valid pages can only occur at
741 vnode_pager_local_getpages(struct vop_getpages_args *ap)
744 return (vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
745 ap->a_rbehind, ap->a_rahead, NULL, NULL));
749 vnode_pager_local_getpages_async(struct vop_getpages_async_args *ap)
752 return (vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
753 ap->a_rbehind, ap->a_rahead, ap->a_iodone, ap->a_arg));
757 * This is now called from local media FS's to operate against their
758 * own vnodes if they fail to implement VOP_GETPAGES.
761 vnode_pager_generic_getpages(struct vnode *vp, vm_page_t *m, int count,
762 int *a_rbehind, int *a_rahead, vop_getpages_iodone_t iodone, void *arg)
771 int bsize, pagesperblock, *freecnt;
772 int error, before, after, rbehind, rahead, poff, i;
773 int bytecount, secmask;
775 KASSERT(vp->v_type != VCHR && vp->v_type != VBLK,
776 ("%s does not support devices", __func__));
778 if (vp->v_iflag & VI_DOOMED)
779 return (VM_PAGER_BAD);
781 object = vp->v_object;
782 foff = IDX_TO_OFF(m[0]->pindex);
783 bsize = vp->v_mount->mnt_stat.f_iosize;
784 pagesperblock = bsize / PAGE_SIZE;
786 KASSERT(foff < object->un_pager.vnp.vnp_size,
787 ("%s: page %p offset beyond vp %p size", __func__, m[0], vp));
788 KASSERT(count <= nitems(bp->b_pages),
789 ("%s: requested %d pages", __func__, count));
792 * The last page has valid blocks. Invalid part can only
793 * exist at the end of file, and the page is made fully valid
794 * by zeroing in vm_pager_get_pages().
796 if (m[count - 1]->valid != 0 && --count == 0) {
798 iodone(arg, m, 1, 0);
799 return (VM_PAGER_OK);
803 * Synchronous and asynchronous paging operations use different
804 * free pbuf counters. This is done to avoid asynchronous requests
805 * to consume all pbufs.
806 * Allocate the pbuf at the very beginning of the function, so that
807 * if we are low on certain kind of pbufs don't even proceed to BMAP,
810 freecnt = iodone != NULL ?
811 &vnode_async_pbuf_freecnt : &vnode_pbuf_freecnt;
812 bp = getpbuf(freecnt);
815 * Get the underlying device blocks for the file with VOP_BMAP().
816 * If the file system doesn't support VOP_BMAP, use old way of
817 * getting pages via VOP_READ.
819 error = VOP_BMAP(vp, foff / bsize, &bo, &bp->b_blkno, &after, &before);
820 if (error == EOPNOTSUPP) {
821 relpbuf(bp, freecnt);
822 VM_OBJECT_WLOCK(object);
823 for (i = 0; i < count; i++) {
824 VM_CNT_INC(v_vnodein);
825 VM_CNT_INC(v_vnodepgsin);
826 error = vnode_pager_input_old(object, m[i]);
830 VM_OBJECT_WUNLOCK(object);
832 } else if (error != 0) {
833 relpbuf(bp, freecnt);
834 return (VM_PAGER_ERROR);
838 * If the file system supports BMAP, but blocksize is smaller
839 * than a page size, then use special small filesystem code.
841 if (pagesperblock == 0) {
842 relpbuf(bp, freecnt);
843 for (i = 0; i < count; i++) {
844 VM_CNT_INC(v_vnodein);
845 VM_CNT_INC(v_vnodepgsin);
846 error = vnode_pager_input_smlfs(object, m[i]);
854 * A sparse file can be encountered only for a single page request,
855 * which may not be preceded by call to vm_pager_haspage().
857 if (bp->b_blkno == -1) {
859 ("%s: array[%d] request to a sparse file %p", __func__,
861 relpbuf(bp, freecnt);
862 pmap_zero_page(m[0]);
863 KASSERT(m[0]->dirty == 0, ("%s: page %p is dirty",
865 VM_OBJECT_WLOCK(object);
866 m[0]->valid = VM_PAGE_BITS_ALL;
867 VM_OBJECT_WUNLOCK(object);
868 return (VM_PAGER_OK);
872 blkno0 = bp->b_blkno;
874 bp->b_blkno += (foff % bsize) / DEV_BSIZE;
876 /* Recalculate blocks available after/before to pages. */
877 poff = (foff % bsize) / PAGE_SIZE;
878 before *= pagesperblock;
880 after *= pagesperblock;
881 after += pagesperblock - (poff + 1);
882 if (m[0]->pindex + after >= object->size)
883 after = object->size - 1 - m[0]->pindex;
884 KASSERT(count <= after + 1, ("%s: %d pages asked, can do only %d",
885 __func__, count, after + 1));
888 /* Trim requested rbehind/rahead to possible values. */
889 rbehind = a_rbehind ? *a_rbehind : 0;
890 rahead = a_rahead ? *a_rahead : 0;
891 rbehind = min(rbehind, before);
892 rbehind = min(rbehind, m[0]->pindex);
893 rahead = min(rahead, after);
894 rahead = min(rahead, object->size - m[count - 1]->pindex);
896 * Check that total amount of pages fit into buf. Trim rbehind and
897 * rahead evenly if not.
899 if (rbehind + rahead + count > nitems(bp->b_pages)) {
902 trim = rbehind + rahead + count - nitems(bp->b_pages) + 1;
903 sum = rbehind + rahead;
904 if (rbehind == before) {
905 /* Roundup rbehind trim to block size. */
906 rbehind -= roundup(trim * rbehind / sum, pagesperblock);
910 rbehind -= trim * rbehind / sum;
911 rahead -= trim * rahead / sum;
913 KASSERT(rbehind + rahead + count <= nitems(bp->b_pages),
914 ("%s: behind %d ahead %d count %d", __func__,
915 rbehind, rahead, count));
918 * Fill in the bp->b_pages[] array with requested and optional
919 * read behind or read ahead pages. Read behind pages are looked
920 * up in a backward direction, down to a first cached page. Same
921 * for read ahead pages, but there is no need to shift the array
922 * in case of encountering a cached page.
924 i = bp->b_npages = 0;
926 vm_pindex_t startpindex, tpindex;
929 VM_OBJECT_WLOCK(object);
930 startpindex = m[0]->pindex - rbehind;
931 if ((p = TAILQ_PREV(m[0], pglist, listq)) != NULL &&
932 p->pindex >= startpindex)
933 startpindex = p->pindex + 1;
935 /* tpindex is unsigned; beware of numeric underflow. */
936 for (tpindex = m[0]->pindex - 1;
937 tpindex >= startpindex && tpindex < m[0]->pindex;
939 p = vm_page_alloc(object, tpindex, VM_ALLOC_NORMAL);
941 /* Shift the array. */
942 for (int j = 0; j < i; j++)
943 bp->b_pages[j] = bp->b_pages[j +
944 tpindex + 1 - startpindex];
947 bp->b_pages[tpindex - startpindex] = p;
952 bp->b_blkno -= IDX_TO_OFF(i) / DEV_BSIZE;
956 /* Requested pages. */
957 for (int j = 0; j < count; j++, i++)
958 bp->b_pages[i] = m[j];
959 bp->b_npages += count;
962 vm_pindex_t endpindex, tpindex;
965 if (!VM_OBJECT_WOWNED(object))
966 VM_OBJECT_WLOCK(object);
967 endpindex = m[count - 1]->pindex + rahead + 1;
968 if ((p = TAILQ_NEXT(m[count - 1], listq)) != NULL &&
969 p->pindex < endpindex)
970 endpindex = p->pindex;
971 if (endpindex > object->size)
972 endpindex = object->size;
974 for (tpindex = m[count - 1]->pindex + 1;
975 tpindex < endpindex; i++, tpindex++) {
976 p = vm_page_alloc(object, tpindex, VM_ALLOC_NORMAL);
982 bp->b_pgafter = i - bp->b_npages;
987 if (VM_OBJECT_WOWNED(object))
988 VM_OBJECT_WUNLOCK(object);
990 /* Report back actual behind/ahead read. */
992 *a_rbehind = bp->b_pgbefore;
994 *a_rahead = bp->b_pgafter;
997 KASSERT(bp->b_npages <= nitems(bp->b_pages),
998 ("%s: buf %p overflowed", __func__, bp));
999 for (int j = 1, prev = 0; j < bp->b_npages; j++) {
1000 if (bp->b_pages[j] == bogus_page)
1002 KASSERT(bp->b_pages[j]->pindex - bp->b_pages[prev]->pindex ==
1003 j - prev, ("%s: pages array not consecutive, bp %p",
1010 * Recalculate first offset and bytecount with regards to read behind.
1011 * Truncate bytecount to vnode real size and round up physical size
1014 foff = IDX_TO_OFF(bp->b_pages[0]->pindex);
1015 bytecount = bp->b_npages << PAGE_SHIFT;
1016 if ((foff + bytecount) > object->un_pager.vnp.vnp_size)
1017 bytecount = object->un_pager.vnp.vnp_size - foff;
1018 secmask = bo->bo_bsize - 1;
1019 KASSERT(secmask < PAGE_SIZE && secmask > 0,
1020 ("%s: sector size %d too large", __func__, secmask + 1));
1021 bytecount = (bytecount + secmask) & ~secmask;
1024 * And map the pages to be read into the kva, if the filesystem
1025 * requires mapped buffers.
1027 if ((vp->v_mount->mnt_kern_flag & MNTK_UNMAPPED_BUFS) != 0 &&
1028 unmapped_buf_allowed) {
1029 bp->b_data = unmapped_buf;
1032 bp->b_data = bp->b_kvabase;
1033 pmap_qenter((vm_offset_t)bp->b_data, bp->b_pages, bp->b_npages);
1036 /* Build a minimal buffer header. */
1037 bp->b_iocmd = BIO_READ;
1038 KASSERT(bp->b_rcred == NOCRED, ("leaking read ucred"));
1039 KASSERT(bp->b_wcred == NOCRED, ("leaking write ucred"));
1040 bp->b_rcred = crhold(curthread->td_ucred);
1041 bp->b_wcred = crhold(curthread->td_ucred);
1044 bp->b_bcount = bp->b_bufsize = bp->b_runningbufspace = bytecount;
1045 bp->b_iooffset = dbtob(bp->b_blkno);
1046 KASSERT(IDX_TO_OFF(m[0]->pindex - bp->b_pages[0]->pindex) ==
1047 (blkno0 - bp->b_blkno) * DEV_BSIZE +
1048 IDX_TO_OFF(m[0]->pindex) % bsize,
1049 ("wrong offsets bsize %d m[0] %ju b_pages[0] %ju "
1050 "blkno0 %ju b_blkno %ju", bsize,
1051 (uintmax_t)m[0]->pindex, (uintmax_t)bp->b_pages[0]->pindex,
1052 (uintmax_t)blkno0, (uintmax_t)bp->b_blkno));
1054 atomic_add_long(&runningbufspace, bp->b_runningbufspace);
1055 VM_CNT_INC(v_vnodein);
1056 VM_CNT_ADD(v_vnodepgsin, bp->b_npages);
1058 if (iodone != NULL) { /* async */
1059 bp->b_pgiodone = iodone;
1060 bp->b_caller1 = arg;
1061 bp->b_iodone = vnode_pager_generic_getpages_done_async;
1062 bp->b_flags |= B_ASYNC;
1065 return (VM_PAGER_OK);
1067 bp->b_iodone = bdone;
1069 bwait(bp, PVM, "vnread");
1070 error = vnode_pager_generic_getpages_done(bp);
1071 for (i = 0; i < bp->b_npages; i++)
1072 bp->b_pages[i] = NULL;
1075 relpbuf(bp, &vnode_pbuf_freecnt);
1076 return (error != 0 ? VM_PAGER_ERROR : VM_PAGER_OK);
1081 vnode_pager_generic_getpages_done_async(struct buf *bp)
1085 error = vnode_pager_generic_getpages_done(bp);
1086 /* Run the iodone upon the requested range. */
1087 bp->b_pgiodone(bp->b_caller1, bp->b_pages + bp->b_pgbefore,
1088 bp->b_npages - bp->b_pgbefore - bp->b_pgafter, error);
1089 for (int i = 0; i < bp->b_npages; i++)
1090 bp->b_pages[i] = NULL;
1093 relpbuf(bp, &vnode_async_pbuf_freecnt);
1097 vnode_pager_generic_getpages_done(struct buf *bp)
1100 off_t tfoff, nextoff;
1103 error = (bp->b_ioflags & BIO_ERROR) != 0 ? EIO : 0;
1104 object = bp->b_vp->v_object;
1106 if (error == 0 && bp->b_bcount != bp->b_npages * PAGE_SIZE) {
1107 if (!buf_mapped(bp)) {
1108 bp->b_data = bp->b_kvabase;
1109 pmap_qenter((vm_offset_t)bp->b_data, bp->b_pages,
1112 bzero(bp->b_data + bp->b_bcount,
1113 PAGE_SIZE * bp->b_npages - bp->b_bcount);
1115 if (buf_mapped(bp)) {
1116 pmap_qremove((vm_offset_t)bp->b_data, bp->b_npages);
1117 bp->b_data = unmapped_buf;
1120 VM_OBJECT_WLOCK(object);
1121 for (i = 0, tfoff = IDX_TO_OFF(bp->b_pages[0]->pindex);
1122 i < bp->b_npages; i++, tfoff = nextoff) {
1125 nextoff = tfoff + PAGE_SIZE;
1126 mt = bp->b_pages[i];
1128 if (nextoff <= object->un_pager.vnp.vnp_size) {
1130 * Read filled up entire page.
1132 mt->valid = VM_PAGE_BITS_ALL;
1133 KASSERT(mt->dirty == 0,
1134 ("%s: page %p is dirty", __func__, mt));
1135 KASSERT(!pmap_page_is_mapped(mt),
1136 ("%s: page %p is mapped", __func__, mt));
1139 * Read did not fill up entire page.
1141 * Currently we do not set the entire page valid,
1142 * we just try to clear the piece that we couldn't
1145 vm_page_set_valid_range(mt, 0,
1146 object->un_pager.vnp.vnp_size - tfoff);
1147 KASSERT((mt->dirty & vm_page_bits(0,
1148 object->un_pager.vnp.vnp_size - tfoff)) == 0,
1149 ("%s: page %p is dirty", __func__, mt));
1152 if (i < bp->b_pgbefore || i >= bp->b_npages - bp->b_pgafter)
1153 vm_page_readahead_finish(mt);
1155 VM_OBJECT_WUNLOCK(object);
1157 printf("%s: I/O read error %d\n", __func__, error);
1163 * EOPNOTSUPP is no longer legal. For local media VFS's that do not
1164 * implement their own VOP_PUTPAGES, their VOP_PUTPAGES should call to
1165 * vnode_pager_generic_putpages() to implement the previous behaviour.
1167 * All other FS's should use the bypass to get to the local media
1168 * backing vp's VOP_PUTPAGES.
1171 vnode_pager_putpages(vm_object_t object, vm_page_t *m, int count,
1172 int flags, int *rtvals)
1176 int bytes = count * PAGE_SIZE;
1179 * Force synchronous operation if we are extremely low on memory
1180 * to prevent a low-memory deadlock. VOP operations often need to
1181 * allocate more memory to initiate the I/O ( i.e. do a BMAP
1182 * operation ). The swapper handles the case by limiting the amount
1183 * of asynchronous I/O, but that sort of solution doesn't scale well
1184 * for the vnode pager without a lot of work.
1186 * Also, the backing vnode's iodone routine may not wake the pageout
1187 * daemon up. This should be probably be addressed XXX.
1190 if (vm_page_count_min())
1191 flags |= VM_PAGER_PUT_SYNC;
1194 * Call device-specific putpages function
1196 vp = object->handle;
1197 VM_OBJECT_WUNLOCK(object);
1198 rtval = VOP_PUTPAGES(vp, m, bytes, flags, rtvals);
1199 KASSERT(rtval != EOPNOTSUPP,
1200 ("vnode_pager: stale FS putpages\n"));
1201 VM_OBJECT_WLOCK(object);
1205 vn_off2bidx(vm_ooffset_t offset)
1208 return ((offset & PAGE_MASK) / DEV_BSIZE);
1212 vn_dirty_blk(vm_page_t m, vm_ooffset_t offset)
1215 KASSERT(IDX_TO_OFF(m->pindex) <= offset &&
1216 offset < IDX_TO_OFF(m->pindex + 1),
1217 ("page %p pidx %ju offset %ju", m, (uintmax_t)m->pindex,
1218 (uintmax_t)offset));
1219 return ((m->dirty & ((vm_page_bits_t)1 << vn_off2bidx(offset))) != 0);
1223 * This is now called from local media FS's to operate against their
1224 * own vnodes if they fail to implement VOP_PUTPAGES.
1226 * This is typically called indirectly via the pageout daemon and
1227 * clustering has already typically occurred, so in general we ask the
1228 * underlying filesystem to write the data out asynchronously rather
1232 vnode_pager_generic_putpages(struct vnode *vp, vm_page_t *ma, int bytecount,
1233 int flags, int *rtvals)
1237 vm_ooffset_t maxblksz, next_offset, poffset, prev_offset;
1240 off_t prev_resid, wrsz;
1241 int count, error, i, maxsize, ncount, pgoff, ppscheck;
1243 static struct timeval lastfail;
1246 object = vp->v_object;
1247 count = bytecount / PAGE_SIZE;
1249 for (i = 0; i < count; i++)
1250 rtvals[i] = VM_PAGER_ERROR;
1252 if ((int64_t)ma[0]->pindex < 0) {
1253 printf("vnode_pager_generic_putpages: "
1254 "attempt to write meta-data 0x%jx(%lx)\n",
1255 (uintmax_t)ma[0]->pindex, (u_long)ma[0]->dirty);
1256 rtvals[0] = VM_PAGER_BAD;
1257 return (VM_PAGER_BAD);
1260 maxsize = count * PAGE_SIZE;
1263 poffset = IDX_TO_OFF(ma[0]->pindex);
1266 * If the page-aligned write is larger then the actual file we
1267 * have to invalidate pages occurring beyond the file EOF. However,
1268 * there is an edge case where a file may not be page-aligned where
1269 * the last page is partially invalid. In this case the filesystem
1270 * may not properly clear the dirty bits for the entire page (which
1271 * could be VM_PAGE_BITS_ALL due to the page having been mmap()d).
1272 * With the page locked we are free to fix-up the dirty bits here.
1274 * We do not under any circumstances truncate the valid bits, as
1275 * this will screw up bogus page replacement.
1277 VM_OBJECT_RLOCK(object);
1278 if (maxsize + poffset > object->un_pager.vnp.vnp_size) {
1279 if (!VM_OBJECT_TRYUPGRADE(object)) {
1280 VM_OBJECT_RUNLOCK(object);
1281 VM_OBJECT_WLOCK(object);
1282 if (maxsize + poffset <= object->un_pager.vnp.vnp_size)
1285 if (object->un_pager.vnp.vnp_size > poffset) {
1286 maxsize = object->un_pager.vnp.vnp_size - poffset;
1287 ncount = btoc(maxsize);
1288 if ((pgoff = (int)maxsize & PAGE_MASK) != 0) {
1289 pgoff = roundup2(pgoff, DEV_BSIZE);
1292 * If the object is locked and the following
1293 * conditions hold, then the page's dirty
1294 * field cannot be concurrently changed by a
1298 vm_page_assert_sbusied(m);
1299 KASSERT(!pmap_page_is_write_mapped(m),
1300 ("vnode_pager_generic_putpages: page %p is not read-only", m));
1301 MPASS(m->dirty != 0);
1302 vm_page_clear_dirty(m, pgoff, PAGE_SIZE -
1309 for (i = ncount; i < count; i++)
1310 rtvals[i] = VM_PAGER_BAD;
1312 VM_OBJECT_LOCK_DOWNGRADE(object);
1315 auio.uio_iov = &aiov;
1316 auio.uio_segflg = UIO_NOCOPY;
1317 auio.uio_rw = UIO_WRITE;
1319 maxblksz = roundup2(poffset + maxsize, DEV_BSIZE);
1321 for (prev_offset = poffset; prev_offset < maxblksz;) {
1322 /* Skip clean blocks. */
1323 for (in_hole = true; in_hole && prev_offset < maxblksz;) {
1324 m = ma[OFF_TO_IDX(prev_offset - poffset)];
1325 for (i = vn_off2bidx(prev_offset);
1326 i < sizeof(vm_page_bits_t) * NBBY &&
1327 prev_offset < maxblksz; i++) {
1328 if (vn_dirty_blk(m, prev_offset)) {
1332 prev_offset += DEV_BSIZE;
1338 /* Find longest run of dirty blocks. */
1339 for (next_offset = prev_offset; next_offset < maxblksz;) {
1340 m = ma[OFF_TO_IDX(next_offset - poffset)];
1341 for (i = vn_off2bidx(next_offset);
1342 i < sizeof(vm_page_bits_t) * NBBY &&
1343 next_offset < maxblksz; i++) {
1344 if (!vn_dirty_blk(m, next_offset))
1346 next_offset += DEV_BSIZE;
1350 if (next_offset > poffset + maxsize)
1351 next_offset = poffset + maxsize;
1354 * Getting here requires finding a dirty block in the
1355 * 'skip clean blocks' loop.
1357 MPASS(prev_offset < next_offset);
1359 VM_OBJECT_RUNLOCK(object);
1360 aiov.iov_base = NULL;
1361 auio.uio_iovcnt = 1;
1362 auio.uio_offset = prev_offset;
1363 prev_resid = auio.uio_resid = aiov.iov_len = next_offset -
1365 error = VOP_WRITE(vp, &auio,
1366 vnode_pager_putpages_ioflags(flags), curthread->td_ucred);
1368 wrsz = prev_resid - auio.uio_resid;
1370 if (ppsratecheck(&lastfail, &curfail, 1) != 0) {
1371 vn_printf(vp, "vnode_pager_putpages: "
1372 "zero-length write at %ju resid %zd\n",
1373 auio.uio_offset, auio.uio_resid);
1375 VM_OBJECT_RLOCK(object);
1379 /* Adjust the starting offset for next iteration. */
1380 prev_offset += wrsz;
1381 MPASS(auio.uio_offset == prev_offset);
1384 if (error != 0 && (ppscheck = ppsratecheck(&lastfail,
1386 vn_printf(vp, "vnode_pager_putpages: I/O error %d\n",
1388 if (auio.uio_resid != 0 && (ppscheck != 0 ||
1389 ppsratecheck(&lastfail, &curfail, 1) != 0))
1390 vn_printf(vp, "vnode_pager_putpages: residual I/O %zd "
1391 "at %ju\n", auio.uio_resid,
1392 (uintmax_t)ma[0]->pindex);
1393 VM_OBJECT_RLOCK(object);
1394 if (error != 0 || auio.uio_resid != 0)
1398 /* Mark completely processed pages. */
1399 for (i = 0; i < OFF_TO_IDX(prev_offset - poffset); i++)
1400 rtvals[i] = VM_PAGER_OK;
1401 /* Mark partial EOF page. */
1402 if (prev_offset == poffset + maxsize && (prev_offset & PAGE_MASK) != 0)
1403 rtvals[i++] = VM_PAGER_OK;
1404 /* Unwritten pages in range, free bonus if the page is clean. */
1405 for (; i < ncount; i++)
1406 rtvals[i] = ma[i]->dirty == 0 ? VM_PAGER_OK : VM_PAGER_ERROR;
1407 VM_OBJECT_RUNLOCK(object);
1408 VM_CNT_ADD(v_vnodepgsout, i);
1409 VM_CNT_INC(v_vnodeout);
1414 vnode_pager_putpages_ioflags(int pager_flags)
1419 * Pageouts are already clustered, use IO_ASYNC to force a
1420 * bawrite() rather then a bdwrite() to prevent paging I/O
1421 * from saturating the buffer cache. Dummy-up the sequential
1422 * heuristic to cause large ranges to cluster. If neither
1423 * IO_SYNC or IO_ASYNC is set, the system decides how to
1427 if ((pager_flags & (VM_PAGER_PUT_SYNC | VM_PAGER_PUT_INVAL)) != 0)
1429 else if ((pager_flags & VM_PAGER_CLUSTER_OK) == 0)
1430 ioflags |= IO_ASYNC;
1431 ioflags |= (pager_flags & VM_PAGER_PUT_INVAL) != 0 ? IO_INVAL: 0;
1432 ioflags |= (pager_flags & VM_PAGER_PUT_NOREUSE) != 0 ? IO_NOREUSE : 0;
1433 ioflags |= IO_SEQMAX << IO_SEQSHIFT;
1438 * vnode_pager_undirty_pages().
1440 * A helper to mark pages as clean after pageout that was possibly
1441 * done with a short write. The lpos argument specifies the page run
1442 * length in bytes, and the written argument specifies how many bytes
1443 * were actually written. eof is the offset past the last valid byte
1444 * in the vnode using the absolute file position of the first byte in
1445 * the run as the base from which it is computed.
1448 vnode_pager_undirty_pages(vm_page_t *ma, int *rtvals, int written, off_t eof,
1452 int i, pos, pos_devb;
1454 if (written == 0 && eof >= lpos)
1456 obj = ma[0]->object;
1457 VM_OBJECT_WLOCK(obj);
1458 for (i = 0, pos = 0; pos < written; i++, pos += PAGE_SIZE) {
1459 if (pos < trunc_page(written)) {
1460 rtvals[i] = VM_PAGER_OK;
1461 vm_page_undirty(ma[i]);
1463 /* Partially written page. */
1464 rtvals[i] = VM_PAGER_AGAIN;
1465 vm_page_clear_dirty(ma[i], 0, written & PAGE_MASK);
1468 if (eof >= lpos) /* avoid truncation */
1470 for (pos = eof, i = OFF_TO_IDX(trunc_page(pos)); pos < lpos; i++) {
1471 if (pos != trunc_page(pos)) {
1473 * The page contains the last valid byte in
1474 * the vnode, mark the rest of the page as
1475 * clean, potentially making the whole page
1478 pos_devb = roundup2(pos & PAGE_MASK, DEV_BSIZE);
1479 vm_page_clear_dirty(ma[i], pos_devb, PAGE_SIZE -
1483 * If the page was cleaned, report the pageout
1484 * on it as successful. msync() no longer
1485 * needs to write out the page, endlessly
1486 * creating write requests and dirty buffers.
1488 if (ma[i]->dirty == 0)
1489 rtvals[i] = VM_PAGER_OK;
1491 pos = round_page(pos);
1493 /* vm_pageout_flush() clears dirty */
1494 rtvals[i] = VM_PAGER_BAD;
1499 VM_OBJECT_WUNLOCK(obj);
1503 vnode_pager_update_writecount(vm_object_t object, vm_offset_t start,
1507 vm_ooffset_t old_wm;
1509 VM_OBJECT_WLOCK(object);
1510 if (object->type != OBJT_VNODE) {
1511 VM_OBJECT_WUNLOCK(object);
1514 old_wm = object->un_pager.vnp.writemappings;
1515 object->un_pager.vnp.writemappings += (vm_ooffset_t)end - start;
1516 vp = object->handle;
1517 if (old_wm == 0 && object->un_pager.vnp.writemappings != 0) {
1518 ASSERT_VOP_LOCKED(vp, "v_writecount inc");
1519 VOP_ADD_WRITECOUNT_CHECKED(vp, 1);
1520 CTR3(KTR_VFS, "%s: vp %p v_writecount increased to %d",
1521 __func__, vp, vp->v_writecount);
1522 } else if (old_wm != 0 && object->un_pager.vnp.writemappings == 0) {
1523 ASSERT_VOP_LOCKED(vp, "v_writecount dec");
1524 VOP_ADD_WRITECOUNT_CHECKED(vp, -1);
1525 CTR3(KTR_VFS, "%s: vp %p v_writecount decreased to %d",
1526 __func__, vp, vp->v_writecount);
1528 VM_OBJECT_WUNLOCK(object);
1532 vnode_pager_release_writecount(vm_object_t object, vm_offset_t start,
1539 VM_OBJECT_WLOCK(object);
1542 * First, recheck the object type to account for the race when
1543 * the vnode is reclaimed.
1545 if (object->type != OBJT_VNODE) {
1546 VM_OBJECT_WUNLOCK(object);
1551 * Optimize for the case when writemappings is not going to
1555 if (object->un_pager.vnp.writemappings != inc) {
1556 object->un_pager.vnp.writemappings -= inc;
1557 VM_OBJECT_WUNLOCK(object);
1561 vp = object->handle;
1563 VM_OBJECT_WUNLOCK(object);
1565 vn_start_write(vp, &mp, V_WAIT);
1566 vn_lock(vp, LK_SHARED | LK_RETRY);
1569 * Decrement the object's writemappings, by swapping the start
1570 * and end arguments for vnode_pager_update_writecount(). If
1571 * there was not a race with vnode reclaimation, then the
1572 * vnode's v_writecount is decremented.
1574 vnode_pager_update_writecount(object, end, start);
1578 vn_finished_write(mp);