2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Mach Operating System
24 * Copyright (c) 1987 Carnegie-Mellon University
25 * All rights reserved. The CMU software License Agreement specifies
26 * the terms and conditions for use and redistribution.
31 * "Swap" pager that pages to/from vnodes. Also
32 * handles demand paging from files.
36 #include <mach/boolean.h>
37 #include <sys/param.h>
38 #include <sys/systm.h>
42 #include <sys/vnode.h>
43 #include <sys/namei.h>
44 #include <sys/mount.h>
48 #include <mach/mach_types.h>
49 #include <mach/memory_object_types.h>
51 #include <vm/vm_map.h>
52 #include <vm/vm_kern.h>
53 #include <kern/parallel.h>
54 #include <kern/zalloc.h>
55 #include <kern/kalloc.h>
56 #include <libkern/libkern.h>
58 #include <vm/vnode_pager.h>
59 #include <vm/vm_pageout.h>
61 #include <kern/assert.h>
63 unsigned int vp_pagein
=0;
64 unsigned int vp_pgodirty
=0;
65 unsigned int vp_pgoclean
=0;
66 unsigned int dp_pgouts
=0; /* Default pager pageouts */
67 unsigned int dp_pgins
=0; /* Default pager pageins */
70 vnode_pager_get_filesize(struct vnode
*vp
)
73 return (vm_object_offset_t
) 0;
76 return (vm_object_offset_t
) ubc_getsize(vp
);
81 vnode_pageout(struct vnode
*vp
,
83 vm_offset_t upl_offset
,
84 vm_object_offset_t f_offset
,
89 int result
= PAGER_SUCCESS
;
90 struct proc
*p
= current_proc();
98 boolean_t funnel_state
;
103 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
105 if (upl
!= (upl_t
)NULL
) {
111 panic("-ve count in vnode_pageout");
113 panic("vnode_pageout: size == 0\n");
115 UBCINFOCHECK("vnode_pageout", vp
);
117 if (UBCINVALID(vp
)) {
118 result
= PAGER_ERROR
;
124 * This is a pageout form the Default pager,
125 * just go ahead and call VOP_PAGEOUT
128 if (error
= VOP_PAGEOUT(vp
, upl
, upl_offset
,
129 (off_t
)f_offset
,(size_t)size
, p
->p_ucred
, flags
)) {
130 result
= PAGER_ERROR
;
141 if (vpupl
== (upl_t
) 0)
144 vp_size
= ubc_getsize(vp
);
148 blkno
= ubc_offtoblk(vp
, (off_t
)f_offset
);
150 if (bp
= incore(vp
, blkno
)) {
151 if (ISSET(bp
->b_flags
, B_BUSY
)) {
152 SET(bp
->b_flags
, B_WANTED
);
153 error
= tsleep(bp
, (PRIBIO
+ 1), "vnpgout", 0);
157 SET(bp
->b_flags
, (B_BUSY
|B_INVAL
));
162 f_offset
+= PAGE_SIZE
;
165 ubc_upl_commit_range(vpupl
, 0, size
, UPL_COMMIT_FREE_ON_EMPTY
);
177 if ( !upl_valid_page(pl
, pg_index
)) {
178 ubc_upl_abort_range(vpupl
, offset
, PAGE_SIZE
,
179 UPL_ABORT_FREE_ON_EMPTY
);
187 if ( !upl_dirty_page(pl
, pg_index
)) {
189 * if the page is not dirty and reached here it is
190 * marked precious or it is due to invalidation in
191 * memory_object_lock request as part of truncation
192 * We also get here from vm_object_terminate()
193 * So all you need to do in these
194 * cases is to invalidate incore buffer if it is there
196 blkno
= ubc_offtoblk(vp
, (off_t
)(f_offset
+ offset
));
200 if (bp
= incore(vp
, blkno
)) {
201 if (ISSET(bp
->b_flags
, B_BUSY
)) {
202 SET(bp
->b_flags
, B_WANTED
);
203 error
= tsleep(bp
, (PRIBIO
+ 1), "vnpgout", 0);
207 SET(bp
->b_flags
, (B_BUSY
|B_INVAL
));
214 ubc_upl_commit_range(vpupl
, offset
, PAGE_SIZE
,
215 UPL_COMMIT_FREE_ON_EMPTY
);
226 xsize
= isize
- PAGE_SIZE
;
229 if ( !upl_valid_page(pl
, pg_index
+ num_of_pages
))
231 if ( !upl_dirty_page(pl
, pg_index
+ num_of_pages
))
236 xsize
= num_of_pages
* PAGE_SIZE
;
238 /* By defn callee will commit or abort upls */
239 if (error
= VOP_PAGEOUT(vp
, vpupl
, (vm_offset_t
) offset
,
240 (off_t
)(f_offset
+ offset
),
241 xsize
, p
->p_ucred
, flags
& ~UPL_NOCOMMIT
)) {
242 result
= PAGER_ERROR
;
247 pg_index
+= num_of_pages
;
253 thread_funnel_set(kernel_flock
, funnel_state
);
263 vm_offset_t pl_offset
,
264 vm_object_offset_t f_offset
,
269 int result
= PAGER_SUCCESS
;
270 struct proc
*p
= current_proc();
273 boolean_t funnel_state
;
279 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
282 if(pl
->page_list
.npages
>1 )
283 panic("vnode_pageout: Can't handle more than one page");
286 if (pl
!= (upl_t
)NULL
) {
289 UBCINFOCHECK("vnode_pagein", vp
);
291 if (UBCINVALID(vp
)) {
292 result
= PAGER_ERROR
;
299 if (error
= VOP_PAGEIN(vp
, pl
, pl_offset
, (off_t
)f_offset
,
300 size
,p
->p_ucred
, flags
)) {
301 result
= PAGER_ERROR
;
307 if((size
> 4096) && (vp
->v_tag
== VT_NFS
)) {
309 size
= size
- xfer_size
;
315 f_offset
+local_offset
,
320 if (vpupl
== (upl_t
) 0) {
321 result
= PAGER_ABSENT
;
322 error
= PAGER_ABSENT
;
328 /* By defn callee will commit or abort upls */
329 if (error
= VOP_PAGEIN(vp
, vpupl
, (vm_offset_t
) 0,
330 (off_t
)f_offset
+local_offset
, xfer_size
,p
->p_ucred
, flags
& ~UPL_NOCOMMIT
)) {
331 result
= PAGER_ERROR
;
334 local_offset
+= PAGE_SIZE_64
;
340 thread_funnel_set(kernel_flock
, funnel_state
);
346 vnode_pager_shutdown()
349 extern struct bs_map bs_port_table
[];
352 for(i
= 0; i
< MAX_BACKING_STORE
; i
++) {
353 vp
= (struct vnode
*)(bs_port_table
[i
]).vp
;
355 (bs_port_table
[i
]).vp
= 0;
357 /* get rid of macx_swapon() namei() reference */
360 /* get rid of macx_swapon() "extra" reference */
368 upl_get_internal_page_list(upl_t upl
)
370 return(UPL_GET_INTERNAL_PAGE_LIST(upl
));