2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
59 * General definitions.
62 #ifndef _DEFAULT_PAGER_INTERNAL_H_
63 #define _DEFAULT_PAGER_INTERNAL_H_
65 #include <default_pager/diag.h>
66 #include <default_pager/default_pager_types.h>
67 #include <mach/mach_types.h>
68 #include <ipc/ipc_port.h>
69 #include <ipc/ipc_types.h>
70 #include <ipc/ipc_space.h>
71 #include <kern/lock.h>
72 #include <kern/kalloc.h>
73 #include <kern/thread.h>
74 #include <vm/vm_kern.h>
75 #include <device/device_types.h>
78 * Default option settings.
88 #define MACH_PORT_FACE mach_port_t
92 #define USE_PRECIOUS TRUE
97 #define UP(stuff) stuff
98 #else /* USER_PAGER */
100 #endif /* USER_PAGER */
102 #define dprintf(args) \
104 printf("%s[KERNEL]: ", my_name); \
111 __private_extern__
char my_name
[];
113 #define DEFAULT_PAGER_DEBUG 0
115 #if DEFAULT_PAGER_DEBUG
117 extern int debug_mask
;
118 #define DEBUG_MSG_EXTERNAL 0x00000001
119 #define DEBUG_MSG_INTERNAL 0x00000002
120 #define DEBUG_MO_EXTERNAL 0x00000100
121 #define DEBUG_MO_INTERNAL 0x00000200
122 #define DEBUG_VS_EXTERNAL 0x00010000
123 #define DEBUG_VS_INTERNAL 0x00020000
124 #define DEBUG_BS_EXTERNAL 0x01000000
125 #define DEBUG_BS_INTERNAL 0x02000000
127 #define DP_DEBUG(level, args) \
129 if (debug_mask & (level)) \
133 #define ASSERT(expr) \
137 panic("%s[%d]%s: assertion failed in %s line %d: %s",\
138 my_name
, dp_thread_id(), here
, \
139 __FILE__
, __LINE__
, # expr); \
141 panic("%s[KERNEL]: assertion failed in %s line %d: %s",\
142 my_name
, __FILE__
, __LINE__
, # expr); \
146 #else /* DEFAULT_PAGER_DEBUG */
148 #define DP_DEBUG(level, args) do {} while(0)
149 #define ASSERT(clause) do {} while(0)
151 #endif /* DEFAULT_PAGER_DEBUG */
154 extern char *mach_error_string(kern_return_t
);
157 #define PAGER_SUCCESS 0
159 #define PAGER_ERROR 2
162 * VM and IPC globals.
165 #define vm_page_size PAGE_SIZE
166 #define vm_page_mask PAGE_MASK
167 #define vm_page_shift PAGE_SHIFT
169 extern vm_object_size_t vm_page_size
;
170 extern unsigned long long vm_page_mask
;
171 extern int vm_page_shift
;
175 #define ptoa(p) ((p)*vm_page_size)
176 #define atop(a) ((a)/vm_page_size)
178 #define howmany(a,b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1))
180 extern memory_object_default_t default_pager_object
;
183 extern lck_mtx_t dpt_lock
; /* Lock for the dpt array */
184 extern int default_pager_internal_count
;
185 extern MACH_PORT_FACE default_pager_host_port
;
186 /* extern task_t default_pager_self; */ /* dont need or want */
187 extern MACH_PORT_FACE default_pager_internal_set
;
188 extern MACH_PORT_FACE default_pager_external_set
;
189 extern MACH_PORT_FACE default_pager_default_set
;
191 extern mach_port_t default_pager_host_port
;
192 extern task_port_t default_pager_self
;
193 extern mach_port_t default_pager_internal_set
;
194 extern mach_port_t default_pager_external_set
;
195 extern mach_port_t default_pager_default_set
;
198 typedef vm32_offset_t dp_offset_t
;
199 typedef vm32_size_t dp_size_t
;
200 typedef vm32_address_t dp_address_t
;
202 typedef struct default_pager_thread
{
204 cthread_t dpt_thread
; /* Server thread. */
206 vm_offset_t dpt_buffer
; /* Read buffer. */
207 boolean_t dpt_internal
; /* Do we handle internal objects? */
209 int dpt_id
; /* thread id for printf */
213 boolean_t dpt_initialized_p
; /* Thread is ready for requests. */
214 } default_pager_thread_t
;
217 extern default_pager_thread_t
**dpt_array
;
223 struct global_stats
{
224 unsigned int gs_pageout_calls
; /* # pageout calls */
225 unsigned int gs_pagein_calls
; /* # pagein calls */
226 unsigned int gs_pages_in
; /* # pages paged in (total) */
227 unsigned int gs_pages_out
; /* # pages paged out (total) */
228 unsigned int gs_pages_unavail
; /* # zero-fill pages */
229 unsigned int gs_pages_init
; /* # page init requests */
230 unsigned int gs_pages_init_writes
; /* # page init writes */
231 VSTATS_LOCK_DECL(gs_lock
)
233 extern struct global_stats global_stats
;
234 #define GSTAT(clause) VSTATS_ACTION(&global_stats.gs_lock, (clause))
237 * Cluster related definitions.
238 * Clusters are sized in number of pages per cluster.
239 * Cluster sizes must be powers of two.
241 * These numbers are related to the struct vs_map,
244 #define MAX_CLUSTER_SIZE 8
245 #define MAX_CLUSTER_SHIFT 3
249 * bit map related macros
251 #define NBBY 8 /* bits per byte XXX */
252 #define BYTEMASK 0xff
253 #define setbit(a,i) (*(((char *)(a)) + ((i)/NBBY)) |= 1<<((i)%NBBY))
254 #define clrbit(a,i) (*(((char *)(a)) + ((i)/NBBY)) &= ~(1<<((i)%NBBY)))
255 #define isset(a,i) (*(((char *)(a)) + ((i)/NBBY)) & (1<<((i)%NBBY)))
256 #define isclr(a,i) ((*(((char *)(a)) + ((i)/NBBY)) & (1<<((i)%NBBY))) == 0)
260 * Backing Store Management.
266 #define BS_FULLPRI -2
269 * Quick way to access the emergency segment backing store structures
270 * without a full-blown search.
272 extern MACH_PORT_FACE emergency_segment_backing_store
;
275 * Mapping between backing store port and backing store object.
277 struct backing_store
{
278 queue_chain_t bs_links
; /* link in backing_store_list */
279 lck_mtx_t bs_lock
; /* lock for the structure */
280 MACH_PORT_FACE bs_port
; /* backing store port */
282 int bs_clsize
; /* cluster size in pages */
285 unsigned int bs_pages_free
; /* # unallocated pages */
286 unsigned int bs_pages_total
; /* # pages (total) */
287 unsigned int bs_pages_in
; /* # page read requests */
288 unsigned int bs_pages_in_fail
; /* # page read errors */
289 unsigned int bs_pages_out
; /* # page write requests */
290 unsigned int bs_pages_out_fail
; /* # page write errors */
292 typedef struct backing_store
*backing_store_t
;
293 #define BACKING_STORE_NULL ((backing_store_t) 0)
294 #define BS_STAT(bs, clause) VSTATS_ACTION(&(bs)->bs_lock, (clause))
297 #define BS_LOCK_INIT(bs) lck_mtx_init(&(bs)->bs_lock, &default_pager_lck_grp, &default_pager_lck_attr)
298 #define BS_LOCK(bs) lck_mtx_lock(&(bs)->bs_lock)
299 #define BS_UNLOCK(bs) lck_mtx_unlock(&(bs)->bs_lock)
301 struct backing_store_list_head
{
302 queue_head_t bsl_queue
;
306 extern struct backing_store_list_head backing_store_list
;
307 extern int backing_store_release_trigger_disable
;
309 #define BSL_LOCK_INIT() lck_mtx_init(&backing_store_list.bsl_lock, &default_pager_lck_grp, &default_pager_lck_attr)
310 #define BSL_LOCK() lck_mtx_lock(&backing_store_list.bsl_lock)
311 #define BSL_UNLOCK() lck_mtx_unlock(&backing_store_list.bsl_lock)
314 * Paging segment management.
315 * Controls allocation of blocks within paging area.
317 struct paging_segment
{
318 /* device management */
320 MACH_PORT_FACE dev
; /* Port to device */
321 struct vnode
*vnode
; /* vnode for bs file */
323 unsigned int ps_segtype
; /* file type or partition */
324 MACH_PORT_FACE ps_device
; /* Port to device */
325 dp_offset_t ps_offset
; /* Offset of segment within device */
326 dp_offset_t ps_recnum
; /* Number of device records in segment*/
327 unsigned int ps_pgnum
; /* Number of pages in segment */
328 unsigned int ps_record_shift
;/* Bit shift: pages to device records */
330 /* clusters and pages */
331 unsigned int ps_clshift
; /* Bit shift: clusters to pages */
332 unsigned int ps_ncls
; /* Number of clusters in segment */
333 unsigned int ps_clcount
; /* Number of free clusters */
334 unsigned int ps_pgcount
; /* Number of free pages */
335 unsigned int ps_hint
; /* Hint of where to look next. */
336 unsigned int ps_special_clusters
; /* Clusters that might come in while we've
337 * released the locks doing a ps_delete.
341 lck_mtx_t ps_lock
; /* Lock for contents of struct */
342 unsigned char *ps_bmap
; /* Map of used clusters */
345 backing_store_t ps_bs
; /* Backing store segment belongs to */
346 #define PS_CAN_USE 0x1
347 #define PS_GOING_AWAY 0x2
348 #define PS_EMERGENCY_SEGMENT 0x4
349 unsigned int ps_state
;
352 #define IS_PS_OK_TO_USE(ps) ((ps->ps_state & PS_CAN_USE) == PS_CAN_USE)
353 #define IS_PS_GOING_AWAY(ps) ((ps->ps_state & PS_GOING_AWAY) == PS_GOING_AWAY)
354 #define IS_PS_EMERGENCY_SEGMENT(ps) ((ps->ps_state & PS_EMERGENCY_SEGMENT) == PS_EMERGENCY_SEGMENT)
356 #define ps_vnode storage_type.vnode
357 #define ps_device storage_type.dev
358 #define PS_PARTITION 1
361 typedef struct paging_segment
*paging_segment_t
;
363 #define PAGING_SEGMENT_NULL ((paging_segment_t) 0)
365 #define PS_LOCK_INIT(ps) lck_mtx_init(&(ps)->ps_lock, &default_pager_lck_grp, &default_pager_lck_attr)
366 #define PS_LOCK(ps) lck_mtx_lock(&(ps)->ps_lock)
367 #define PS_UNLOCK(ps) lck_mtx_unlock(&(ps)->ps_lock)
369 typedef unsigned int pseg_index_t
;
371 #define INVALID_PSEG_INDEX ((pseg_index_t)-1)
372 #define EMERGENCY_PSEG_INDEX ((pseg_index_t) 0)
374 * MAX_PSEG_INDEX value is related to struct vs_map below.
375 * "0" is reserved for empty map entries (no segment).
377 #define MAX_PSEG_INDEX 63 /* 0 is reserved for empty map */
378 #define MAX_NUM_PAGING_SEGMENTS MAX_PSEG_INDEX
380 /* paging segments array */
381 extern paging_segment_t paging_segments
[MAX_NUM_PAGING_SEGMENTS
];
382 extern lck_mtx_t paging_segments_lock
;
383 extern int paging_segment_count
; /* number of active paging segments */
384 extern int paging_segment_max
; /* highest used paging segment index */
385 extern int ps_select_array
[DEFAULT_PAGER_BACKING_STORE_MAXPRI
+1];
387 #define PSL_LOCK_INIT() lck_mtx_init(&paging_segments_lock, &default_pager_lck_grp, &default_pager_lck_attr)
388 #define PSL_LOCK() lck_mtx_lock(&paging_segments_lock)
389 #define PSL_UNLOCK() lck_mtx_unlock(&paging_segments_lock)
392 * Vstruct manipulation. The vstruct is the pager's internal
393 * representation of vm objects it manages. There is one vstruct allocated
396 * The following data structures are defined for vstruct and vm object
402 * A structure used only for temporary objects. It is the element
403 * contained in the vs_clmap structure, which contains information
404 * about which clusters and pages in an object are present on backing
405 * store (a paging file).
406 * Note that this structure and its associated constants may change
407 * with minimal impact on code. The only function which knows the
408 * internals of this structure is ps_clmap().
410 * If it is necessary to change the maximum number of paging segments
411 * or pages in a cluster, then this structure is the one most
412 * affected. The constants and structures which *may* change are:
415 * MAX_NUM_PAGING_SEGMENTS
416 * VSTRUCT_DEF_CLSHIFT
417 * struct vs_map and associated macros and constants (VSM_*)
418 * (only the macro definitions need change, the exported (inside the
419 * pager only) interfaces remain the same; the constants are for
420 * internal vs_map manipulation only).
421 * struct clbmap (below).
424 unsigned int vsmap_entry
:23, /* offset in paging segment */
425 vsmap_psindex
:8, /* paging segment */
431 typedef struct vs_map
*vs_map_t
;
434 #define VSM_ENTRY_NULL 0x7fffff
437 * Exported macros for manipulating the vs_map structure --
438 * checking status, getting and setting bits.
440 #define VSCLSIZE(vs) (1U << (vs)->vs_clshift)
441 #define VSM_ISCLR(vsm) (((vsm).vsmap_entry == VSM_ENTRY_NULL) && \
442 ((vsm).vsmap_error == 0))
443 #define VSM_ISERR(vsm) ((vsm).vsmap_error)
444 #define VSM_SETCLOFF(vsm, val) ((vsm).vsmap_entry = (val))
445 #define VSM_SETERR(vsm, err) ((vsm).vsmap_error = 1, \
446 (vsm).vsmap_entry = (err))
447 #define VSM_GETERR(vsm) ((vsm).vsmap_entry)
448 #define VSM_SETPG(vsm, page) ((vsm).vsmap_bmap |= (1 << (page)))
449 #define VSM_CLRPG(vsm, page) ((vsm).vsmap_bmap &= ~(1 << (page)))
450 #define VSM_SETPS(vsm, psindx) ((vsm).vsmap_psindex = (psindx))
451 #define VSM_PSINDEX(vsm) ((vsm).vsmap_psindex)
452 #define VSM_PS(vsm) paging_segments[(vsm).vsmap_psindex]
453 #define VSM_BMAP(vsm) ((vsm).vsmap_bmap)
454 #define VSM_CLOFF(vsm) ((vsm).vsmap_entry)
455 #define VSM_CLR(vsm) ((vsm).vsmap_entry = VSM_ENTRY_NULL, \
456 (vsm).vsmap_psindex = 0, \
457 (vsm).vsmap_error = 0, \
458 (vsm).vsmap_bmap = 0, \
459 (vsm).vsmap_alloc = 0)
460 #define VSM_ALLOC(vsm) ((vsm).vsmap_alloc)
461 #define VSM_SETALLOC(vsm, page) ((vsm).vsmap_alloc |= (1 << (page)))
462 #define VSM_CLRALLOC(vsm, page) ((vsm).vsmap_alloc &= ~(1 << (page)))
465 * Constants and macros for dealing with vstruct maps,
466 * which comprise vs_map structures, which
467 * map vm objects to backing storage (paging files and clusters).
469 #define CLMAP_THRESHOLD 512 /* bytes */
470 #define CLMAP_ENTRIES (CLMAP_THRESHOLD/(int)sizeof(struct vs_map))
471 #define CLMAP_SIZE(ncls) (ncls*(int)sizeof(struct vs_map))
473 #define INDIRECT_CLMAP_ENTRIES(ncls) (((ncls-1)/CLMAP_ENTRIES) + 1)
474 #define INDIRECT_CLMAP_SIZE(ncls) (INDIRECT_CLMAP_ENTRIES(ncls) * (int)sizeof(struct vs_map *))
475 #define INDIRECT_CLMAP(size) (CLMAP_SIZE(size) > CLMAP_THRESHOLD)
477 #define RMAPSIZE(blocks) (howmany(blocks,NBBY))
485 * A cluster map returned by ps_clmap. It is an abstracted cluster of
486 * pages. It gives the caller information about the cluster
487 * desired. On read it tells the caller if a cluster is mapped, and if so,
488 * which of its pages are valid. It should not be referenced directly,
489 * except by ps_clmap; macros should be used. If the number of pages
490 * in a cluster needs to be more than 32, then the struct clbmap must
494 unsigned int clb_map
;
498 paging_segment_t cl_ps
; /* paging segment backing cluster */
499 int cl_numpages
; /* number of valid pages */
500 struct clbmap cl_bmap
; /* map of pages in cluster */
501 int cl_error
; /* cluster error value */
502 struct clbmap cl_alloc
; /* map of allocated pages in cluster */
505 #define CLMAP_ERROR(clm) (clm).cl_error
506 #define CLMAP_PS(clm) (clm).cl_ps
507 #define CLMAP_NPGS(clm) (clm).cl_numpages
508 #define CLMAP_ISSET(clm,i) ((1<<(i))&((clm).cl_bmap.clb_map))
509 #define CLMAP_ALLOC(clm) (clm).cl_alloc.clb_map
511 * Shift off unused bits in a partial cluster
513 #define CLMAP_SHIFT(clm,vs) \
514 (clm)->cl_bmap.clb_map >>= (VSCLSIZE(vs) - (clm)->cl_numpages)
515 #define CLMAP_SHIFTALLOC(clm,vs) \
516 (clm)->cl_alloc.clb_map >>= (VSCLSIZE(vs) - (clm)->cl_numpages)
518 typedef struct vstruct_alias
{
519 memory_object_pager_ops_t name
;
523 #define DPT_LOCK_INIT(lock) lck_mtx_init(&(lock), &default_pager_lck_grp, &default_pager_lck_attr)
524 #define DPT_LOCK(lock) lck_mtx_lock(&(lock))
525 #define DPT_UNLOCK(lock) lck_mtx_unlock(&(lock))
526 #define DPT_SLEEP(lock, e, i) lck_mtx_sleep(&(lock), LCK_SLEEP_DEFAULT, (event_t)(e), i)
527 #define VS_LOCK_TYPE hw_lock_data_t
528 #define VS_LOCK_INIT(vs) hw_lock_init(&(vs)->vs_lock)
529 #define VS_TRY_LOCK(vs) (VS_LOCK(vs),TRUE)
530 #define VS_LOCK(vs) hw_lock_lock(&(vs)->vs_lock)
531 #define VS_UNLOCK(vs) hw_lock_unlock(&(vs)->vs_lock)
532 #define VS_MAP_LOCK_TYPE lck_mtx_t
533 #define VS_MAP_LOCK_INIT(vs) lck_mtx_init(&(vs)->vs_map_lock, &default_pager_lck_grp, &default_pager_lck_attr)
534 #define VS_MAP_LOCK(vs) lck_mtx_lock(&(vs)->vs_map_lock)
535 #define VS_MAP_TRY_LOCK(vs) lck_mtx_try_lock(&(vs)->vs_map_lock)
536 #define VS_MAP_UNLOCK(vs) lck_mtx_unlock(&(vs)->vs_map_lock)
540 * VM Object Structure: This is the structure used to manage
541 * default pager object associations with their control counter-
542 * parts (VM objects).
544 * The start of this structure MUST match a "struct memory_object".
546 typedef struct vstruct
{
547 struct ipc_object_header vs_pager_header
; /* fake ip_kotype() */
548 memory_object_pager_ops_t vs_pager_ops
; /* == &default_pager_ops */
549 memory_object_control_t vs_control
; /* our mem obj control ref */
550 VS_LOCK_TYPE vs_lock
; /* data for the lock */
552 /* JMM - Could combine these first two in a single pending count now */
553 unsigned int vs_next_seqno
; /* next sequence num to issue */
554 unsigned int vs_seqno
; /* Pager port sequence number */
555 unsigned int vs_readers
; /* Reads in progress */
556 unsigned int vs_writers
; /* Writes in progress */
559 /* boolean_t */ vs_waiting_seqno
:1, /* to wait on seqno */
560 /* boolean_t */ vs_waiting_read
:1, /* waiting on reader? */
561 /* boolean_t */ vs_waiting_write
:1, /* waiting on writer? */
562 /* boolean_t */ vs_waiting_async
:1, /* waiting on async? */
563 /* boolean_t */ vs_indirect
:1, /* map indirect? */
564 /* boolean_t */ vs_xfer_pending
:1; /* xfer out of seg? */
566 unsigned int vs_async_pending
;/* pending async write count */
567 unsigned int vs_errors
; /* Pageout error count */
568 unsigned int vs_references
; /* references */
570 queue_chain_t vs_links
; /* Link in pager-wide list */
572 unsigned int vs_clshift
; /* Bit shift: clusters->pages */
573 unsigned int vs_size
; /* Object size in clusters */
574 lck_mtx_t vs_map_lock
; /* to protect map below */
576 struct vs_map
*vsu_dmap
; /* Direct map of clusters */
577 struct vs_map
**vsu_imap
; /* Indirect map of clusters */
581 #define vs_dmap vs_un.vsu_dmap
582 #define vs_imap vs_un.vsu_imap
584 #define VSTRUCT_NULL ((vstruct_t) 0)
586 __private_extern__
void vs_async_wait(vstruct_t
);
589 __private_extern__
void vs_lock(vstruct_t
);
590 __private_extern__
void vs_unlock(vstruct_t
);
591 __private_extern__
void vs_start_read(vstruct_t
);
592 __private_extern__
void vs_finish_read(vstruct_t
);
593 __private_extern__
void vs_wait_for_readers(vstruct_t
);
594 __private_extern__
void vs_start_write(vstruct_t
);
595 __private_extern__
void vs_finish_write(vstruct_t
);
596 __private_extern__
void vs_wait_for_writers(vstruct_t
);
597 __private_extern__
void vs_wait_for_sync_writers(vstruct_t
);
600 #define vs_unlock(vs)
601 #define vs_start_read(vs)
602 #define vs_wait_for_readers(vs)
603 #define vs_finish_read(vs)
604 #define vs_start_write(vs)
605 #define vs_wait_for_writers(vs)
606 #define vs_wait_for_sync_writers(vs)
607 #define vs_finish_write(vs)
608 #endif /* PARALLEL */
611 * Data structures and variables dealing with asynchronous
612 * completion of paging operations.
616 * A structure passed to ps_write_device for asynchronous completions.
617 * It contains enough information to complete the write and
618 * inform the VM of its completion.
621 struct vs_async
*vsa_next
; /* pointer to next structure */
622 vstruct_t vsa_vs
; /* the vstruct for the object */
623 vm_offset_t vsa_addr
; /* the vaddr of the data moved */
624 vm_offset_t vsa_offset
; /* the object offset of the data */
625 vm_size_t vsa_size
; /* the number of bytes moved */
626 paging_segment_t vsa_ps
; /* the paging segment used */
627 int vsa_flags
; /* flags */
628 int vsa_error
; /* error, if there is one */
629 MACH_PORT_FACE reply_port
; /* associated reply port */
635 #define VSA_READ 0x0001
636 #define VSA_WRITE 0x0002
637 #define VSA_TRANSFER 0x0004
640 * List of all vstructs. A specific vstruct is
641 * found directly via its port, this list is
642 * only used for monitoring purposes by the
643 * default_pager_object* calls
645 struct vstruct_list_head
{
646 queue_head_t vsl_queue
;
648 int vsl_count
; /* saves code */
651 __private_extern__
struct vstruct_list_head vstruct_list
;
653 __private_extern__
void vstruct_list_insert(vstruct_t vs
);
654 __private_extern__
void vstruct_list_delete(vstruct_t vs
);
657 extern lck_grp_t default_pager_lck_grp
;
658 extern lck_attr_t default_pager_lck_attr
;
660 #define VSL_LOCK_INIT() lck_mtx_init(&vstruct_list.vsl_lock, &default_pager_lck_grp, &default_pager_lck_attr)
661 #define VSL_LOCK() lck_mtx_lock(&vstruct_list.vsl_lock)
662 #define VSL_LOCK_TRY() lck_mtx_try_lock(&vstruct_list.vsl_lock)
663 #define VSL_UNLOCK() lck_mtx_unlock(&vstruct_list.vsl_lock)
664 #define VSL_SLEEP(e,i) lck_mtx_sleep(&vstruct_list.vsl_lock, LCK_SLEEP_DEFAULT, (e), (i))
667 __private_extern__ zone_t vstruct_zone
;
671 * Create port alias for vstruct address.
673 * We assume that the last two bits of a vstruct address will be zero due to
674 * memory allocation restrictions, hence are available for use as a sanity
679 extern const struct memory_object_pager_ops default_pager_ops
;
681 #define mem_obj_is_vs(_mem_obj_) \
682 (((_mem_obj_) != NULL) && \
683 ((_mem_obj_)->mo_pager_ops == &default_pager_ops))
684 #define mem_obj_to_vs(_mem_obj_) \
685 ((vstruct_t)(_mem_obj_))
686 #define vs_to_mem_obj(_vs_) ((memory_object_t)(_vs_))
687 #define vs_lookup(_mem_obj_, _vs_) \
689 if (!mem_obj_is_vs(_mem_obj_)) \
690 panic("bad dp memory object"); \
691 _vs_ = mem_obj_to_vs(_mem_obj_); \
693 #define vs_lookup_safe(_mem_obj_, _vs_) \
695 if (!mem_obj_is_vs(_mem_obj_)) \
696 _vs_ = VSTRUCT_NULL; \
698 _vs_ = mem_obj_to_vs(_mem_obj_); \
702 #define vs_to_port(_vs_) (((vm_offset_t)(_vs_))+1)
703 #define port_to_vs(_port_) ((vstruct_t)(((vm_offset_t)(_port_))&~3))
704 #define port_is_vs(_port_) ((((vm_offset_t)(_port_))&3) == 1)
706 #define vs_lookup(_port_, _vs_) \
708 if (!MACH_PORT_VALID(_port_) || !port_is_vs(_port_) \
709 || port_to_vs(_port_)->vs_mem_obj != (_port_)) \
710 Panic("bad pager port"); \
711 _vs_ = port_to_vs(_port_); \
716 * Cross-module routines declaration.
719 extern int dp_thread_id(void);
721 extern boolean_t
device_reply_server(mach_msg_header_t
*,
722 mach_msg_header_t
*);
724 extern boolean_t
default_pager_no_senders(memory_object_t
,
725 mach_port_mscount_t
);
727 extern void default_pager_no_senders(memory_object_t
,
729 mach_port_mscount_t
);
732 extern int local_log2(unsigned int);
733 extern void bs_initialize(void);
734 extern void bs_global_info(uint64_t *,
736 extern boolean_t
bs_add_device(char *,
738 extern vstruct_t
ps_vstruct_create(dp_size_t
);
739 extern void ps_vstruct_dealloc(vstruct_t
);
740 extern kern_return_t
pvs_cluster_read(vstruct_t
,
744 extern kern_return_t
vs_cluster_write(vstruct_t
,
750 extern dp_offset_t
ps_clmap(vstruct_t
,
756 extern vm_size_t
ps_vstruct_allocated_size(vstruct_t
);
757 extern unsigned int ps_vstruct_allocated_pages(vstruct_t
,
758 default_pager_page_t
*,
760 extern boolean_t
bs_set_default_clsize(unsigned int);
762 extern boolean_t verbose
;
764 extern thread_call_t default_pager_backing_store_monitor_callout
;
765 extern void default_pager_backing_store_monitor(thread_call_param_t
, thread_call_param_t
);
767 extern ipc_port_t max_pages_trigger_port
;
768 extern unsigned int dp_pages_free
;
769 extern unsigned int maximum_pages_free
;
771 /* Do we know yet if swap files need to be encrypted ? */
772 extern boolean_t dp_encryption_inited
;
773 /* Should we encrypt data before writing to swap ? */
774 extern boolean_t dp_encryption
;
776 #endif /* _DEFAULT_PAGER_INTERNAL_H_ */