Home | History | Annotate | Line # | Download | only in uvm
uvm_vnode.c revision 1.97.2.3
      1  1.97.2.1      yamt /*	$NetBSD: uvm_vnode.c,v 1.97.2.3 2011/12/20 13:46:17 yamt Exp $	*/
      2       1.1       mrg 
      3       1.1       mrg /*
      4       1.1       mrg  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      5       1.1       mrg  * Copyright (c) 1991, 1993
      6      1.49       chs  *      The Regents of the University of California.
      7       1.1       mrg  * Copyright (c) 1990 University of Utah.
      8       1.1       mrg  *
      9       1.1       mrg  * All rights reserved.
     10       1.1       mrg  *
     11       1.1       mrg  * This code is derived from software contributed to Berkeley by
     12       1.1       mrg  * the Systems Programming Group of the University of Utah Computer
     13       1.1       mrg  * Science Department.
     14       1.1       mrg  *
     15       1.1       mrg  * Redistribution and use in source and binary forms, with or without
     16       1.1       mrg  * modification, are permitted provided that the following conditions
     17       1.1       mrg  * are met:
     18       1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     19       1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     20       1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     21       1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     22       1.1       mrg  *    documentation and/or other materials provided with the distribution.
     23      1.94     chuck  * 3. Neither the name of the University nor the names of its contributors
     24       1.1       mrg  *    may be used to endorse or promote products derived from this software
     25       1.1       mrg  *    without specific prior written permission.
     26       1.1       mrg  *
     27       1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28       1.1       mrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29       1.1       mrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30       1.1       mrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31       1.1       mrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32       1.1       mrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33       1.1       mrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34       1.1       mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35       1.1       mrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36       1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37       1.1       mrg  * SUCH DAMAGE.
     38       1.1       mrg  *
     39       1.1       mrg  *      @(#)vnode_pager.c       8.8 (Berkeley) 2/13/94
     40       1.3       mrg  * from: Id: uvm_vnode.c,v 1.1.2.26 1998/02/02 20:38:07 chuck Exp
     41       1.1       mrg  */
     42       1.1       mrg 
     43      1.55     lukem /*
     44      1.55     lukem  * uvm_vnode.c: the vnode pager.
     45      1.55     lukem  */
     46      1.55     lukem 
     47      1.55     lukem #include <sys/cdefs.h>
     48  1.97.2.1      yamt __KERNEL_RCSID(0, "$NetBSD: uvm_vnode.c,v 1.97.2.3 2011/12/20 13:46:17 yamt Exp $");
     49      1.55     lukem 
     50       1.4       mrg #include "opt_uvmhist.h"
     51       1.1       mrg 
     52       1.1       mrg #include <sys/param.h>
     53       1.1       mrg #include <sys/systm.h>
     54      1.37       chs #include <sys/kernel.h>
     55       1.1       mrg #include <sys/vnode.h>
     56      1.13   thorpej #include <sys/disklabel.h>
     57      1.13   thorpej #include <sys/ioctl.h>
     58      1.13   thorpej #include <sys/fcntl.h>
     59      1.13   thorpej #include <sys/conf.h>
     60      1.37       chs #include <sys/pool.h>
     61      1.37       chs #include <sys/mount.h>
     62      1.13   thorpej 
     63      1.13   thorpej #include <miscfs/specfs/specdev.h>
     64       1.1       mrg 
     65       1.1       mrg #include <uvm/uvm.h>
     66      1.68      yamt #include <uvm/uvm_readahead.h>
     67  1.97.2.2      yamt #include <uvm/uvm_page_array.h>
     68       1.1       mrg 
     69       1.1       mrg /*
     70       1.1       mrg  * functions
     71       1.1       mrg  */
     72       1.1       mrg 
     73      1.66   thorpej static void	uvn_detach(struct uvm_object *);
     74      1.66   thorpej static int	uvn_get(struct uvm_object *, voff_t, struct vm_page **, int *,
     75      1.66   thorpej 			int, vm_prot_t, int, int);
     76      1.66   thorpej static int	uvn_put(struct uvm_object *, voff_t, voff_t, int);
     77      1.66   thorpej static void	uvn_reference(struct uvm_object *);
     78      1.52       chs 
     79      1.66   thorpej static int	uvn_findpage(struct uvm_object *, voff_t, struct vm_page **,
     80  1.97.2.3      yamt 			     unsigned int, struct uvm_page_array *a,
     81  1.97.2.3      yamt 			     unsigned int);
     82       1.1       mrg 
     83       1.1       mrg /*
     84       1.1       mrg  * master pager structure
     85       1.1       mrg  */
     86       1.1       mrg 
     87      1.89      yamt const struct uvm_pagerops uvm_vnodeops = {
     88      1.88      yamt 	.pgo_reference = uvn_reference,
     89      1.88      yamt 	.pgo_detach = uvn_detach,
     90      1.88      yamt 	.pgo_get = uvn_get,
     91      1.88      yamt 	.pgo_put = uvn_put,
     92       1.1       mrg };
     93       1.1       mrg 
     94       1.1       mrg /*
     95       1.1       mrg  * the ops!
     96       1.1       mrg  */
     97       1.1       mrg 
     98       1.1       mrg /*
     99       1.1       mrg  * uvn_reference
    100       1.1       mrg  *
    101       1.1       mrg  * duplicate a reference to a VM object.  Note that the reference
    102      1.49       chs  * count must already be at least one (the passed in reference) so
    103       1.1       mrg  * there is no chance of the uvn being killed or locked out here.
    104       1.1       mrg  *
    105      1.49       chs  * => caller must call with object unlocked.
    106       1.1       mrg  * => caller must be using the same accessprot as was used at attach time
    107       1.1       mrg  */
    108       1.1       mrg 
    109      1.66   thorpej static void
    110      1.65   thorpej uvn_reference(struct uvm_object *uobj)
    111       1.1       mrg {
    112      1.93     pooka 	vref((struct vnode *)uobj);
    113       1.1       mrg }
    114       1.1       mrg 
    115      1.52       chs 
    116       1.1       mrg /*
    117       1.1       mrg  * uvn_detach
    118       1.1       mrg  *
    119       1.1       mrg  * remove a reference to a VM object.
    120       1.1       mrg  *
    121       1.1       mrg  * => caller must call with object unlocked and map locked.
    122       1.1       mrg  */
    123      1.52       chs 
    124      1.66   thorpej static void
    125      1.65   thorpej uvn_detach(struct uvm_object *uobj)
    126       1.8       mrg {
    127      1.37       chs 	vrele((struct vnode *)uobj);
    128       1.1       mrg }
    129       1.1       mrg 
    130       1.1       mrg /*
    131       1.1       mrg  * uvn_put: flush page data to backing store.
    132       1.1       mrg  *
    133      1.53  sommerfe  * => object must be locked on entry!   VOP_PUTPAGES must unlock it.
    134       1.1       mrg  * => flags: PGO_SYNCIO -- use sync. I/O
    135       1.1       mrg  */
    136       1.1       mrg 
    137      1.66   thorpej static int
    138      1.65   thorpej uvn_put(struct uvm_object *uobj, voff_t offlo, voff_t offhi, int flags)
    139       1.1       mrg {
    140      1.37       chs 	struct vnode *vp = (struct vnode *)uobj;
    141      1.37       chs 	int error;
    142       1.1       mrg 
    143      1.96     rmind 	KASSERT(mutex_owned(vp->v_interlock));
    144      1.54       chs 	error = VOP_PUTPAGES(vp, offlo, offhi, flags);
    145      1.90        ad 
    146      1.48       chs 	return error;
    147       1.1       mrg }
    148       1.1       mrg 
    149       1.1       mrg 
    150       1.1       mrg /*
    151       1.1       mrg  * uvn_get: get pages (synchronously) from backing store
    152       1.1       mrg  *
    153       1.1       mrg  * => prefer map unlocked (not required)
    154       1.1       mrg  * => object must be locked!  we will _unlock_ it before starting any I/O.
    155       1.1       mrg  * => flags: PGO_ALLPAGES: get all of the pages
    156       1.1       mrg  *           PGO_LOCKED: fault data structures are locked
    157       1.1       mrg  * => NOTE: offset is the offset of pps[0], _NOT_ pps[centeridx]
    158       1.1       mrg  * => NOTE: caller must check for released pages!!
    159       1.1       mrg  */
    160      1.49       chs 
    161      1.66   thorpej static int
    162      1.65   thorpej uvn_get(struct uvm_object *uobj, voff_t offset,
    163      1.65   thorpej     struct vm_page **pps /* IN/OUT */,
    164      1.65   thorpej     int *npagesp /* IN (OUT if PGO_LOCKED)*/,
    165      1.65   thorpej     int centeridx, vm_prot_t access_type, int advice, int flags)
    166       1.8       mrg {
    167      1.37       chs 	struct vnode *vp = (struct vnode *)uobj;
    168      1.37       chs 	int error;
    169      1.67      yamt 
    170      1.37       chs 	UVMHIST_FUNC("uvn_get"); UVMHIST_CALLED(ubchist);
    171      1.37       chs 
    172      1.37       chs 	UVMHIST_LOG(ubchist, "vp %p off 0x%x", vp, (int)offset, 0,0);
    173      1.68      yamt 
    174      1.68      yamt 	if ((access_type & VM_PROT_WRITE) == 0 && (flags & PGO_LOCKED) == 0) {
    175      1.68      yamt 		vn_ra_allocctx(vp);
    176      1.68      yamt 		uvm_ra_request(vp->v_ractx, advice, uobj, offset,
    177      1.68      yamt 		    *npagesp << PAGE_SHIFT);
    178      1.68      yamt 	}
    179      1.68      yamt 
    180      1.37       chs 	error = VOP_GETPAGES(vp, offset, pps, npagesp, centeridx,
    181      1.37       chs 			     access_type, advice, flags);
    182      1.67      yamt 
    183      1.96     rmind 	KASSERT(((flags & PGO_LOCKED) != 0 && mutex_owned(vp->v_interlock)) ||
    184      1.90        ad 	    (flags & PGO_LOCKED) == 0);
    185      1.48       chs 	return error;
    186      1.37       chs }
    187       1.8       mrg 
    188       1.8       mrg 
    189      1.37       chs /*
    190      1.37       chs  * uvn_findpages:
    191      1.37       chs  * return the page for the uobj and offset requested, allocating if needed.
    192      1.37       chs  * => uobj must be locked.
    193      1.52       chs  * => returned pages will be BUSY.
    194      1.37       chs  */
    195       1.1       mrg 
    196      1.58     enami int
    197  1.97.2.3      yamt uvn_findpages(struct uvm_object *uobj, voff_t offset, unsigned int *npagesp,
    198  1.97.2.3      yamt     struct vm_page **pgs, struct uvm_page_array *a, unsigned int flags)
    199      1.37       chs {
    200  1.97.2.3      yamt 	unsigned int count, found, npages;
    201  1.97.2.3      yamt 	int i, rv;
    202  1.97.2.3      yamt 	struct uvm_page_array a_store;
    203  1.97.2.3      yamt 
    204  1.97.2.3      yamt 	if (a == NULL) {
    205  1.97.2.3      yamt 		a = &a_store;
    206  1.97.2.3      yamt 		uvm_page_array_init(a);
    207  1.97.2.3      yamt 	}
    208      1.58     enami 	count = found = 0;
    209      1.37       chs 	npages = *npagesp;
    210      1.52       chs 	if (flags & UFP_BACKWARD) {
    211      1.52       chs 		for (i = npages - 1; i >= 0; i--, offset -= PAGE_SIZE) {
    212  1.97.2.3      yamt 			rv = uvn_findpage(uobj, offset, &pgs[i], flags, a,
    213  1.97.2.2      yamt 			    npages - i);
    214      1.58     enami 			if (rv == 0) {
    215      1.58     enami 				if (flags & UFP_DIRTYONLY)
    216      1.58     enami 					break;
    217      1.58     enami 			} else
    218      1.58     enami 				found++;
    219      1.52       chs 			count++;
    220      1.52       chs 		}
    221      1.52       chs 	} else {
    222      1.52       chs 		for (i = 0; i < npages; i++, offset += PAGE_SIZE) {
    223  1.97.2.3      yamt 			rv = uvn_findpage(uobj, offset, &pgs[i], flags, a,
    224  1.97.2.2      yamt 			    npages - i);
    225      1.58     enami 			if (rv == 0) {
    226      1.58     enami 				if (flags & UFP_DIRTYONLY)
    227      1.58     enami 					break;
    228      1.58     enami 			} else
    229      1.58     enami 				found++;
    230      1.52       chs 			count++;
    231      1.52       chs 		}
    232      1.37       chs 	}
    233  1.97.2.3      yamt 	if (a == &a_store) {
    234  1.97.2.3      yamt 		uvm_page_array_fini(a);
    235  1.97.2.3      yamt 	}
    236      1.52       chs 	*npagesp = count;
    237      1.58     enami 	return (found);
    238      1.37       chs }
    239       1.8       mrg 
    240      1.66   thorpej static int
    241      1.65   thorpej uvn_findpage(struct uvm_object *uobj, voff_t offset, struct vm_page **pgp,
    242  1.97.2.3      yamt     unsigned int flags, struct uvm_page_array *a, unsigned int nleft)
    243      1.37       chs {
    244      1.37       chs 	struct vm_page *pg;
    245      1.79   thorpej 	bool dirty;
    246  1.97.2.2      yamt 	const unsigned int fillflags =
    247  1.97.2.2      yamt 	    ((flags & UFP_BACKWARD) ? UVM_PAGE_ARRAY_FILL_BACKWARD : 0) ||
    248  1.97.2.2      yamt 	    ((flags & UFP_DIRTYONLY) ?
    249  1.97.2.2      yamt 	    (UVM_PAGE_ARRAY_FILL_DIRTYONLY|UVM_PAGE_ARRAY_FILL_DENSE) : 0);
    250      1.37       chs 	UVMHIST_FUNC("uvn_findpage"); UVMHIST_CALLED(ubchist);
    251      1.37       chs 	UVMHIST_LOG(ubchist, "vp %p off 0x%lx", uobj, offset,0,0);
    252       1.8       mrg 
    253      1.96     rmind 	KASSERT(mutex_owned(uobj->vmobjlock));
    254      1.96     rmind 
    255      1.37       chs 	if (*pgp != NULL) {
    256      1.37       chs 		UVMHIST_LOG(ubchist, "dontcare", 0,0,0,0);
    257  1.97.2.2      yamt 		goto skip;
    258      1.37       chs 	}
    259      1.37       chs 	for (;;) {
    260      1.37       chs 		/* look for an existing page */
    261  1.97.2.2      yamt 		pg = uvm_page_array_fill_and_peek(a, uobj, offset, nleft,
    262  1.97.2.2      yamt 		    fillflags);
    263  1.97.2.2      yamt 		if (pg != NULL && pg->offset != offset) {
    264  1.97.2.2      yamt 			KASSERT((fillflags & UVM_PAGE_ARRAY_FILL_DENSE) == 0);
    265  1.97.2.2      yamt 			KASSERT(
    266  1.97.2.2      yamt 			    ((fillflags & UVM_PAGE_ARRAY_FILL_BACKWARD) != 0)
    267  1.97.2.2      yamt 			    == (pg->offset < offset));
    268  1.97.2.2      yamt 			pg = NULL;
    269  1.97.2.2      yamt 		}
    270      1.37       chs 
    271      1.52       chs 		/* nope?  allocate one now */
    272      1.37       chs 		if (pg == NULL) {
    273      1.37       chs 			if (flags & UFP_NOALLOC) {
    274      1.37       chs 				UVMHIST_LOG(ubchist, "noalloc", 0,0,0,0);
    275      1.37       chs 				return 0;
    276      1.37       chs 			}
    277      1.97      matt 			pg = uvm_pagealloc(uobj, offset, NULL,
    278      1.97      matt 			    UVM_FLAG_COLORMATCH);
    279      1.37       chs 			if (pg == NULL) {
    280      1.37       chs 				if (flags & UFP_NOWAIT) {
    281      1.37       chs 					UVMHIST_LOG(ubchist, "nowait",0,0,0,0);
    282      1.37       chs 					return 0;
    283       1.8       mrg 				}
    284      1.96     rmind 				mutex_exit(uobj->vmobjlock);
    285      1.37       chs 				uvm_wait("uvn_fp1");
    286  1.97.2.2      yamt 				uvm_page_array_clear(a);
    287      1.96     rmind 				mutex_enter(uobj->vmobjlock);
    288      1.37       chs 				continue;
    289      1.47       chs 			}
    290      1.97      matt 			UVMHIST_LOG(ubchist, "alloced %p (color %u)", pg,
    291      1.97      matt 			    VM_PGCOLOR_BUCKET(pg), 0,0);
    292      1.37       chs 			break;
    293      1.37       chs 		} else if (flags & UFP_NOCACHE) {
    294      1.37       chs 			UVMHIST_LOG(ubchist, "nocache",0,0,0,0);
    295  1.97.2.2      yamt 			goto skip;
    296       1.8       mrg 		}
    297       1.8       mrg 
    298      1.37       chs 		/* page is there, see if we need to wait on it */
    299      1.52       chs 		if ((pg->flags & PG_BUSY) != 0) {
    300      1.37       chs 			if (flags & UFP_NOWAIT) {
    301      1.37       chs 				UVMHIST_LOG(ubchist, "nowait",0,0,0,0);
    302  1.97.2.2      yamt 				goto skip;
    303      1.37       chs 			}
    304      1.37       chs 			pg->flags |= PG_WANTED;
    305      1.97      matt 			UVMHIST_LOG(ubchist, "wait %p (color %u)", pg,
    306      1.97      matt 			    VM_PGCOLOR_BUCKET(pg), 0,0);
    307      1.96     rmind 			UVM_UNLOCK_AND_WAIT(pg, uobj->vmobjlock, 0,
    308      1.37       chs 					    "uvn_fp2", 0);
    309  1.97.2.2      yamt 			uvm_page_array_clear(a);
    310      1.96     rmind 			mutex_enter(uobj->vmobjlock);
    311      1.37       chs 			continue;
    312       1.8       mrg 		}
    313      1.49       chs 
    314  1.97.2.1      yamt 		/* skip PG_RDONLY and PG_HOLE pages if requested */
    315  1.97.2.1      yamt 		if ((flags & UFP_NORDONLY) &&
    316  1.97.2.1      yamt 		    (pg->flags & (PG_RDONLY|PG_HOLE))) {
    317      1.37       chs 			UVMHIST_LOG(ubchist, "nordonly",0,0,0,0);
    318  1.97.2.2      yamt 			goto skip;
    319       1.8       mrg 		}
    320       1.8       mrg 
    321  1.97.2.3      yamt 		/*
    322  1.97.2.3      yamt 		 * check for PG_PAGER1 requests
    323  1.97.2.3      yamt 		 */
    324  1.97.2.3      yamt 		if ((flags & UFP_NOPAGER1) != 0 &&
    325  1.97.2.3      yamt 		    (pg->flags & PG_PAGER1) != 0) {
    326  1.97.2.3      yamt 			UVMHIST_LOG(ubchist, "nopager1",0,0,0,0);
    327  1.97.2.3      yamt 			goto skip;
    328  1.97.2.3      yamt 		}
    329  1.97.2.3      yamt 		if ((flags & UFP_ONLYPAGER1) != 0 &&
    330  1.97.2.3      yamt 		    (pg->flags & PG_PAGER1) == 0) {
    331  1.97.2.3      yamt 			UVMHIST_LOG(ubchist, "onlypager1",0,0,0,0);
    332  1.97.2.3      yamt 			goto skip;
    333  1.97.2.3      yamt 		}
    334  1.97.2.3      yamt 
    335      1.52       chs 		/* stop on clean pages if requested */
    336      1.52       chs 		if (flags & UFP_DIRTYONLY) {
    337  1.97.2.1      yamt 			dirty = uvm_pagecheckdirty(pg, false);
    338      1.52       chs 			if (!dirty) {
    339      1.58     enami 				UVMHIST_LOG(ubchist, "dirtonly", 0,0,0,0);
    340      1.52       chs 				return 0;
    341      1.52       chs 			}
    342      1.52       chs 		}
    343      1.52       chs 
    344      1.37       chs 		/* mark the page BUSY and we're done. */
    345      1.37       chs 		pg->flags |= PG_BUSY;
    346      1.37       chs 		UVM_PAGE_OWN(pg, "uvn_findpage");
    347      1.97      matt 		UVMHIST_LOG(ubchist, "found %p (color %u)",
    348      1.97      matt 		    pg, VM_PGCOLOR_BUCKET(pg), 0,0);
    349  1.97.2.2      yamt 		uvm_page_array_advance(a);
    350      1.37       chs 		break;
    351       1.8       mrg 	}
    352      1.37       chs 	*pgp = pg;
    353      1.37       chs 	return 1;
    354  1.97.2.2      yamt 
    355  1.97.2.2      yamt skip:
    356  1.97.2.2      yamt 	pg = uvm_page_array_peek(a);
    357  1.97.2.2      yamt 	if (pg != NULL) {
    358  1.97.2.2      yamt 		if (pg->offset == offset) {
    359  1.97.2.2      yamt 			uvm_page_array_advance(a);
    360  1.97.2.2      yamt 		} else {
    361  1.97.2.2      yamt 			KASSERT((fillflags & UVM_PAGE_ARRAY_FILL_DENSE) == 0);
    362  1.97.2.2      yamt 		}
    363  1.97.2.2      yamt 	}
    364  1.97.2.2      yamt 	return 0;
    365       1.1       mrg }
    366       1.1       mrg 
    367       1.1       mrg /*
    368      1.52       chs  * uvm_vnp_setsize: grow or shrink a vnode uobj
    369       1.1       mrg  *
    370       1.1       mrg  * grow   => just update size value
    371       1.1       mrg  * shrink => toss un-needed pages
    372       1.1       mrg  *
    373      1.49       chs  * => we assume that the caller has a reference of some sort to the
    374       1.1       mrg  *	vnode in question so that it will not be yanked out from under
    375       1.1       mrg  *	us.
    376       1.1       mrg  */
    377       1.1       mrg 
    378       1.8       mrg void
    379      1.65   thorpej uvm_vnp_setsize(struct vnode *vp, voff_t newsize)
    380       1.8       mrg {
    381      1.52       chs 	struct uvm_object *uobj = &vp->v_uobj;
    382      1.46     enami 	voff_t pgend = round_page(newsize);
    383      1.72      yamt 	voff_t oldsize;
    384      1.37       chs 	UVMHIST_FUNC("uvm_vnp_setsize"); UVMHIST_CALLED(ubchist);
    385      1.37       chs 
    386      1.96     rmind 	mutex_enter(uobj->vmobjlock);
    387      1.52       chs 	UVMHIST_LOG(ubchist, "vp %p old 0x%x new 0x%x",
    388      1.52       chs 	    vp, vp->v_size, newsize, 0);
    389       1.1       mrg 
    390       1.8       mrg 	/*
    391      1.37       chs 	 * now check if the size has changed: if we shrink we had better
    392      1.37       chs 	 * toss some pages...
    393       1.8       mrg 	 */
    394       1.1       mrg 
    395      1.85     pooka 	KASSERT(newsize != VSIZENOTSET);
    396      1.85     pooka 	KASSERT(vp->v_size <= vp->v_writesize);
    397      1.85     pooka 	KASSERT(vp->v_size == vp->v_writesize ||
    398      1.85     pooka 	    newsize == vp->v_writesize || newsize <= vp->v_size);
    399      1.85     pooka 
    400      1.85     pooka 	oldsize = vp->v_writesize;
    401      1.85     pooka 	KASSERT(oldsize != VSIZENOTSET || pgend > oldsize);
    402      1.85     pooka 
    403      1.85     pooka 	if (oldsize > pgend) {
    404      1.57       chs 		(void) uvn_put(uobj, pgend, 0, PGO_FREE | PGO_SYNCIO);
    405      1.96     rmind 		mutex_enter(uobj->vmobjlock);
    406       1.8       mrg 	}
    407      1.82      yamt 	vp->v_size = vp->v_writesize = newsize;
    408      1.96     rmind 	mutex_exit(uobj->vmobjlock);
    409       1.1       mrg }
    410       1.1       mrg 
    411      1.82      yamt void
    412      1.82      yamt uvm_vnp_setwritesize(struct vnode *vp, voff_t newsize)
    413      1.82      yamt {
    414      1.82      yamt 
    415      1.96     rmind 	mutex_enter(vp->v_interlock);
    416      1.85     pooka 	KASSERT(newsize != VSIZENOTSET);
    417      1.82      yamt 	KASSERT(vp->v_size != VSIZENOTSET);
    418      1.82      yamt 	KASSERT(vp->v_writesize != VSIZENOTSET);
    419      1.82      yamt 	KASSERT(vp->v_size <= vp->v_writesize);
    420      1.82      yamt 	KASSERT(vp->v_size <= newsize);
    421      1.82      yamt 	vp->v_writesize = newsize;
    422      1.96     rmind 	mutex_exit(vp->v_interlock);
    423      1.82      yamt }
    424      1.82      yamt 
    425      1.79   thorpej bool
    426      1.75      yamt uvn_text_p(struct uvm_object *uobj)
    427      1.75      yamt {
    428      1.75      yamt 	struct vnode *vp = (struct vnode *)uobj;
    429      1.75      yamt 
    430      1.86        ad 	return (vp->v_iflag & VI_EXECMAP) != 0;
    431      1.75      yamt }
    432      1.75      yamt 
    433      1.79   thorpej bool
    434      1.75      yamt uvn_clean_p(struct uvm_object *uobj)
    435      1.75      yamt {
    436      1.75      yamt 	struct vnode *vp = (struct vnode *)uobj;
    437      1.75      yamt 
    438      1.86        ad 	return (vp->v_iflag & VI_ONWORKLST) == 0;
    439      1.75      yamt }
    440      1.75      yamt 
    441      1.79   thorpej bool
    442      1.75      yamt uvn_needs_writefault_p(struct uvm_object *uobj)
    443      1.75      yamt {
    444      1.75      yamt 	struct vnode *vp = (struct vnode *)uobj;
    445      1.75      yamt 
    446      1.75      yamt 	return uvn_clean_p(uobj) ||
    447      1.86        ad 	    (vp->v_iflag & (VI_WRMAP|VI_WRMAPDIRTY)) == VI_WRMAP;
    448      1.75      yamt }
    449