2 * Copyright (c) 1990 University of Utah.
3 * Copyright (c) 1991 The Regents of the University of California.
5 * Copyright (c) 1993, 1994 John S. Dyson
6 * Copyright (c) 1995, David Greenman
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * from: @(#)vnode_pager.c 7.5 (Berkeley) 4/20/91
41 * $FreeBSD: src/sys/vm/vnode_pager.c,v 1.116.2.7 2002/12/31 09:34:51 dillon Exp $
42 * $DragonFly: src/sys/vm/vnode_pager.c,v 1.10 2003/08/20 08:03:01 rob Exp $
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/param.h>
56 #include <sys/systm.h>
58 #include <sys/vnode.h>
59 #include <sys/mount.h>
61 #include <sys/vmmeter.h>
65 #include <vm/vm_object.h>
66 #include <vm/vm_page.h>
67 #include <vm/vm_pager.h>
68 #include <vm/vm_map.h>
69 #include <vm/vnode_pager.h>
70 #include <vm/vm_extern.h>
72 static vm_offset_t vnode_pager_addr (struct vnode *vp, vm_ooffset_t address,
74 static void vnode_pager_iodone (struct buf *bp);
75 static int vnode_pager_input_smlfs (vm_object_t object, vm_page_t m);
76 static int vnode_pager_input_old (vm_object_t object, vm_page_t m);
77 static void vnode_pager_dealloc (vm_object_t);
78 static int vnode_pager_getpages (vm_object_t, vm_page_t *, int, int);
79 static void vnode_pager_putpages (vm_object_t, vm_page_t *, int, boolean_t, int *);
80 static boolean_t vnode_pager_haspage (vm_object_t, vm_pindex_t, int *, int *);
82 struct pagerops vnodepagerops = {
92 int vnode_pbuf_freecnt = -1; /* start out unlimited */
95 * Allocate (or lookup) pager for a vnode.
96 * Handle is a vnode pointer.
99 vnode_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
106 * Pageout to vnode, no can do yet.
112 * XXX hack - This initialization should be put somewhere else.
114 if (vnode_pbuf_freecnt < 0) {
115 vnode_pbuf_freecnt = nswbuf / 2 + 1;
118 vp = (struct vnode *) handle;
121 * Prevent race condition when allocating the object. This
122 * can happen with NFS vnodes since the nfsnode isn't locked.
124 while (vp->v_flag & VOLOCK) {
125 vp->v_flag |= VOWANT;
126 tsleep(vp, 0, "vnpobj", 0);
128 vp->v_flag |= VOLOCK;
131 * If the object is being terminated, wait for it to
134 while (((object = vp->v_object) != NULL) &&
135 (object->flags & OBJ_DEAD)) {
136 tsleep(object, 0, "vadead", 0);
139 if (vp->v_usecount == 0)
140 panic("vnode_pager_alloc: no vnode reference");
142 if (object == NULL) {
144 * And an object of the appropriate size
146 object = vm_object_allocate(OBJT_VNODE, OFF_TO_IDX(round_page(size)));
149 object->un_pager.vnp.vnp_size = size;
151 object->handle = handle;
152 vp->v_object = object;
159 vp->v_flag &= ~VOLOCK;
160 if (vp->v_flag & VOWANT) {
161 vp->v_flag &= ~VOWANT;
168 vnode_pager_dealloc(object)
171 struct vnode *vp = object->handle;
174 panic("vnode_pager_dealloc: pager already dealloced");
176 vm_object_pip_wait(object, "vnpdea");
178 object->handle = NULL;
179 object->type = OBJT_DEAD;
181 vp->v_flag &= ~(VTEXT | VOBJBUF);
185 vnode_pager_haspage(object, pindex, before, after)
191 struct vnode *vp = object->handle;
197 int pagesperblock, blocksperpage;
200 * If no vp or vp is doomed or marked transparent to VM, we do not
203 if ((vp == NULL) || (vp->v_flag & VDOOMED))
207 * If filesystem no longer mounted or offset beyond end of file we do
210 if ((vp->v_mount == NULL) ||
211 (IDX_TO_OFF(pindex) >= object->un_pager.vnp.vnp_size))
214 bsize = vp->v_mount->mnt_stat.f_iosize;
215 pagesperblock = bsize / PAGE_SIZE;
217 if (pagesperblock > 0) {
218 reqblock = pindex / pagesperblock;
220 blocksperpage = (PAGE_SIZE / bsize);
221 reqblock = pindex * blocksperpage;
223 err = VOP_BMAP(vp, reqblock, (struct vnode **) 0, &bn,
229 if (pagesperblock > 0) {
230 poff = pindex - (reqblock * pagesperblock);
232 *before *= pagesperblock;
237 *after *= pagesperblock;
238 numafter = pagesperblock - (poff + 1);
239 if (IDX_TO_OFF(pindex + numafter) > object->un_pager.vnp.vnp_size) {
240 numafter = OFF_TO_IDX((object->un_pager.vnp.vnp_size - IDX_TO_OFF(pindex)));
246 *before /= blocksperpage;
250 *after /= blocksperpage;
257 * Lets the VM system know about a change in size for a file.
258 * We adjust our own internal size and flush any cached pages in
259 * the associated object that are affected by the size change.
261 * Note: this routine may be invoked as a result of a pager put
262 * operation (possibly at object termination time), so we must be careful.
265 vnode_pager_setsize(vp, nsize)
269 vm_pindex_t nobjsize;
270 vm_object_t object = vp->v_object;
276 * Hasn't changed size
278 if (nsize == object->un_pager.vnp.vnp_size)
281 nobjsize = OFF_TO_IDX(nsize + PAGE_MASK);
284 * File has shrunk. Toss any cached pages beyond the new EOF.
286 if (nsize < object->un_pager.vnp.vnp_size) {
287 vm_freeze_copyopts(object, OFF_TO_IDX(nsize), object->size);
288 if (nobjsize < object->size) {
289 vm_object_page_remove(object, nobjsize, object->size,
293 * this gets rid of garbage at the end of a page that is now
294 * only partially backed by the vnode.
296 * XXX for some reason (I don't know yet), if we take a
297 * completely invalid page and mark it partially valid
298 * it can screw up NFS reads, so we don't allow the case.
300 if (nsize & PAGE_MASK) {
304 m = vm_page_lookup(object, OFF_TO_IDX(nsize));
306 int base = (int)nsize & PAGE_MASK;
307 int size = PAGE_SIZE - base;
310 * Clear out partial-page garbage in case
311 * the page has been mapped.
313 kva = vm_pager_map_page(m);
314 bzero((caddr_t)kva + base, size);
315 vm_pager_unmap_page(kva);
318 * XXX work around SMP data integrity race
319 * by unmapping the page from user processes.
320 * The garbage we just cleared may be mapped
321 * to a user process running on another cpu
322 * and this code is not running through normal
323 * I/O channels which handle SMP issues for
324 * us, so unmap page to synchronize all cpus.
326 * XXX should vm_pager_unmap_page() have
329 vm_page_protect(m, VM_PROT_NONE);
332 * Clear out partial-page dirty bits. This
333 * has the side effect of setting the valid
334 * bits, but that is ok. There are a bunch
335 * of places in the VM system where we expected
336 * m->dirty == VM_PAGE_BITS_ALL. The file EOF
337 * case is one of them. If the page is still
338 * partially dirty, make it fully dirty.
340 * note that we do not clear out the valid
341 * bits. This would prevent bogus_page
342 * replacement from working properly.
344 vm_page_set_validclean(m, base, size);
346 m->dirty = VM_PAGE_BITS_ALL;
350 object->un_pager.vnp.vnp_size = nsize;
351 object->size = nobjsize;
355 vnode_pager_freepage(m)
362 * calculate the linear (byte) disk address of specified virtual
366 vnode_pager_addr(vp, address, run)
368 vm_ooffset_t address;
379 if ((int) address < 0)
382 if (vp->v_mount == NULL)
385 bsize = vp->v_mount->mnt_stat.f_iosize;
386 vblock = address / bsize;
387 voffset = address % bsize;
389 err = VOP_BMAP(vp, vblock, &rtvp, &block, run, NULL);
391 if (err || (block == -1))
394 rtaddress = block + voffset / DEV_BSIZE;
397 *run *= bsize/PAGE_SIZE;
398 *run -= voffset/PAGE_SIZE;
406 * interrupt routine for I/O completion
409 vnode_pager_iodone(bp)
412 bp->b_flags |= B_DONE;
417 * small block file system vnode pager input
420 vnode_pager_input_smlfs(object, m)
426 struct vnode *dp, *vp;
434 if (vp->v_mount == NULL)
437 bsize = vp->v_mount->mnt_stat.f_iosize;
440 VOP_BMAP(vp, 0, &dp, 0, NULL, NULL);
442 kva = vm_pager_map_page(m);
444 for (i = 0; i < PAGE_SIZE / bsize; i++) {
445 vm_ooffset_t address;
447 if (vm_page_bits(i * bsize, bsize) & m->valid)
450 address = IDX_TO_OFF(m->pindex) + i * bsize;
451 if (address >= object->un_pager.vnp.vnp_size) {
454 fileaddr = vnode_pager_addr(vp, address, NULL);
456 if (fileaddr != -1) {
457 bp = getpbuf(&vnode_pbuf_freecnt);
459 /* build a minimal buffer header */
460 bp->b_flags = B_READ | B_CALL;
461 bp->b_iodone = vnode_pager_iodone;
462 bp->b_data = (caddr_t) kva + i * bsize;
463 bp->b_blkno = fileaddr;
465 bp->b_bcount = bsize;
466 bp->b_bufsize = bsize;
467 bp->b_runningbufspace = bp->b_bufsize;
468 runningbufspace += bp->b_runningbufspace;
471 VOP_STRATEGY(bp->b_vp, bp);
473 /* we definitely need to be at splvm here */
476 while ((bp->b_flags & B_DONE) == 0) {
477 tsleep(bp, 0, "vnsrd", 0);
480 if ((bp->b_flags & B_ERROR) != 0)
484 * free the buffer header back to the swap buffer pool
486 relpbuf(bp, &vnode_pbuf_freecnt);
490 vm_page_set_validclean(m, (i * bsize) & PAGE_MASK, bsize);
492 vm_page_set_validclean(m, (i * bsize) & PAGE_MASK, bsize);
493 bzero((caddr_t) kva + i * bsize, bsize);
496 vm_pager_unmap_page(kva);
497 pmap_clear_modify(m);
498 vm_page_flag_clear(m, PG_ZERO);
500 return VM_PAGER_ERROR;
508 * old style vnode pager output routine
511 vnode_pager_input_old(object, m)
524 * Return failure if beyond current EOF
526 if (IDX_TO_OFF(m->pindex) >= object->un_pager.vnp.vnp_size) {
530 if (IDX_TO_OFF(m->pindex) + size > object->un_pager.vnp.vnp_size)
531 size = object->un_pager.vnp.vnp_size - IDX_TO_OFF(m->pindex);
534 * Allocate a kernel virtual address and initialize so that
535 * we can use VOP_READ/WRITE routines.
537 kva = vm_pager_map_page(m);
539 aiov.iov_base = (caddr_t) kva;
541 auio.uio_iov = &aiov;
543 auio.uio_offset = IDX_TO_OFF(m->pindex);
544 auio.uio_segflg = UIO_SYSSPACE;
545 auio.uio_rw = UIO_READ;
546 auio.uio_resid = size;
547 auio.uio_td = curthread;
549 error = VOP_READ(object->handle, &auio, 0, proc0.p_ucred);
551 int count = size - auio.uio_resid;
555 else if (count != PAGE_SIZE)
556 bzero((caddr_t) kva + count, PAGE_SIZE - count);
558 vm_pager_unmap_page(kva);
560 pmap_clear_modify(m);
562 vm_page_flag_clear(m, PG_ZERO);
564 m->valid = VM_PAGE_BITS_ALL;
565 return error ? VM_PAGER_ERROR : VM_PAGER_OK;
569 * generic vnode pager input routine
573 * EOPNOTSUPP is no longer legal. For local media VFS's that do not
574 * implement their own VOP_GETPAGES, their VOP_GETPAGES should call to
575 * vnode_pager_generic_getpages() to implement the previous behaviour.
577 * All other FS's should use the bypass to get to the local media
578 * backing vp's VOP_GETPAGES.
581 vnode_pager_getpages(object, m, count, reqpage)
589 int bytes = count * PAGE_SIZE;
593 * XXX temporary diagnostic message to help track stale FS code,
594 * Returning EOPNOTSUPP from here may make things unhappy.
596 rtval = VOP_GETPAGES(vp, m, bytes, reqpage, 0);
597 if (rtval == EOPNOTSUPP) {
598 printf("vnode_pager: *** WARNING *** stale FS getpages\n");
599 rtval = vnode_pager_generic_getpages( vp, m, bytes, reqpage);
606 * This is now called from local media FS's to operate against their
607 * own vnodes if they fail to implement VOP_GETPAGES.
610 vnode_pager_generic_getpages(vp, m, bytecount, reqpage)
618 off_t foff, tfoff, nextoff;
619 int i, size, bsize, first, firstaddr;
628 object = vp->v_object;
629 count = bytecount / PAGE_SIZE;
631 if (vp->v_mount == NULL)
634 bsize = vp->v_mount->mnt_stat.f_iosize;
636 /* get the UNDERLYING device for the file with VOP_BMAP() */
639 * originally, we did not check for an error return value -- assuming
640 * an fs always has a bmap entry point -- that assumption is wrong!!!
642 foff = IDX_TO_OFF(m[reqpage]->pindex);
645 * if we can't bmap, use old VOP code
647 if (VOP_BMAP(vp, 0, &dp, 0, NULL, NULL)) {
648 for (i = 0; i < count; i++) {
650 vnode_pager_freepage(m[i]);
653 mycpu->gd_cnt.v_vnodein++;
654 mycpu->gd_cnt.v_vnodepgsin++;
655 return vnode_pager_input_old(object, m[reqpage]);
658 * if the blocksize is smaller than a page size, then use
659 * special small filesystem code. NFS sometimes has a small
660 * blocksize, but it can handle large reads itself.
662 } else if ((PAGE_SIZE / bsize) > 1 &&
663 (vp->v_mount->mnt_stat.f_type != nfs_mount_type)) {
664 for (i = 0; i < count; i++) {
666 vnode_pager_freepage(m[i]);
669 mycpu->gd_cnt.v_vnodein++;
670 mycpu->gd_cnt.v_vnodepgsin++;
671 return vnode_pager_input_smlfs(object, m[reqpage]);
675 * If we have a completely valid page available to us, we can
676 * clean up and return. Otherwise we have to re-read the
680 if (m[reqpage]->valid == VM_PAGE_BITS_ALL) {
681 for (i = 0; i < count; i++) {
683 vnode_pager_freepage(m[i]);
687 m[reqpage]->valid = 0;
690 * here on direct device I/O
695 * calculate the run that includes the required page
697 for(first = 0, i = 0; i < count; i = runend) {
698 firstaddr = vnode_pager_addr(vp,
699 IDX_TO_OFF(m[i]->pindex), &runpg);
700 if (firstaddr == -1) {
701 if (i == reqpage && foff < object->un_pager.vnp.vnp_size) {
702 /* XXX no %qd in kernel. */
703 panic("vnode_pager_getpages: unexpected missing page: firstaddr: %d, foff: 0x%lx%08lx, vnp_size: 0x%lx%08lx",
704 firstaddr, (u_long)(foff >> 32),
705 (u_long)(u_int32_t)foff,
707 (object->un_pager.vnp.vnp_size >> 32),
709 object->un_pager.vnp.vnp_size);
711 vnode_pager_freepage(m[i]);
717 if (runend <= reqpage) {
719 for (j = i; j < runend; j++) {
720 vnode_pager_freepage(m[j]);
723 if (runpg < (count - first)) {
724 for (i = first + runpg; i < count; i++)
725 vnode_pager_freepage(m[i]);
726 count = first + runpg;
734 * the first and last page have been calculated now, move input pages
735 * to be zero based...
738 for (i = first; i < count; i++) {
746 * calculate the file virtual address for the transfer
748 foff = IDX_TO_OFF(m[0]->pindex);
751 * calculate the size of the transfer
753 size = count * PAGE_SIZE;
754 if ((foff + size) > object->un_pager.vnp.vnp_size)
755 size = object->un_pager.vnp.vnp_size - foff;
758 * round up physical size for real devices.
760 if (dp->v_type == VBLK || dp->v_type == VCHR) {
761 int secmask = dp->v_rdev->si_bsize_phys - 1;
762 KASSERT(secmask < PAGE_SIZE, ("vnode_pager_generic_getpages: sector size %d too large\n", secmask + 1));
763 size = (size + secmask) & ~secmask;
766 bp = getpbuf(&vnode_pbuf_freecnt);
767 kva = (vm_offset_t) bp->b_data;
770 * and map the pages to be read into the kva
772 pmap_qenter(kva, m, count);
774 /* build a minimal buffer header */
775 bp->b_flags = B_READ | B_CALL;
776 bp->b_iodone = vnode_pager_iodone;
777 /* B_PHYS is not set, but it is nice to fill this in */
778 bp->b_blkno = firstaddr;
781 bp->b_bufsize = size;
782 bp->b_runningbufspace = bp->b_bufsize;
783 runningbufspace += bp->b_runningbufspace;
785 mycpu->gd_cnt.v_vnodein++;
786 mycpu->gd_cnt.v_vnodepgsin += count;
789 VOP_STRATEGY(bp->b_vp, bp);
792 /* we definitely need to be at splvm here */
794 while ((bp->b_flags & B_DONE) == 0) {
795 tsleep(bp, 0, "vnread", 0);
798 if ((bp->b_flags & B_ERROR) != 0)
802 if (size != count * PAGE_SIZE)
803 bzero((caddr_t) kva + size, PAGE_SIZE * count - size);
805 pmap_qremove(kva, count);
808 * free the buffer header back to the swap buffer pool
810 relpbuf(bp, &vnode_pbuf_freecnt);
812 for (i = 0, tfoff = foff; i < count; i++, tfoff = nextoff) {
815 nextoff = tfoff + PAGE_SIZE;
818 if (nextoff <= object->un_pager.vnp.vnp_size) {
820 * Read filled up entire page.
822 mt->valid = VM_PAGE_BITS_ALL;
823 vm_page_undirty(mt); /* should be an assert? XXX */
824 pmap_clear_modify(mt);
827 * Read did not fill up entire page. Since this
828 * is getpages, the page may be mapped, so we have
829 * to zero the invalid portions of the page even
830 * though we aren't setting them valid.
832 * Currently we do not set the entire page valid,
833 * we just try to clear the piece that we couldn't
836 vm_page_set_validclean(mt, 0,
837 object->un_pager.vnp.vnp_size - tfoff);
838 /* handled by vm_fault now */
839 /* vm_page_zero_invalid(mt, FALSE); */
842 vm_page_flag_clear(mt, PG_ZERO);
846 * whether or not to leave the page activated is up in
847 * the air, but we should put the page on a page queue
848 * somewhere. (it already is in the object). Result:
849 * It appears that empirical results show that
850 * deactivating pages is best.
854 * just in case someone was asking for this page we
855 * now tell them that it is ok to use
858 if (mt->flags & PG_WANTED)
859 vm_page_activate(mt);
861 vm_page_deactivate(mt);
864 vnode_pager_freepage(mt);
869 printf("vnode_pager_getpages: I/O read error\n");
871 return (error ? VM_PAGER_ERROR : VM_PAGER_OK);
875 * EOPNOTSUPP is no longer legal. For local media VFS's that do not
876 * implement their own VOP_PUTPAGES, their VOP_PUTPAGES should call to
877 * vnode_pager_generic_putpages() to implement the previous behaviour.
879 * All other FS's should use the bypass to get to the local media
880 * backing vp's VOP_PUTPAGES.
883 vnode_pager_putpages(object, m, count, sync, rtvals)
892 int bytes = count * PAGE_SIZE;
895 * Force synchronous operation if we are extremely low on memory
896 * to prevent a low-memory deadlock. VOP operations often need to
897 * allocate more memory to initiate the I/O ( i.e. do a BMAP
898 * operation ). The swapper handles the case by limiting the amount
899 * of asynchronous I/O, but that sort of solution doesn't scale well
900 * for the vnode pager without a lot of work.
902 * Also, the backing vnode's iodone routine may not wake the pageout
903 * daemon up. This should be probably be addressed XXX.
906 if ((vmstats.v_free_count + vmstats.v_cache_count) < vmstats.v_pageout_free_min)
910 * Call device-specific putpages function
914 rtval = VOP_PUTPAGES(vp, m, bytes, sync, rtvals, 0);
915 if (rtval == EOPNOTSUPP) {
916 printf("vnode_pager: *** WARNING *** stale FS putpages\n");
917 rtval = vnode_pager_generic_putpages( vp, m, bytes, sync, rtvals);
923 * This is now called from local media FS's to operate against their
924 * own vnodes if they fail to implement VOP_PUTPAGES.
926 * This is typically called indirectly via the pageout daemon and
927 * clustering has already typically occured, so in general we ask the
928 * underlying filesystem to write the data out asynchronously rather
932 vnode_pager_generic_putpages(vp, m, bytecount, flags, rtvals)
944 vm_ooffset_t poffset;
950 object = vp->v_object;
951 count = bytecount / PAGE_SIZE;
953 for (i = 0; i < count; i++)
954 rtvals[i] = VM_PAGER_AGAIN;
956 if ((int) m[0]->pindex < 0) {
957 printf("vnode_pager_putpages: attempt to write meta-data!!! -- 0x%lx(%x)\n",
958 (long)m[0]->pindex, m[0]->dirty);
959 rtvals[0] = VM_PAGER_BAD;
963 maxsize = count * PAGE_SIZE;
966 poffset = IDX_TO_OFF(m[0]->pindex);
969 * If the page-aligned write is larger then the actual file we
970 * have to invalidate pages occuring beyond the file EOF. However,
971 * there is an edge case where a file may not be page-aligned where
972 * the last page is partially invalid. In this case the filesystem
973 * may not properly clear the dirty bits for the entire page (which
974 * could be VM_PAGE_BITS_ALL due to the page having been mmap()d).
975 * With the page locked we are free to fix-up the dirty bits here.
977 * We do not under any circumstances truncate the valid bits, as
978 * this will screw up bogus page replacement.
980 if (maxsize + poffset > object->un_pager.vnp.vnp_size) {
981 if (object->un_pager.vnp.vnp_size > poffset) {
984 maxsize = object->un_pager.vnp.vnp_size - poffset;
985 ncount = btoc(maxsize);
986 if ((pgoff = (int)maxsize & PAGE_MASK) != 0) {
987 vm_page_clear_dirty(m[ncount - 1], pgoff,
994 if (ncount < count) {
995 for (i = ncount; i < count; i++) {
996 rtvals[i] = VM_PAGER_BAD;
1002 * pageouts are already clustered, use IO_ASYNC to force a bawrite()
1003 * rather then a bdwrite() to prevent paging I/O from saturating
1004 * the buffer cache. Dummy-up the sequential heuristic to cause
1005 * large ranges to cluster. If neither IO_SYNC or IO_ASYNC is set,
1006 * the system decides how to cluster.
1009 if (flags & (VM_PAGER_PUT_SYNC | VM_PAGER_PUT_INVAL))
1011 else if ((flags & VM_PAGER_CLUSTER_OK) == 0)
1012 ioflags |= IO_ASYNC;
1013 ioflags |= (flags & VM_PAGER_PUT_INVAL) ? IO_INVAL: 0;
1014 ioflags |= IO_SEQMAX << IO_SEQSHIFT;
1016 aiov.iov_base = (caddr_t) 0;
1017 aiov.iov_len = maxsize;
1018 auio.uio_iov = &aiov;
1019 auio.uio_iovcnt = 1;
1020 auio.uio_offset = poffset;
1021 auio.uio_segflg = UIO_NOCOPY;
1022 auio.uio_rw = UIO_WRITE;
1023 auio.uio_resid = maxsize;
1025 error = VOP_WRITE(vp, &auio, ioflags, proc0.p_ucred);
1026 mycpu->gd_cnt.v_vnodeout++;
1027 mycpu->gd_cnt.v_vnodepgsout += ncount;
1030 printf("vnode_pager_putpages: I/O error %d\n", error);
1032 if (auio.uio_resid) {
1033 printf("vnode_pager_putpages: residual I/O %d at %lu\n",
1034 auio.uio_resid, (u_long)m[0]->pindex);
1036 for (i = 0; i < ncount; i++) {
1037 rtvals[i] = VM_PAGER_OK;
1043 vnode_pager_lock(vm_object_t object)
1045 struct thread *td = curthread; /* XXX */
1047 for (; object != NULL; object = object->backing_object) {
1048 if (object->type != OBJT_VNODE)
1050 if (object->flags & OBJ_DEAD)
1053 while (vget(object->handle,
1054 LK_NOPAUSE | LK_SHARED | LK_RETRY | LK_CANRECURSE, td)) {
1055 if ((object->flags & OBJ_DEAD) ||
1056 (object->type != OBJT_VNODE)) {
1059 printf("vnode_pager_lock: retrying\n");
1061 return object->handle;