xref: /xnu-8792.81.2/bsd/vm/vnode_pager.h (revision 19c3b8c28c31cb8130e034cfb5df6bf9ba342d90)
1*19c3b8c2SApple OSS Distributions /*
2*19c3b8c2SApple OSS Distributions  * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3*19c3b8c2SApple OSS Distributions  *
4*19c3b8c2SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*19c3b8c2SApple OSS Distributions  *
6*19c3b8c2SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*19c3b8c2SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*19c3b8c2SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*19c3b8c2SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*19c3b8c2SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*19c3b8c2SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*19c3b8c2SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*19c3b8c2SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*19c3b8c2SApple OSS Distributions  *
15*19c3b8c2SApple OSS Distributions  * Please obtain a copy of the License at
16*19c3b8c2SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*19c3b8c2SApple OSS Distributions  *
18*19c3b8c2SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*19c3b8c2SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*19c3b8c2SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*19c3b8c2SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*19c3b8c2SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*19c3b8c2SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*19c3b8c2SApple OSS Distributions  * limitations under the License.
25*19c3b8c2SApple OSS Distributions  *
26*19c3b8c2SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*19c3b8c2SApple OSS Distributions  */
28*19c3b8c2SApple OSS Distributions /*
29*19c3b8c2SApple OSS Distributions  * Mach Operating System
30*19c3b8c2SApple OSS Distributions  * Copyright (c) 1987 Carnegie-Mellon University
31*19c3b8c2SApple OSS Distributions  * All rights reserved.  The CMU software License Agreement specifies
32*19c3b8c2SApple OSS Distributions  * the terms and conditions for use and redistribution.
33*19c3b8c2SApple OSS Distributions  */
34*19c3b8c2SApple OSS Distributions 
35*19c3b8c2SApple OSS Distributions #ifndef _VNODE_PAGER_
36*19c3b8c2SApple OSS Distributions #define _VNODE_PAGER_   1
37*19c3b8c2SApple OSS Distributions 
38*19c3b8c2SApple OSS Distributions #include <mach/kern_return.h>
39*19c3b8c2SApple OSS Distributions #include <sys/types.h>
40*19c3b8c2SApple OSS Distributions #include <kern/queue.h>
41*19c3b8c2SApple OSS Distributions 
42*19c3b8c2SApple OSS Distributions #ifdef  KERNEL
43*19c3b8c2SApple OSS Distributions #include <mach/boolean.h>
44*19c3b8c2SApple OSS Distributions #include <mach/memory_object_types.h>
45*19c3b8c2SApple OSS Distributions #include <mach/vm_types.h>
46*19c3b8c2SApple OSS Distributions #include <vm/vm_protos.h>
47*19c3b8c2SApple OSS Distributions #include <vm/vm_pager.h>
48*19c3b8c2SApple OSS Distributions 
49*19c3b8c2SApple OSS Distributions /*
50*19c3b8c2SApple OSS Distributions  *  Vstructs are the internal (to us) description of a unit of backing store.
51*19c3b8c2SApple OSS Distributions  *  The are the link between memory objects and the backing store they represent.
52*19c3b8c2SApple OSS Distributions  *  For the vnode pager, backing store comes in two flavors: normal files and
53*19c3b8c2SApple OSS Distributions  *  swap files.
54*19c3b8c2SApple OSS Distributions  *
55*19c3b8c2SApple OSS Distributions  *  For objects that page to and from normal files (e.g. objects that represent
56*19c3b8c2SApple OSS Distributions  *  program text segments), we maintain some simple parameters that allow us to
57*19c3b8c2SApple OSS Distributions  *  access the file's contents directly through the vnode interface.
58*19c3b8c2SApple OSS Distributions  *
59*19c3b8c2SApple OSS Distributions  *  Data for objects without associated vnodes is maintained in the swap files.
60*19c3b8c2SApple OSS Distributions  *  Each object that uses one of these as backing store has a vstruct indicating
61*19c3b8c2SApple OSS Distributions  *  the swap file of preference (vs_pf) and a mapping between contiguous object
62*19c3b8c2SApple OSS Distributions  *  offsets and swap file offsets (vs_pmap).  Each entry in this mapping specifies
63*19c3b8c2SApple OSS Distributions  *  the pager file to use, and the offset of the page in that pager file.  These
64*19c3b8c2SApple OSS Distributions  *  mapping entries are of type pfMapEntry.
65*19c3b8c2SApple OSS Distributions  */
66*19c3b8c2SApple OSS Distributions 
67*19c3b8c2SApple OSS Distributions /*
68*19c3b8c2SApple OSS Distributions  * Pager file structure.  One per swap file.
69*19c3b8c2SApple OSS Distributions  */
70*19c3b8c2SApple OSS Distributions typedef struct pager_file {
71*19c3b8c2SApple OSS Distributions 	queue_chain_t   pf_chain;       /* link to other paging files */
72*19c3b8c2SApple OSS Distributions 	struct  vnode   *pf_vp;         /* vnode of paging file */
73*19c3b8c2SApple OSS Distributions 	u_int           pf_count;       /* Number of vstruct using this file */
74*19c3b8c2SApple OSS Distributions 	u_char          *pf_bmap;       /* Map of used blocks */
75*19c3b8c2SApple OSS Distributions 	long            pf_npgs;        /* Size of file in pages */
76*19c3b8c2SApple OSS Distributions 	long            pf_pfree;       /* Number of unused pages */
77*19c3b8c2SApple OSS Distributions 	long            pf_lowat;       /* Low water page */
78*19c3b8c2SApple OSS Distributions 	long            pf_hipage;      /* Highest page allocated */
79*19c3b8c2SApple OSS Distributions 	long            pf_hint;        /* Lowest page unallocated */
80*19c3b8c2SApple OSS Distributions 	char            *pf_name;       /* Filename of this file */
81*19c3b8c2SApple OSS Distributions 	boolean_t       pf_prefer;
82*19c3b8c2SApple OSS Distributions 	int             pf_index;       /* index into the pager_file array */
83*19c3b8c2SApple OSS Distributions 	void *          pf_lock;        /* Lock for alloc and dealloc */
84*19c3b8c2SApple OSS Distributions } *pager_file_t;
85*19c3b8c2SApple OSS Distributions 
86*19c3b8c2SApple OSS Distributions #define PAGER_FILE_NULL (pager_file_t) 0
87*19c3b8c2SApple OSS Distributions 
88*19c3b8c2SApple OSS Distributions #define MAXPAGERFILES 16
89*19c3b8c2SApple OSS Distributions 
90*19c3b8c2SApple OSS Distributions #define MAX_BACKING_STORE 100
91*19c3b8c2SApple OSS Distributions 
92*19c3b8c2SApple OSS Distributions struct bs_map {
93*19c3b8c2SApple OSS Distributions 	struct vnode    *vp;
94*19c3b8c2SApple OSS Distributions 	void            *bs;
95*19c3b8c2SApple OSS Distributions };
96*19c3b8c2SApple OSS Distributions extern struct bs_map  bs_port_table[];
97*19c3b8c2SApple OSS Distributions 
98*19c3b8c2SApple OSS Distributions 
99*19c3b8c2SApple OSS Distributions 
100*19c3b8c2SApple OSS Distributions /*
101*19c3b8c2SApple OSS Distributions  * Pager file data structures.
102*19c3b8c2SApple OSS Distributions  */
103*19c3b8c2SApple OSS Distributions #define INDEX_NULL      0
104*19c3b8c2SApple OSS Distributions typedef struct {
105*19c3b8c2SApple OSS Distributions 	unsigned int index:8;   /* paging file this block is in */
106*19c3b8c2SApple OSS Distributions 	unsigned int offset:24; /* page number where block resides */
107*19c3b8c2SApple OSS Distributions } pf_entry;
108*19c3b8c2SApple OSS Distributions 
109*19c3b8c2SApple OSS Distributions typedef enum {
110*19c3b8c2SApple OSS Distributions 	IS_INODE,               /* Local disk */
111*19c3b8c2SApple OSS Distributions 	IS_RNODE                /* NFS */
112*19c3b8c2SApple OSS Distributions } vpager_fstype;
113*19c3b8c2SApple OSS Distributions 
114*19c3b8c2SApple OSS Distributions /*
115*19c3b8c2SApple OSS Distributions  *  Basic vnode pager structure.  One per object, backing-store pair.
116*19c3b8c2SApple OSS Distributions  */
117*19c3b8c2SApple OSS Distributions typedef struct vstruct {
118*19c3b8c2SApple OSS Distributions 	boolean_t       is_device;      /* Must be first - see vm_pager.h */
119*19c3b8c2SApple OSS Distributions 	pager_file_t    vs_pf;          /* Pager file this uses */
120*19c3b8c2SApple OSS Distributions 	pf_entry        **vs_pmap;      /* Map of pages into paging file */
121*19c3b8c2SApple OSS Distributions 	unsigned int
122*19c3b8c2SApple OSS Distributions 	/* boolean_t */ vs_swapfile:1;  /* vnode is a swapfile */
123*19c3b8c2SApple OSS Distributions 	short           vs_count;       /* use count */
124*19c3b8c2SApple OSS Distributions 	int             vs_size;        /* size of this chunk in pages*/
125*19c3b8c2SApple OSS Distributions 	struct vnode    *vs_vp;         /* vnode to page to */
126*19c3b8c2SApple OSS Distributions } *vnode_pager_t;
127*19c3b8c2SApple OSS Distributions 
128*19c3b8c2SApple OSS Distributions #define VNODE_PAGER_NULL        ((vnode_pager_t) 0)
129*19c3b8c2SApple OSS Distributions 
130*19c3b8c2SApple OSS Distributions #endif  /* KERNEL */
131*19c3b8c2SApple OSS Distributions 
132*19c3b8c2SApple OSS Distributions #endif  /* _VNODE_PAGER_ */
133