]> git.saurik.com Git - apple/xnu.git/blob - bsd/vm/vnode_pager.h
xnu-123.5.tar.gz
[apple/xnu.git] / bsd / vm / vnode_pager.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
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.
27 */
28
29 #ifndef _VNODE_PAGER_
30 #define _VNODE_PAGER_ 1
31
32 #include <mach/kern_return.h>
33 #include <sys/types.h>
34 #include <kern/queue.h>
35
36 #ifdef KERNEL
37
38 #include <mach/boolean.h>
39 #include <vm/vm_pager.h>
40
41 void vnode_pager_init();
42
43 vm_pager_t vnode_pager_setup();
44 boolean_t vnode_has_page();
45 boolean_t vnode_pager_active();
46
47 /*
48 * Vstructs are the internal (to us) description of a unit of backing store.
49 * The are the link between memory objects and the backing store they represent.
50 * For the vnode pager, backing store comes in two flavors: normal files and
51 * swap files.
52 *
53 * For objects that page to and from normal files (e.g. objects that represent
54 * program text segments), we maintain some simple parameters that allow us to
55 * access the file's contents directly through the vnode interface.
56 *
57 * Data for objects without associated vnodes is maintained in the swap files.
58 * Each object that uses one of these as backing store has a vstruct indicating
59 * the swap file of preference (vs_pf) and a mapping between contiguous object
60 * offsets and swap file offsets (vs_pmap). Each entry in this mapping specifies
61 * the pager file to use, and the offset of the page in that pager file. These
62 * mapping entries are of type pfMapEntry.
63 */
64
65 /*
66 * Pager file structure. One per swap file.
67 */
68 typedef struct pager_file {
69 queue_chain_t pf_chain; /* link to other paging files */
70 struct vnode *pf_vp; /* vnode of paging file */
71 u_int pf_count; /* Number of vstruct using this file */
72 u_char *pf_bmap; /* Map of used blocks */
73 long pf_npgs; /* Size of file in pages */
74 long pf_pfree; /* Number of unused pages */
75 long pf_lowat; /* Low water page */
76 long pf_hipage; /* Highest page allocated */
77 long pf_hint; /* Lowest page unallocated */
78 char *pf_name; /* Filename of this file */
79 boolean_t pf_prefer;
80 int pf_index; /* index into the pager_file array */
81 void * pf_lock; /* Lock for alloc and dealloc */
82 } *pager_file_t;
83
84 #define PAGER_FILE_NULL (pager_file_t) 0
85
86 #define MAXPAGERFILES 16
87
88 #define MAX_BACKING_STORE 100
89
90 struct bs_map {
91 struct vnode *vp;
92 void *bs;
93 };
94
95
96
97 /*
98 * Pager file data structures.
99 */
100 #define INDEX_NULL 0
101 typedef struct {
102 unsigned int index:8; /* paging file this block is in */
103 unsigned int offset:24; /* page number where block resides */
104 } pf_entry;
105
106 typedef enum {
107 IS_INODE, /* Local disk */
108 IS_RNODE /* NFS */
109 } vpager_fstype;
110
111 /*
112 * Basic vnode pager structure. One per object, backing-store pair.
113 */
114 typedef struct vstruct {
115 boolean_t is_device; /* Must be first - see vm_pager.h */
116 pager_file_t vs_pf; /* Pager file this uses */
117 pf_entry **vs_pmap; /* Map of pages into paging file */
118 unsigned int
119 /* boolean_t */ vs_swapfile:1; /* vnode is a swapfile */
120 short vs_count; /* use count */
121 int vs_size; /* size of this chunk in pages*/
122 struct vnode *vs_vp; /* vnode to page to */
123 } *vnode_pager_t;
124
125 #define VNODE_PAGER_NULL ((vnode_pager_t) 0)
126
127
128
129 pager_return_t pager_vnode_pagein();
130 pager_return_t pager_vnode_pageout();
131 pager_return_t vnode_pagein();
132 pager_return_t vnode_pageout();
133
134 #endif /* KERNEL */
135
136 #endif /* _VNODE_PAGER_ */