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@
27 * $Log: default_pager.c,v $
28 * Revision 1.7 2001/01/15 20:03:32 lindak
29 * Merged PR-2523198-116-3 into Cheetah from magee which fixes all of the
31 * 2430517 2445360 2511207 2513779 2523198 2581705 2585290 2595323 2596060
34 * Revision 1.6.260.1 2001/01/14 10:02:17 jmagee
35 * A conglomeration of fixes related to races in the termination of processes
37 * Bug #2430517 - Race condition between port death and BSD causes wait4() to fail
38 * Bug #2445360 - Process hung in sigsuspend waiting for SIGCHLD
39 * Bug #2511207 - IPC thread_act disable too "loose"
40 * Bug #2513779 - thread_continue is NOT a continuation routine
41 * Bug #2523198 - shuttleless activation during thread creation
42 * Bug #2581705 - 4F8: panic in task_info
43 * Bug #2585290 - PANIC: thread_deallocate: released last reference on map
44 * Bug #2595323 - Cheetah4K9: Lost user context
45 * Bug #2596060 - can't get mutex interlock in vm_map_deallocate / load_machfile
46 * Bug #2601360 - killing CrashReporter causes process hangs
47 * Submitted by: jmagee
48 * Reviewed by: Youngworth Umesh Ramesh
50 * Revision 1.6 2000/10/13 06:21:06 lindak
51 * Merged PR-2425995-2 into Cheetah (youngworth Need Pager and VM support for
52 * 64 bit address space)
54 * Revision 1.5.804.1 2000/10/12 17:29:25 youngwor
55 * Changes for base 64 bit data path support
57 * Revision 1.5.782.1 2000/10/12 14:02:32 youngwor
58 * Changes to support 64 bit data path throughout the kernel.
60 * Submitted by: Chris Youngworth
63 * Revision 1.5 2000/01/26 05:56:22 wsanchez
66 * Revision 1.4 1999/07/20 02:55:34 lindak
67 * Merged PR-2291281-1 into Beaker (magee Kernel Components kobject groupings)
69 * Revision 1.3.674.1 1999/07/20 00:33:02 jmagee
70 * Workaround for partial EMMI components work
72 * Revision 1.3 1999/02/24 16:55:12 wsanchez
75 * Revision 1.2.168.1 1999/02/23 20:43:52 semeria
76 * Component Header files phase 1
78 * Revision 1.2 1998/12/01 00:24:41 wsanchez
79 * Merged in CDY_DP1 (chris: default pager)
81 * Revision 1.1.2.2 1998/11/25 21:32:17 youngwor
82 * fix errant comment format
84 * Revision 1.1.2.1 1998/11/24 22:39:57 youngwor
85 * Check-in of support for the in-kernel default pager
87 * Revision 1.1.1.1 1998/03/07 02:26:31 wsanchez
88 * Import of OSF Mach kernel (~mburg)
90 * Revision 1.2.84.2 1997/03/27 18:45:15 barbou
91 * submit adidtional picco changes
92 * [1996/09/12 22:09:29 robert]
96 * Revision 1.2.84.1 1996/11/29 16:54:38 stephen
97 * nmklinux_1.0b3_shared into pmk1.1
98 * Added -v option (verbose flag) and tests before warning printfs
99 * [1996/07/29 12:25:54 stephen]
101 * Revision 1.2.34.16 1996/07/31 06:41:45 paire
102 * Merged with nmk20b7_shared (1.2.77.1)
105 * Revision 1.2.77.1 1996/04/12 06:30:58 paire
106 * Changed signature of default_pager_thread to (void ()(void *)).
107 * Replaced bzero() by memset().
110 * Revision 1.2.34.15 1995/08/21 20:52:09 devrcs
111 * Initialize dpt_initialized_p element of
112 * default_pager_thread_tb and set it to true after thread starts
113 * up. Wait until all threads have signalled ready before
114 * telling the bootstrap process that it's ok to go ahead.
117 * Revision 1.2.34.14 1995/06/12 18:44:00 dwm
118 * ri-osc CR1394 - allow argument from bootstrap to set cluster size,
119 * Usage: default_pager clsize=4 sd0b, for example
120 * [1995/06/12 18:40:21 dwm]
122 * Revision 1.2.34.13 1995/05/31 07:55:10 emcmanus
123 * Use mach_msg instead of mach_msg_overwrite_trap so that message
124 * operations can be interrupted without provoking a default-pager
125 * panic. Remote gdb does this.
126 * [1995/05/31 07:54:21 emcmanus]
128 * Revision 1.2.34.12 1995/05/25 20:36:39 mmp
129 * Removed TEMPORARILY_USE_OLD_INIT and the !TEMPORARILY_USE_OLD_INIT
130 * code. The change to use m_o_init was not temporary.
131 * [1995/05/25 19:59:17 mmp]
133 * Revision 1.2.34.11 1995/04/07 18:50:57 barbou
134 * Merged into mainline:
135 * Revision 1.2.34.10 1995/02/27 18:24:08 mmp
136 * Replaced m_o_notify with m_o_init; used m_o_change_attributes
137 * instead of m_o_establish; removed m_o_rejected.
138 * [1995/02/27 18:22:40 mmp]
139 * Revision 1.2.34.9 1995/02/23 21:15:48 alanl
140 * Use system_priority instead of server_priority. Fix locking
141 * with regards to pager_extend!
142 * Merged with DIPC2_SHARED.
143 * [1995/02/23 21:14:55 alanl]
147 * Started from the modified b26 file.
148 * Integrated the following MK6 changes:
150 * Fix ri-osc CR846: Avoid use of fixed BASEPRI_SYSTEM; use new
151 * host_info() interface to determine priority dynamically.
152 * [1994/12/23 15:39:32 bolinger]
153 * mk6 CR668 - 1.3b26 merge
154 * Correct local btodb() def; change port_to_ds() et al. to work
155 * with port names returned by current merged kernel.
156 * [1994/12/03 02:10:30 bolinger]
157 * mk6 CR668 - 1.3b26 merge
158 * Did not bring forward PAGING_MEMORY support. Did bring forward
159 * NORMA support -- can be deleted when proven no longer needed.
160 * [1994/11/10 15:32:12 bolinger]
164 * Revision 1.2.56.2 1995/02/13 14:40:41 barbou
166 * Started from the modified b26 file.
167 * Integrated the following MK6 changes:
169 * Fix ri-osc CR846: Avoid use of fixed BASEPRI_SYSTEM; use new
170 * host_info() interface to determine priority dynamically.
171 * [1994/12/23 15:39:32 bolinger]
172 * mk6 CR668 - 1.3b26 merge
173 * Correct local btodb() def; change port_to_ds() et al. to work
174 * with port names returned by current merged kernel.
175 * [1994/12/03 02:10:30 bolinger]
176 * mk6 CR668 - 1.3b26 merge
177 * Did not bring forward PAGING_MEMORY support. Did bring forward
178 * NORMA support -- can be deleted when proven no longer needed.
179 * [1994/11/10 15:32:12 bolinger]
182 * Revision 1.2.46.3 1994/11/02 14:57:23 barbou
183 * Use new task_swappable() interface to make our task unswappable.
186 * Revision 1.2.46.2 1994/10/10 15:28:48 barbou
187 * VM Merge - Default Pager Clustering.
189 * Also split this file in three:
190 * default_pager.c contains code that deals with threads and
192 * dp_memory_object.c contains memory object management code.
193 * dp_backing_store.c contains backing store management code.
196 * Revision 1.2.6.23 1994/05/16 16:43:50 jph
197 * CR8809 -- Fix messages when paging space is exhausted.
198 * CR10905 -- Disallow overlapped paging areas.
199 * [1994/05/16 16:43:04 jph]
201 * Revision 1.2.6.22 1994/04/01 18:42:34 jph
202 * CR10550 -- Add backing store info interfaces.
203 * CR10718 -- Fix pagein error path.
204 * [1994/04/01 18:40:13 jph]
206 * Revision 1.2.6.21 1994/03/04 18:34:49 jeffc
207 * CR10636 -- delete all NMK15_COMPAT support.
208 * [1994/03/04 14:50:44 jeffc]
210 * Revision 1.2.6.20 1994/02/16 14:22:24 jph
211 * CR10554 -- Multi-page requests now handled, albeit crudely.
212 * Fixed leak in data_request for partial page reads.
213 * Tidied up code to be at least consistent.
214 * Fixed ASSERTIONS option and bad assert (name_refs in terminate).
215 * [1994/02/16 14:20:47 jph]
217 * Revision 1.2.6.19 1994/02/07 22:41:25 jph
218 * Merged with changes from 1.2.6.18
219 * [1994/02/07 22:40:25 jph]
221 * CR10433 -- Upgrade default pager.
222 * Add device argument capability.
223 * Removed defunct file_io.h reference.
224 * Replaced pager_{lock_init,lock,unlock,lock_try} macros.
225 * Moved cthreads globals to top of file from middle.
226 * Removed "id" field of "partition_t" - not needed.
227 * Added "device", "offset", "count" and "record_shift" fields
228 * to "partition_t" to record backing store device info.
229 * Removed "p_read", "p_write" and "p_private" fields from
230 * "partition_t" - Unneeded filesystem abstraction.
231 * Merge "struct dstruct" fields into the "struct dpager",
232 * delete "struct dstruct" and "default_pager_t".
233 * Added "struct bstruct" and "all_backing_store" to hold list
234 * of all backing store ports.
235 * Simplify arguments to create_paging_partition().
236 * Delete part_id(), add_paging_file() and default_pager_setup() routines.
237 * Added backing_store_port_alloc(), log2() routine.
238 * Added vm_page_mask and vm_page_shift to augment vm_page_size.
239 * [1994/02/07 22:28:15 jph]
241 * Revision 1.2.6.18 1994/02/01 19:44:38 collins
242 * CR9926: Set the default pager scheduling policy to round-robin with
243 * a priority of BASEPRI_SYSTEM.
244 * [1994/02/01 14:56:05 collins]
246 * Revision 1.2.6.17 1994/01/27 17:04:21 chasb
247 * Expand Copyright markers
248 * [1994/01/27 16:32:40 chasb]
250 * Revision 1.2.6.16 1994/01/26 18:42:03 collins
251 * CR10474: Change any_t to void *.
252 * [1994/01/26 18:39:47 collins]
254 * Revision 1.2.6.15 1994/01/25 17:02:40 jeffc
255 * CR10107 -- Mach spec compliance - eliminate copy_call
256 * [1994/01/24 21:23:43 jeffc]
258 * Revision 1.2.6.14 1994/01/20 16:58:18 meissner
259 * CR 10468 - Make initialization have proper number of {}'s.
260 * [1994/01/19 19:02:57 meissner]
262 * Revision 1.2.6.13 1993/12/03 20:53:51 jvs
263 * Trusted pager throttling changes. CR 10108
264 * [1993/12/03 20:53:09 jvs]
266 * Revision 1.2.6.12 1993/12/02 17:22:34 jph
267 * CR10254 -- Fix warning about unused ledger/ security ports.
268 * [1993/12/02 15:59:30 jph]
270 * Revision 1.2.6.11 1993/11/24 20:30:31 jph
271 * CR9801 brezak merge, ledgers, security and NMK15_COMPAT
272 * [1993/11/23 22:52:33 jph]
274 * New bootstrap_ports() signature.
275 * [1993/11/23 20:58:25 jph]
277 * Revision 1.2.6.10 1993/11/23 18:05:47 watkins
278 * Increment send right for object in mo_notify.
279 * [1993/11/23 18:04:35 watkins]
281 * Revision 1.2.6.9 1993/11/16 21:49:42 watkins
282 * Remove pager_name argument from memory_object_terminate
283 * and memory_object_create, as per spec. Remove mo_init
284 * and flesh out mo_notify. Extend maps for reads beyond the
285 * end. Add xpr traces.
286 * [1993/11/16 21:29:43 watkins]
288 * Revision 1.2.6.8 1993/10/20 18:50:13 gm
289 * CR9928: Remove bootstrap_port lookup.
290 * CR9990: Remove code that deletes initial stack.
291 * [1993/10/20 12:34:40 gm]
293 * Revision 1.2.6.7 1993/10/08 17:32:08 jeffc
294 * CR9508 - Delete typed IPC code
295 * [1993/09/28 17:27:02 jeffc]
297 * Revision 1.2.6.6 1993/10/08 16:08:14 jeffc
298 * CR9792 - delete obsolete memory_object_data_write message.
299 * [1993/10/08 15:59:49 jeffc]
301 * Revision 1.2.6.5 1993/10/05 21:57:08 watkins
302 * New memory object attribute interfaces comply with spec.
303 * [1993/10/05 21:53:27 watkins]
305 * Revision 1.2.6.4 1993/09/16 18:38:39 jeffc
306 * CR9792 - delete defunct EMMI interfaces
307 * [1993/09/15 20:02:07 jeffc]
309 * Revision 1.2.6.3 1993/08/05 17:57:08 gm
310 * CR9627: Moved def_pager_setup and bootstrap code here. Removed
311 * EXT_PAGER code. Fixed up code problems with more agressive warning
312 * in gcc. Added full prototype support. Changed internal interfaces
313 * that had unions as return values to take pointer arguments instead.
314 * Delete bootstrap code since their is now a separate bootstrap task.
315 * Removed set_ras_address() since it should be provided by a machine
316 * dependent file on machines that need it. Changed to get priv
317 * ports using mach interfaces instead of argv.
318 * [1993/07/09 19:11:36 gm]
320 * Revision 1.2.6.2 1993/06/09 02:08:56 gm
321 * Conditionalize no_senders_check for untyped IPC. CR #9058.
322 * [1993/05/11 18:19:30 rod]
324 * Add header files to pick up definitions of Mach traps and
326 * [1993/05/14 15:37:15 jeffc]
328 * Fix ANSI C violations and warnings.
329 * [1993/05/13 21:05:22 jeffc]
331 * Remove dependency on own pathname.
332 * [1993/05/12 17:53:18 jeffc]
334 * Revision 1.2 1993/04/19 15:07:02 devrcs
335 * Added trailer support to untyped ipc. [travos@osf.org, fdr@osf.org]
336 * [1993/04/06 18:14:54 travos]
339 * Added untyped support to bootstrap_compat().
340 * [1993/04/02 17:37:59 rod]
342 * Share more code when building the in kernel version
344 * [93/03/19 bernadat]
346 * Fix memory_object_synchronize hang.
347 * [1993/03/15 13:21:59 david]
349 * memory_object_synchronize define twice
350 * [1993/03/03 15:09:30 david]
352 * remerge with 1.1.2.3
353 * [1993/03/03 14:26:14 david]
355 * Add memory_object_synchronize stub
356 * [1993/03/03 11:04:05 david]
358 * Fixed a deadlock bug in internal pager configuration.
359 * [93/02/25 bernadat]
361 * moved out of mach_kernel directory
362 * [1993/02/27 13:56:35 david]
364 * Modified to use the same new interface (default_pager_object.defs) for both
366 * [1993/02/17 13:40:18 bruel]
368 * Added stubs for new exception interface.
371 * Modified from mk78.
372 * Added the ufs_pager_option.
375 * Yup, it works. Undefine CHECKSUM, debug and
376 * DEBUG_READER_CONFLICTS again.
379 * Update CHECKSUM to work with current dp_map union.
382 * Define debug CHECKSUM and DEBUG_READER_CONFLICTS.
385 * Eliminated use of old memory object calls (set_attributes, data_write, data_provided).
392 * Revision 2.12 92/07/20 13:32:18 cmaeda
393 * Added private version of set_ras_address for fast_tas support.
394 * [92/05/11 14:31:52 cmaeda]
396 * Revision 2.11 92/05/05 10:03:46 danner
397 * For merge purposes, backed-out the unstable stuff.
398 * [92/05/04 11:12:01 af]
400 * Now we can page an object across partitions.
401 * Initial rough ideas about automatically extending
403 * [92/03/11 02:23:58 af]
405 * Revision 2.10 92/03/06 13:58:48 rpd
406 * Fixed pager_dealloc_page calls in pager_dealloc (from af).
407 * Removed chatty printfs.
410 * Revision 2.9 92/03/05 15:58:35 rpd
411 * Changed PAGEMAP_ENTRIES from 128 to 64. From af.
414 * Revision 2.8 92/03/03 12:12:04 rpd
415 * Changed to catch exception messages and handle bootstrap requests.
416 * Added partition_init.
419 * Revision 2.7 92/02/25 11:22:38 elf
420 * Accept creation of objects bigger than any one partition, in
421 * anticipation of the code that will page across partitions.
422 * Since we are at it, also proceed with no paging partitions:
423 * rely on killing unlucky objects on pageouts.
426 * Revision 2.6 92/02/23 23:00:31 elf
427 * Copyright updated, corrected history.
430 * Revision 2.5 92/02/23 22:25:35 elf
431 * Improved handling of big objects, fixed a deadlock in
432 * object relocation, improved printouts.
433 * Now only crash if out of memory, otherwise use the old
434 * code that just marked the object as in-error.
435 * [92/02/23 13:25:49 af]
437 * As per jsb instructions, removed all NORMA conditionals.
438 * Rename port names to odd values, a trivial heuristic that
439 * makes name conflicts even more unlikely.
442 * Refined the port name conflict problem. Instead of renaming
443 * ports that we send to, just set aside the memory that we cannot
444 * use. When objects get deleted put back the memory in the system.
447 * Added renaming of request and name ports (from af).
450 * Many changes. Now supports adding/removing paging files, it does
451 * not immediately panic if a paging file fills up but relocates the
452 * object elsewhere, it uses the precious attribute in data_supply
453 * to reduce paging space usage (under USE_PRECIOUS conditional,
455 * [92/02/19 17:29:54 af]
457 * Two mods: changed bitmap ops to work one int at a time rather
458 * than one byte at a time. This helps under load, e.g. when the
459 * paging file is large and busy. Second mod to use port-to-pointer
460 * casting in lookups, rather than hash+list searching. This not
461 * only helps under load (I see >600 objects on my pmax) but also
462 * increases parallelism a little.
463 * Shrunk the code size by one page in the process.
464 * [92/02/14 01:44:23 af]
466 * Revision 2.4 92/01/23 15:19:41 rpd
467 * Changed to not include mig server interfaces.
470 * Revision 2.3 92/01/14 16:43:14 rpd
471 * Moved mach/default_pager_object.defs to mach/default_pager.defs.
472 * Revised default_pager_info etc. for their new definitions.
473 * Removed (now) unnecessary #define's to rename kernel functions.
475 * Added page_size to default_pager_info.
476 * Added default_pager_object_pages.
479 * Updated to handle name ports from memory_object_create.
480 * Changed to remember the name ports associated with objects.
481 * Changed default_pager_objects to return the name ports.
484 * Added default_pager_objects.
487 * Revision 2.2 92/01/03 19:56:21 dbg
491 * Convert to run outside of kernel.
494 * Revision 2.17 91/08/29 13:44:27 jsb
495 * A couple quick changes for NORMA_VM. Will be fixed later.
497 * Revision 2.16 91/08/28 16:59:29 jsb
498 * Fixed the default values of default_pager_internal_count and
499 * default_pager_external_count.
502 * Revision 2.15 91/08/28 11:09:32 jsb
503 * Added seqnos_memory_object_change_completed.
504 * From dlb: use memory_object_data_supply for pagein when buffer is
505 * going to be deallocated.
506 * From me: don't use data_supply under NORMA_VM (will be fixed).
507 * [91/08/26 14:30:07 jsb]
509 * Changed to process requests in parallel when possible.
511 * Don't bother keeping track of mscount.
513 * Added default_pager_info.
516 * Added sequence numbers to the memory object interface.
517 * Changed to use no-senders notifications.
518 * Changed to keep track of port rights and not use mach_port_destroy.
519 * Added dummy supply-completed and data-return stubs.
522 * Revision 2.14 91/05/18 14:28:32 rpd
523 * Don't give privileges to threads handling external objects.
525 * Enhanced to use multiple threads, for performance and to avoid
526 * a deadlock caused by default_pager_object_create.
527 * Added locking to partitions.
528 * Added locking to pager_port_hashtable.
529 * Changed pager_port_hash to something reasonable.
532 * Revision 2.13 91/05/14 15:21:41 mrt
533 * Correcting copyright
535 * Revision 2.12 91/03/16 14:41:26 rpd
536 * Updated for new kmem_alloc interface.
537 * Fixed memory_object_create to zero the new pager structure.
539 * Removed thread_swappable.
542 * Revision 2.11 91/02/05 17:00:49 mrt
543 * Changed to new copyright
544 * [91/01/28 14:54:31 mrt]
546 * Revision 2.10 90/09/09 14:31:01 rpd
547 * Use decl_simple_lock_data.
550 * Revision 2.9 90/08/27 21:44:51 dbg
551 * Add definitions of NBBY, howmany.
554 * Revision 2.8 90/06/02 14:45:22 rpd
555 * Changed default_pager_object_create so the out argument
556 * is a poly send right.
558 * Removed references to keep_wired_memory.
560 * Converted to new IPC.
561 * Removed data-request queue.
562 * [90/03/26 21:30:57 rpd]
564 * Revision 2.7 90/03/14 21:09:58 rwd
565 * Call default_pager_object_server and add
566 * default_pager_object_create
569 * Revision 2.6 90/01/11 11:41:08 dbg
570 * Use bootstrap-task print routines.
576 * Revision 2.5 89/12/08 19:52:03 rwd
580 * Revision 2.4 89/10/23 12:01:54 dbg
581 * Change pager_read_offset and pager_write_offset to return block
582 * number as function result. default_read()'s caller must now
583 * deallocate data if not the same as the data buffer passed in.
584 * Add register declarations and clean up loops a bit.
587 * Oops - nothing like having your debugging code introduce bugs...
590 * Revision 2.3 89/10/16 15:21:59 rwd
591 * debugging: checksum pages in each object.
594 * Revision 2.2 89/09/08 11:22:06 dbg
595 * Wait for default_partition to be set.
598 * Modified to call outside routines for read and write.
599 * Removed disk structure. Added part_create.
606 * Mach Operating System
607 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
608 * All Rights Reserved.
610 * Permission to use, copy, modify and distribute this software and its
611 * documentation is hereby granted, provided that both the copyright
612 * notice and this permission notice appear in all copies of the
613 * software, derivative works or modified versions, and any portions
614 * thereof, and that both notices appear in supporting documentation.
616 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
617 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
618 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
620 * Carnegie Mellon requests users of this software to return to
622 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
623 * School of Computer Science
624 * Carnegie Mellon University
625 * Pittsburgh PA 15213-3890
627 * any improvements or extensions that they make and grant Carnegie Mellon
628 * the rights to redistribute these changes.
633 * Threads management.
637 #include "default_pager_internal.h"
638 #include <kern/host.h>
639 #include <kern/ledger.h>
640 #include <mach/host_info.h>
641 #include <ipc/ipc_space.h>
642 #include <vm/vm_kern.h>
644 char my_name
[] = "(default pager): ";
646 #if DEFAULT_PAGER_DEBUG
648 #endif /* DEFAULT_PAGER_DEBUG */
651 * Use 16 Kbyte stacks instead of the default 64K.
652 * Use 4 Kbyte waiting stacks instead of the default 8K.
655 vm_size_t cthread_stack_size
= 16 *1024;
656 extern vm_size_t cthread_wait_stack_size
;
658 unsigned long long vm_page_mask
;
665 /* task_t default_pager_self; */ /* Our task port. */
666 mutex_t dpt_lock
; /* lock for the dpt array struct */
667 default_pager_thread_t
**dpt_array
;
669 MACH_PORT_FACE default_pager_default_set
; /* Port set for "default" thread. */
670 MACH_PORT_FACE default_pager_default_port
;/* Port for memory_object_create. */
671 MACH_PORT_FACE default_pager_internal_set
; /* Port set for internal objects. */
672 MACH_PORT_FACE default_pager_external_set
; /* Port set for external objects. */
674 #define DEFAULT_PAGER_INTERNAL_COUNT (4)
677 /* Memory created by default_pager_object_create should mostly be resident. */
678 #define DEFAULT_PAGER_EXTERNAL_COUNT (2)
680 unsigned int default_pager_internal_count
= DEFAULT_PAGER_INTERNAL_COUNT
;
681 /* Number of "internal" threads. */
682 unsigned int default_pager_external_count
= DEFAULT_PAGER_EXTERNAL_COUNT
;
683 /* Number of "external" threads. */
686 * Forward declarations.
688 boolean_t
default_pager_notify_server(mach_msg_header_t
*,
689 mach_msg_header_t
*);
690 boolean_t
default_pager_demux_object(mach_msg_header_t
*,
691 mach_msg_header_t
*);
692 boolean_t
default_pager_demux_default(mach_msg_header_t
*,
693 mach_msg_header_t
*);
694 default_pager_thread_t
*start_default_pager_thread(int, boolean_t
);
695 void default_pager(void);
696 void default_pager_thread(void *);
697 void default_pager_initialize(void);
698 void default_pager_set_policy(MACH_PORT_FACE
);
699 boolean_t
dp_parse_argument(char *); /* forward; */
700 unsigned int d_to_i(char *); /* forward; */
703 extern int vstruct_def_clshift
;
707 * Initialize and Run the default pager
713 static char here
[] = "default_pager";
714 mach_msg_options_t server_options
;
715 default_pager_thread_t dpt
;
721 * Give me space for the thread array and zero it.
723 i
= default_pager_internal_count
+ default_pager_external_count
+ 1;
724 dpt_array
= (default_pager_thread_t
**)
725 kalloc(i
* sizeof(default_pager_thread_t
*));
726 memset(dpt_array
, 0, i
* sizeof(default_pager_thread_t
*));
728 /* Setup my thread structure. */
731 dpt
.dpt_internal
= FALSE
;
732 dpt
.dpt_initialized_p
= TRUE
;
736 * Now we create the threads that will actually
740 for (i
= 0; i
< default_pager_internal_count
; i
++) {
741 dpt_array
[id
] = (default_pager_thread_t
*)
742 kalloc(sizeof (default_pager_thread_t
));
743 if (dpt_array
[id
] == NULL
)
744 Panic("alloc pager thread");
745 kr
= vm_allocate(kernel_map
, &((dpt_array
[id
])->dpt_buffer
),
746 vm_page_size
<< vstruct_def_clshift
, TRUE
);
747 if (kr
!= KERN_SUCCESS
)
748 Panic("alloc thread buffer");
749 kr
= vm_map_wire(kernel_map
, (dpt_array
[id
])->dpt_buffer
,
750 ((dpt_array
[id
])->dpt_buffer
)
751 +(vm_page_size
<< vstruct_def_clshift
),
754 if (kr
!= KERN_SUCCESS
)
755 Panic("wire thread buffer");
756 (dpt_array
[id
])->dpt_internal
= TRUE
;
757 (dpt_array
[id
])->dpt_initialized_p
= TRUE
;
758 (dpt_array
[id
])->checked_out
= FALSE
;
761 DPT_LOCK_INIT(dpt_lock
);
769 /* simple utility: only works for 2^n */
778 while ((n
& 1) == 0) {
788 /* another simple utility, d_to_i(char*) supporting only decimal
789 * and devoid of range checking; obscure name chosen deliberately
790 * to avoid confusion with semantic-rich POSIX routines */
794 unsigned int rval
= 0;
797 while ((ch
= *arg
++) && ch
>= '0' && ch
<= '9') {
808 * Check for non-disk-partition arguments of the form
810 * returning TRUE if one if found
812 boolean_t
dp_parse_argument(char *av
)
815 static char here
[] = "dp_parse_argument";
817 /* Check for '-v' flag */
819 if (av
[0] == '-' && av
[1] == 'v' && av
[2] == 0) {
825 * If we find a '=' followed by an argument in the string,
826 * check for known arguments
828 while (*rhs
&& *rhs
!= '=')
830 if (*rhs
&& *++rhs
) {
832 if (strprefix(av
,"cl")) {
833 if (!bs_set_default_clsize(d_to_i(rhs
)))
834 dprintf(("Bad argument (%s) - ignored\n", av
));
837 /* else if strprefix(av,"another_argument")) {
838 handle_another_argument(av);
846 start_def_pager(char *bs_device
)
850 MACH_PORT_FACE master_device_port;
852 MACH_PORT_FACE security_port
;
854 MACH_PORT_FACE root_ledger_wired;
855 MACH_PORT_FACE root_ledger_paged;
857 static char here
[] = "main";
858 int need_dp_init
= 1;
863 default_pager_host_port = ipc_port_make_send(realhost.host_priv_self);
864 master_device_port = ipc_port_make_send(master_device_port);
865 root_ledger_wired = ipc_port_make_send(root_wired_ledger_port);
866 root_ledger_paged = ipc_port_make_send(root_paged_ledger_port);
868 security_port
= ipc_port_make_send(realhost
.host_security_self
);
878 /* setup read buffers, etc */
879 default_pager_initialize();
884 * Return TRUE if string 2 is a prefix of string 1.
887 strprefix(register const char *s1
, register const char *s2
)
891 while ((c
= *s2
++) != '\0') {
901 MACH_PORT_FACE pager
,
902 default_pager_info_t
*infop
)
904 vm_size_t pages_total
, pages_free
;
906 if (pager
!= default_pager_default_port
)
907 return KERN_INVALID_ARGUMENT
;
909 bs_global_info(&pages_total
, &pages_free
);
911 infop
->dpi_total_space
= ptoa(pages_total
);
912 infop
->dpi_free_space
= ptoa(pages_free
);
913 infop
->dpi_page_size
= vm_page_size
;
920 default_pager_initialize()
923 static char here
[] = "default_pager_initialize";
929 default_pager_default_port
= ipc_port_alloc_kernel();
933 * Export pager interfaces.
936 if ((kr
= netname_check_in(name_server_port
, "UserPager",
938 default_pager_default_port
))
940 dprintf(("netname_check_in returned 0x%x\n", kr
));
943 #else /* USER_PAGER */
948 DMM
= ipc_port_make_send(default_pager_default_port
);
949 clsize
= (vm_page_size
<< vstruct_def_clshift
);
950 kr
= host_default_memory_manager(host_priv_self(), &DMM
, clsize
);
951 if ((kr
!= KERN_SUCCESS
) || (DMM
!= MACH_PORT_NULL
))
952 Panic("default memory manager");
955 #endif /* USER_PAGER */
961 vm_page_mask
= vm_page_size
- 1;
962 vm_page_shift
= local_log2(vm_page_size
);
965 * List of all vstructs.
968 queue_init(&vstruct_list
.vsl_queue
);
969 queue_init(&vstruct_list
.vsl_leak_queue
);
970 vstruct_list
.vsl_count
= 0;
972 VSTATS_LOCK_INIT(&global_stats
.gs_lock
);