]> git.saurik.com Git - apple/xnu.git/blob - osfmk/default_pager/default_pager.c
xnu-123.5.tar.gz
[apple/xnu.git] / osfmk / default_pager / default_pager.c
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 * @OSF_COPYRIGHT@
24 */
25 /*
26 * HISTORY
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
30 * following:
31 * 2430517 2445360 2511207 2513779 2523198 2581705 2585290 2595323 2596060
32 * 2597427 2601360
33 *
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
36 *
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
49 *
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)
53 *
54 * Revision 1.5.804.1 2000/10/12 17:29:25 youngwor
55 * Changes for base 64 bit data path support
56 *
57 * Revision 1.5.782.1 2000/10/12 14:02:32 youngwor
58 * Changes to support 64 bit data path throughout the kernel.
59 * Bug #: 2425995
60 * Submitted by: Chris Youngworth
61 * Reviewed by:
62 *
63 * Revision 1.5 2000/01/26 05:56:22 wsanchez
64 * Add APSL
65 *
66 * Revision 1.4 1999/07/20 02:55:34 lindak
67 * Merged PR-2291281-1 into Beaker (magee Kernel Components kobject groupings)
68 *
69 * Revision 1.3.674.1 1999/07/20 00:33:02 jmagee
70 * Workaround for partial EMMI components work
71 *
72 * Revision 1.3 1999/02/24 16:55:12 wsanchez
73 * PR-2308031
74 *
75 * Revision 1.2.168.1 1999/02/23 20:43:52 semeria
76 * Component Header files phase 1
77 *
78 * Revision 1.2 1998/12/01 00:24:41 wsanchez
79 * Merged in CDY_DP1 (chris: default pager)
80 *
81 * Revision 1.1.2.2 1998/11/25 21:32:17 youngwor
82 * fix errant comment format
83 *
84 * Revision 1.1.2.1 1998/11/24 22:39:57 youngwor
85 * Check-in of support for the in-kernel default pager
86 *
87 * Revision 1.1.1.1 1998/03/07 02:26:31 wsanchez
88 * Import of OSF Mach kernel (~mburg)
89 *
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]
93 * AXP pool merge.
94 * [97/02/25 barbou]
95 *
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]
100 *
101 * Revision 1.2.34.16 1996/07/31 06:41:45 paire
102 * Merged with nmk20b7_shared (1.2.77.1)
103 * [96/05/30 paire]
104 *
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().
108 * [96/01/30 paire]
109 *
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.
115 * [95/07/10 randys]
116 *
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]
121 *
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]
127 *
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]
132 *
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]
144 * [95/03/08 barbou]
145 *
146 * VM-MK6 Merge.
147 * Started from the modified b26 file.
148 * Integrated the following MK6 changes:
149 *
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]
161 * [95/01/10 barbou]
162 * [95/03/08 barbou]
163 *
164 * Revision 1.2.56.2 1995/02/13 14:40:41 barbou
165 * VM-MK6 Merge.
166 * Started from the modified b26 file.
167 * Integrated the following MK6 changes:
168 *
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]
180 * [95/01/10 barbou]
181 *
182 * Revision 1.2.46.3 1994/11/02 14:57:23 barbou
183 * Use new task_swappable() interface to make our task unswappable.
184 * [94/11/02 barbou]
185 *
186 * Revision 1.2.46.2 1994/10/10 15:28:48 barbou
187 * VM Merge - Default Pager Clustering.
188 *
189 * Also split this file in three:
190 * default_pager.c contains code that deals with threads and
191 * incoming messages.
192 * dp_memory_object.c contains memory object management code.
193 * dp_backing_store.c contains backing store management code.
194 * [94/10/10 barbou]
195 *
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]
200 *
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]
205 *
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]
209 *
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]
216 *
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]
220 *
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]
240 *
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]
245 *
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]
249 *
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]
253 *
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]
257 *
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]
261 *
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]
265 *
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]
269 *
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]
273 *
274 * New bootstrap_ports() signature.
275 * [1993/11/23 20:58:25 jph]
276 *
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]
280 *
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]
287 *
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]
292 *
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]
296 *
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]
300 *
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]
304 *
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]
308 *
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]
319 *
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]
323 *
324 * Add header files to pick up definitions of Mach traps and
325 * wiring interfaces.
326 * [1993/05/14 15:37:15 jeffc]
327 *
328 * Fix ANSI C violations and warnings.
329 * [1993/05/13 21:05:22 jeffc]
330 *
331 * Remove dependency on own pathname.
332 * [1993/05/12 17:53:18 jeffc]
333 *
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]
337 *
338 * Merge untyped ipc:
339 * Added untyped support to bootstrap_compat().
340 * [1993/04/02 17:37:59 rod]
341 *
342 * Share more code when building the in kernel version
343 * of the pager.
344 * [93/03/19 bernadat]
345 *
346 * Fix memory_object_synchronize hang.
347 * [1993/03/15 13:21:59 david]
348 *
349 * memory_object_synchronize define twice
350 * [1993/03/03 15:09:30 david]
351 *
352 * remerge with 1.1.2.3
353 * [1993/03/03 14:26:14 david]
354 *
355 * Add memory_object_synchronize stub
356 * [1993/03/03 11:04:05 david]
357 *
358 * Fixed a deadlock bug in internal pager configuration.
359 * [93/02/25 bernadat]
360 *
361 * moved out of mach_kernel directory
362 * [1993/02/27 13:56:35 david]
363 *
364 * Modified to use the same new interface (default_pager_object.defs) for both
365 * configurations.
366 * [1993/02/17 13:40:18 bruel]
367 *
368 * Added stubs for new exception interface.
369 * [93/02/11 bruel]
370 *
371 * Modified from mk78.
372 * Added the ufs_pager_option.
373 * [93/01/29 bruel]
374 *
375 * Yup, it works. Undefine CHECKSUM, debug and
376 * DEBUG_READER_CONFLICTS again.
377 * [92/12/03 ian]
378 *
379 * Update CHECKSUM to work with current dp_map union.
380 * [92/12/03 ian]
381 *
382 * Define debug CHECKSUM and DEBUG_READER_CONFLICTS.
383 * [92/11/28 ian]
384 *
385 * Eliminated use of old memory object calls (set_attributes, data_write, data_provided).
386 * [92/09/25 jsb]
387 *
388 * $EndLog$
389 */
390 /* CMU_HIST */
391 /*
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]
395 *
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]
399 *
400 * Now we can page an object across partitions.
401 * Initial rough ideas about automatically extending
402 * paging space.
403 * [92/03/11 02:23:58 af]
404 *
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.
408 * [92/03/06 rpd]
409 *
410 * Revision 2.9 92/03/05 15:58:35 rpd
411 * Changed PAGEMAP_ENTRIES from 128 to 64. From af.
412 * [92/03/05 rpd]
413 *
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.
417 * [92/03/03 rpd]
418 *
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.
424 * [92/02/25 af]
425 *
426 * Revision 2.6 92/02/23 23:00:31 elf
427 * Copyright updated, corrected history.
428 * [92/02/23 elf]
429 *
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]
436 *
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.
440 * [92/02/22 af]
441 *
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.
445 * [92/02/21 af]
446 *
447 * Added renaming of request and name ports (from af).
448 * [92/02/21 danner]
449 *
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,
454 * enabled).
455 * [92/02/19 17:29:54 af]
456 *
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]
465 *
466 * Revision 2.4 92/01/23 15:19:41 rpd
467 * Changed to not include mig server interfaces.
468 * [92/01/23 rpd]
469 *
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.
474 * [92/01/13 rpd]
475 * Added page_size to default_pager_info.
476 * Added default_pager_object_pages.
477 * [92/01/03 rpd]
478 *
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.
482 * [91/12/28 rpd]
483 *
484 * Added default_pager_objects.
485 * [91/12/15 rpd]
486 *
487 * Revision 2.2 92/01/03 19:56:21 dbg
488 * Simplify locking.
489 * [91/10/02 dbg]
490 *
491 * Convert to run outside of kernel.
492 * [91/09/04 dbg]
493 *
494 * Revision 2.17 91/08/29 13:44:27 jsb
495 * A couple quick changes for NORMA_VM. Will be fixed later.
496 *
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.
500 * [91/08/28 rpd]
501 *
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]
508 *
509 * Changed to process requests in parallel when possible.
510 *
511 * Don't bother keeping track of mscount.
512 * [91/08/16 rpd]
513 * Added default_pager_info.
514 * [91/08/15 rpd]
515 *
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.
520 * [91/08/13 rpd]
521 *
522 * Revision 2.14 91/05/18 14:28:32 rpd
523 * Don't give privileges to threads handling external objects.
524 * [91/04/06 rpd]
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.
530 * [91/04/03 rpd]
531 *
532 * Revision 2.13 91/05/14 15:21:41 mrt
533 * Correcting copyright
534 *
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.
538 * [91/03/03 rpd]
539 * Removed thread_swappable.
540 * [91/01/18 rpd]
541 *
542 * Revision 2.11 91/02/05 17:00:49 mrt
543 * Changed to new copyright
544 * [91/01/28 14:54:31 mrt]
545 *
546 * Revision 2.10 90/09/09 14:31:01 rpd
547 * Use decl_simple_lock_data.
548 * [90/08/30 rpd]
549 *
550 * Revision 2.9 90/08/27 21:44:51 dbg
551 * Add definitions of NBBY, howmany.
552 * [90/07/16 dbg]
553 *
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.
557 * [90/05/03 rpd]
558 * Removed references to keep_wired_memory.
559 * [90/04/29 rpd]
560 * Converted to new IPC.
561 * Removed data-request queue.
562 * [90/03/26 21:30:57 rpd]
563 *
564 * Revision 2.7 90/03/14 21:09:58 rwd
565 * Call default_pager_object_server and add
566 * default_pager_object_create
567 * [90/01/22 rwd]
568 *
569 * Revision 2.6 90/01/11 11:41:08 dbg
570 * Use bootstrap-task print routines.
571 * [89/12/20 dbg]
572 *
573 * De-lint.
574 * [89/12/06 dbg]
575 *
576 * Revision 2.5 89/12/08 19:52:03 rwd
577 * Turn off CHECKSUM
578 * [89/12/06 rwd]
579 *
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.
585 * [89/10/19 dbg]
586 *
587 * Oops - nothing like having your debugging code introduce bugs...
588 * [89/10/17 dbg]
589 *
590 * Revision 2.3 89/10/16 15:21:59 rwd
591 * debugging: checksum pages in each object.
592 * [89/10/04 dbg]
593 *
594 * Revision 2.2 89/09/08 11:22:06 dbg
595 * Wait for default_partition to be set.
596 * [89/09/01 dbg]
597 *
598 * Modified to call outside routines for read and write.
599 * Removed disk structure. Added part_create.
600 * Reorganized code.
601 * [89/07/11 dbg]
602 *
603 */
604 /* CMU_ENDHIST */
605 /*
606 * Mach Operating System
607 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
608 * All Rights Reserved.
609 *
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.
615 *
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.
619 *
620 * Carnegie Mellon requests users of this software to return to
621 *
622 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
623 * School of Computer Science
624 * Carnegie Mellon University
625 * Pittsburgh PA 15213-3890
626 *
627 * any improvements or extensions that they make and grant Carnegie Mellon
628 * the rights to redistribute these changes.
629 */
630
631 /*
632 * Default pager.
633 * Threads management.
634 * Requests handling.
635 */
636
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>
643
644 char my_name[] = "(default pager): ";
645
646 #if DEFAULT_PAGER_DEBUG
647 int debug_mask = 0;
648 #endif /* DEFAULT_PAGER_DEBUG */
649
650 /*
651 * Use 16 Kbyte stacks instead of the default 64K.
652 * Use 4 Kbyte waiting stacks instead of the default 8K.
653 */
654
655 vm_size_t cthread_stack_size = 16 *1024;
656 extern vm_size_t cthread_wait_stack_size;
657
658 unsigned long long vm_page_mask;
659 int vm_page_shift;
660
661 int norma_mk;
662
663 boolean_t verbose;
664
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;
668
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. */
673
674 #define DEFAULT_PAGER_INTERNAL_COUNT (4)
675
676
677 /* Memory created by default_pager_object_create should mostly be resident. */
678 #define DEFAULT_PAGER_EXTERNAL_COUNT (2)
679
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. */
684
685 /*
686 * Forward declarations.
687 */
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; */
701
702
703 extern int vstruct_def_clshift;
704
705
706 /*
707 * Initialize and Run the default pager
708 */
709 void
710 default_pager(void)
711 {
712 int i, id;
713 static char here[] = "default_pager";
714 mach_msg_options_t server_options;
715 default_pager_thread_t dpt;
716 kern_return_t kr;
717
718
719
720 /*
721 * Give me space for the thread array and zero it.
722 */
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 *));
727
728 /* Setup my thread structure. */
729 id = 0;
730 dpt.dpt_buffer = 0;
731 dpt.dpt_internal = FALSE;
732 dpt.dpt_initialized_p = TRUE;
733 dpt_array[0] = &dpt;
734
735 /*
736 * Now we create the threads that will actually
737 * manage objects.
738 */
739
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),
752 VM_PROT_DEFAULT,
753 FALSE);
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;
759 id++;
760 }
761 DPT_LOCK_INIT(dpt_lock);
762 }
763
764
765
766
767
768
769 /* simple utility: only works for 2^n */
770 int
771 local_log2(
772 unsigned int n)
773 {
774 register int i = 0;
775
776 if(n == 0) return 0;
777
778 while ((n & 1) == 0) {
779 i++;
780 n >>= 1;
781 }
782 return i;
783 }
784
785
786
787
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 */
791 unsigned int
792 d_to_i(char * arg)
793 {
794 unsigned int rval = 0;
795 char ch;
796
797 while ((ch = *arg++) && ch >= '0' && ch <= '9') {
798 rval *= 10;
799 rval += ch - '0';
800 }
801 return(rval);
802 }
803
804
805
806
807 /*
808 * Check for non-disk-partition arguments of the form
809 * attribute=argument
810 * returning TRUE if one if found
811 */
812 boolean_t dp_parse_argument(char *av)
813 {
814 char *rhs = av;
815 static char here[] = "dp_parse_argument";
816
817 /* Check for '-v' flag */
818
819 if (av[0] == '-' && av[1] == 'v' && av[2] == 0) {
820 verbose = TRUE ;
821 return TRUE;
822 }
823
824 /*
825 * If we find a '=' followed by an argument in the string,
826 * check for known arguments
827 */
828 while (*rhs && *rhs != '=')
829 rhs++;
830 if (*rhs && *++rhs) {
831 /* clsize=N pages */
832 if (strprefix(av,"cl")) {
833 if (!bs_set_default_clsize(d_to_i(rhs)))
834 dprintf(("Bad argument (%s) - ignored\n", av));
835 return(TRUE);
836 }
837 /* else if strprefix(av,"another_argument")) {
838 handle_another_argument(av);
839 return(TRUE);
840 } */
841 }
842 return(FALSE);
843 }
844
845 int
846 start_def_pager(char *bs_device)
847 {
848 int my_node;
849 /*
850 MACH_PORT_FACE master_device_port;
851 */
852 MACH_PORT_FACE security_port;
853 /*
854 MACH_PORT_FACE root_ledger_wired;
855 MACH_PORT_FACE root_ledger_paged;
856 */
857 static char here[] = "main";
858 int need_dp_init = 1;
859
860
861
862 /*
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);
867 */
868 security_port = ipc_port_make_send(realhost.host_security_self);
869
870
871 #if NORMA_VM
872 norma_mk = 1;
873 #else
874 norma_mk = 0;
875 #endif
876
877
878 /* setup read buffers, etc */
879 default_pager_initialize();
880 default_pager();
881 }
882
883 /*
884 * Return TRUE if string 2 is a prefix of string 1.
885 */
886 boolean_t
887 strprefix(register const char *s1, register const char *s2)
888 {
889 register int c;
890
891 while ((c = *s2++) != '\0') {
892 if (c != *s1++)
893 return (FALSE);
894 }
895 return (TRUE);
896 }
897
898
899 kern_return_t
900 default_pager_info(
901 MACH_PORT_FACE pager,
902 default_pager_info_t *infop)
903 {
904 vm_size_t pages_total, pages_free;
905
906 if (pager != default_pager_default_port)
907 return KERN_INVALID_ARGUMENT;
908
909 bs_global_info(&pages_total, &pages_free);
910
911 infop->dpi_total_space = ptoa(pages_total);
912 infop->dpi_free_space = ptoa(pages_free);
913 infop->dpi_page_size = vm_page_size;
914
915 return KERN_SUCCESS;
916 }
917
918
919 void
920 default_pager_initialize()
921 {
922 kern_return_t kr;
923 static char here[] = "default_pager_initialize";
924
925
926 /*
927 * Exported DMM port.
928 */
929 default_pager_default_port = ipc_port_alloc_kernel();
930
931
932 /*
933 * Export pager interfaces.
934 */
935 #ifdef USER_PAGER
936 if ((kr = netname_check_in(name_server_port, "UserPager",
937 default_pager_self,
938 default_pager_default_port))
939 != KERN_SUCCESS) {
940 dprintf(("netname_check_in returned 0x%x\n", kr));
941 exit(1);
942 }
943 #else /* USER_PAGER */
944 {
945 int clsize;
946 ipc_port_t DMM;
947
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");
953
954 }
955 #endif /* USER_PAGER */
956
957
958 /*
959 * Vm variables.
960 */
961 vm_page_mask = vm_page_size - 1;
962 vm_page_shift = local_log2(vm_page_size);
963
964 /*
965 * List of all vstructs.
966 */
967 VSL_LOCK_INIT();
968 queue_init(&vstruct_list.vsl_queue);
969 queue_init(&vstruct_list.vsl_leak_queue);
970 vstruct_list.vsl_count = 0;
971
972 VSTATS_LOCK_INIT(&global_stats.gs_lock);
973
974 bs_initialize();
975 }
976