|
|
1.1 ! root 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.1.1.1 2000/03/25 21:02:54 wsanchez ! 29: * Import of xnu-68.4 ! 30: * ! 31: * Revision 1.5 2000/01/26 05:56:22 wsanchez ! 32: * Add APSL ! 33: * ! 34: * Revision 1.4 1999/07/20 02:55:34 lindak ! 35: * Merged PR-2291281-1 into Beaker (magee Kernel Components kobject groupings) ! 36: * ! 37: * Revision 1.3.674.1 1999/07/20 00:33:02 jmagee ! 38: * Workaround for partial EMMI components work ! 39: * ! 40: * Revision 1.3 1999/02/24 16:55:12 wsanchez ! 41: * PR-2308031 ! 42: * ! 43: * Revision 1.2.168.1 1999/02/23 20:43:52 semeria ! 44: * Component Header files phase 1 ! 45: * ! 46: * Revision 1.2 1998/12/01 00:24:41 wsanchez ! 47: * Merged in CDY_DP1 (chris: default pager) ! 48: * ! 49: * Revision 1.1.2.2 1998/11/25 21:32:17 youngwor ! 50: * fix errant comment format ! 51: * ! 52: * Revision 1.1.2.1 1998/11/24 22:39:57 youngwor ! 53: * Check-in of support for the in-kernel default pager ! 54: * ! 55: * Revision 1.1.1.1 1998/03/07 02:26:31 wsanchez ! 56: * Import of OSF Mach kernel (~mburg) ! 57: * ! 58: * Revision 1.2.84.2 1997/03/27 18:45:15 barbou ! 59: * submit adidtional picco changes ! 60: * [1996/09/12 22:09:29 robert] ! 61: * AXP pool merge. ! 62: * [97/02/25 barbou] ! 63: * ! 64: * Revision 1.2.84.1 1996/11/29 16:54:38 stephen ! 65: * nmklinux_1.0b3_shared into pmk1.1 ! 66: * Added -v option (verbose flag) and tests before warning printfs ! 67: * [1996/07/29 12:25:54 stephen] ! 68: * ! 69: * Revision 1.2.34.16 1996/07/31 06:41:45 paire ! 70: * Merged with nmk20b7_shared (1.2.77.1) ! 71: * [96/05/30 paire] ! 72: * ! 73: * Revision 1.2.77.1 1996/04/12 06:30:58 paire ! 74: * Changed signature of default_pager_thread to (void ()(void *)). ! 75: * Replaced bzero() by memset(). ! 76: * [96/01/30 paire] ! 77: * ! 78: * Revision 1.2.34.15 1995/08/21 20:52:09 devrcs ! 79: * Initialize dpt_initialized_p element of ! 80: * default_pager_thread_tb and set it to true after thread starts ! 81: * up. Wait until all threads have signalled ready before ! 82: * telling the bootstrap process that it's ok to go ahead. ! 83: * [95/07/10 randys] ! 84: * ! 85: * Revision 1.2.34.14 1995/06/12 18:44:00 dwm ! 86: * ri-osc CR1394 - allow argument from bootstrap to set cluster size, ! 87: * Usage: default_pager clsize=4 sd0b, for example ! 88: * [1995/06/12 18:40:21 dwm] ! 89: * ! 90: * Revision 1.2.34.13 1995/05/31 07:55:10 emcmanus ! 91: * Use mach_msg instead of mach_msg_overwrite_trap so that message ! 92: * operations can be interrupted without provoking a default-pager ! 93: * panic. Remote gdb does this. ! 94: * [1995/05/31 07:54:21 emcmanus] ! 95: * ! 96: * Revision 1.2.34.12 1995/05/25 20:36:39 mmp ! 97: * Removed TEMPORARILY_USE_OLD_INIT and the !TEMPORARILY_USE_OLD_INIT ! 98: * code. The change to use m_o_init was not temporary. ! 99: * [1995/05/25 19:59:17 mmp] ! 100: * ! 101: * Revision 1.2.34.11 1995/04/07 18:50:57 barbou ! 102: * Merged into mainline: ! 103: * Revision 1.2.34.10 1995/02/27 18:24:08 mmp ! 104: * Replaced m_o_notify with m_o_init; used m_o_change_attributes ! 105: * instead of m_o_establish; removed m_o_rejected. ! 106: * [1995/02/27 18:22:40 mmp] ! 107: * Revision 1.2.34.9 1995/02/23 21:15:48 alanl ! 108: * Use system_priority instead of server_priority. Fix locking ! 109: * with regards to pager_extend! ! 110: * Merged with DIPC2_SHARED. ! 111: * [1995/02/23 21:14:55 alanl] ! 112: * [95/03/08 barbou] ! 113: * ! 114: * VM-MK6 Merge. ! 115: * Started from the modified b26 file. ! 116: * Integrated the following MK6 changes: ! 117: * ! 118: * Fix ri-osc CR846: Avoid use of fixed BASEPRI_SYSTEM; use new ! 119: * host_info() interface to determine priority dynamically. ! 120: * [1994/12/23 15:39:32 bolinger] ! 121: * mk6 CR668 - 1.3b26 merge ! 122: * Correct local btodb() def; change port_to_ds() et al. to work ! 123: * with port names returned by current merged kernel. ! 124: * [1994/12/03 02:10:30 bolinger] ! 125: * mk6 CR668 - 1.3b26 merge ! 126: * Did not bring forward PAGING_MEMORY support. Did bring forward ! 127: * NORMA support -- can be deleted when proven no longer needed. ! 128: * [1994/11/10 15:32:12 bolinger] ! 129: * [95/01/10 barbou] ! 130: * [95/03/08 barbou] ! 131: * ! 132: * Revision 1.2.56.2 1995/02/13 14:40:41 barbou ! 133: * VM-MK6 Merge. ! 134: * Started from the modified b26 file. ! 135: * Integrated the following MK6 changes: ! 136: * ! 137: * Fix ri-osc CR846: Avoid use of fixed BASEPRI_SYSTEM; use new ! 138: * host_info() interface to determine priority dynamically. ! 139: * [1994/12/23 15:39:32 bolinger] ! 140: * mk6 CR668 - 1.3b26 merge ! 141: * Correct local btodb() def; change port_to_ds() et al. to work ! 142: * with port names returned by current merged kernel. ! 143: * [1994/12/03 02:10:30 bolinger] ! 144: * mk6 CR668 - 1.3b26 merge ! 145: * Did not bring forward PAGING_MEMORY support. Did bring forward ! 146: * NORMA support -- can be deleted when proven no longer needed. ! 147: * [1994/11/10 15:32:12 bolinger] ! 148: * [95/01/10 barbou] ! 149: * ! 150: * Revision 1.2.46.3 1994/11/02 14:57:23 barbou ! 151: * Use new task_swappable() interface to make our task unswappable. ! 152: * [94/11/02 barbou] ! 153: * ! 154: * Revision 1.2.46.2 1994/10/10 15:28:48 barbou ! 155: * VM Merge - Default Pager Clustering. ! 156: * ! 157: * Also split this file in three: ! 158: * default_pager.c contains code that deals with threads and ! 159: * incoming messages. ! 160: * dp_memory_object.c contains memory object management code. ! 161: * dp_backing_store.c contains backing store management code. ! 162: * [94/10/10 barbou] ! 163: * ! 164: * Revision 1.2.6.23 1994/05/16 16:43:50 jph ! 165: * CR8809 -- Fix messages when paging space is exhausted. ! 166: * CR10905 -- Disallow overlapped paging areas. ! 167: * [1994/05/16 16:43:04 jph] ! 168: * ! 169: * Revision 1.2.6.22 1994/04/01 18:42:34 jph ! 170: * CR10550 -- Add backing store info interfaces. ! 171: * CR10718 -- Fix pagein error path. ! 172: * [1994/04/01 18:40:13 jph] ! 173: * ! 174: * Revision 1.2.6.21 1994/03/04 18:34:49 jeffc ! 175: * CR10636 -- delete all NMK15_COMPAT support. ! 176: * [1994/03/04 14:50:44 jeffc] ! 177: * ! 178: * Revision 1.2.6.20 1994/02/16 14:22:24 jph ! 179: * CR10554 -- Multi-page requests now handled, albeit crudely. ! 180: * Fixed leak in data_request for partial page reads. ! 181: * Tidied up code to be at least consistent. ! 182: * Fixed ASSERTIONS option and bad assert (name_refs in terminate). ! 183: * [1994/02/16 14:20:47 jph] ! 184: * ! 185: * Revision 1.2.6.19 1994/02/07 22:41:25 jph ! 186: * Merged with changes from 1.2.6.18 ! 187: * [1994/02/07 22:40:25 jph] ! 188: * ! 189: * CR10433 -- Upgrade default pager. ! 190: * Add device argument capability. ! 191: * Removed defunct file_io.h reference. ! 192: * Replaced pager_{lock_init,lock,unlock,lock_try} macros. ! 193: * Moved cthreads globals to top of file from middle. ! 194: * Removed "id" field of "partition_t" - not needed. ! 195: * Added "device", "offset", "count" and "record_shift" fields ! 196: * to "partition_t" to record backing store device info. ! 197: * Removed "p_read", "p_write" and "p_private" fields from ! 198: * "partition_t" - Unneeded filesystem abstraction. ! 199: * Merge "struct dstruct" fields into the "struct dpager", ! 200: * delete "struct dstruct" and "default_pager_t". ! 201: * Added "struct bstruct" and "all_backing_store" to hold list ! 202: * of all backing store ports. ! 203: * Simplify arguments to create_paging_partition(). ! 204: * Delete part_id(), add_paging_file() and default_pager_setup() routines. ! 205: * Added backing_store_port_alloc(), log2() routine. ! 206: * Added vm_page_mask and vm_page_shift to augment vm_page_size. ! 207: * [1994/02/07 22:28:15 jph] ! 208: * ! 209: * Revision 1.2.6.18 1994/02/01 19:44:38 collins ! 210: * CR9926: Set the default pager scheduling policy to round-robin with ! 211: * a priority of BASEPRI_SYSTEM. ! 212: * [1994/02/01 14:56:05 collins] ! 213: * ! 214: * Revision 1.2.6.17 1994/01/27 17:04:21 chasb ! 215: * Expand Copyright markers ! 216: * [1994/01/27 16:32:40 chasb] ! 217: * ! 218: * Revision 1.2.6.16 1994/01/26 18:42:03 collins ! 219: * CR10474: Change any_t to void *. ! 220: * [1994/01/26 18:39:47 collins] ! 221: * ! 222: * Revision 1.2.6.15 1994/01/25 17:02:40 jeffc ! 223: * CR10107 -- Mach spec compliance - eliminate copy_call ! 224: * [1994/01/24 21:23:43 jeffc] ! 225: * ! 226: * Revision 1.2.6.14 1994/01/20 16:58:18 meissner ! 227: * CR 10468 - Make initialization have proper number of {}'s. ! 228: * [1994/01/19 19:02:57 meissner] ! 229: * ! 230: * Revision 1.2.6.13 1993/12/03 20:53:51 jvs ! 231: * Trusted pager throttling changes. CR 10108 ! 232: * [1993/12/03 20:53:09 jvs] ! 233: * ! 234: * Revision 1.2.6.12 1993/12/02 17:22:34 jph ! 235: * CR10254 -- Fix warning about unused ledger/ security ports. ! 236: * [1993/12/02 15:59:30 jph] ! 237: * ! 238: * Revision 1.2.6.11 1993/11/24 20:30:31 jph ! 239: * CR9801 brezak merge, ledgers, security and NMK15_COMPAT ! 240: * [1993/11/23 22:52:33 jph] ! 241: * ! 242: * New bootstrap_ports() signature. ! 243: * [1993/11/23 20:58:25 jph] ! 244: * ! 245: * Revision 1.2.6.10 1993/11/23 18:05:47 watkins ! 246: * Increment send right for object in mo_notify. ! 247: * [1993/11/23 18:04:35 watkins] ! 248: * ! 249: * Revision 1.2.6.9 1993/11/16 21:49:42 watkins ! 250: * Remove pager_name argument from memory_object_terminate ! 251: * and memory_object_create, as per spec. Remove mo_init ! 252: * and flesh out mo_notify. Extend maps for reads beyond the ! 253: * end. Add xpr traces. ! 254: * [1993/11/16 21:29:43 watkins] ! 255: * ! 256: * Revision 1.2.6.8 1993/10/20 18:50:13 gm ! 257: * CR9928: Remove bootstrap_port lookup. ! 258: * CR9990: Remove code that deletes initial stack. ! 259: * [1993/10/20 12:34:40 gm] ! 260: * ! 261: * Revision 1.2.6.7 1993/10/08 17:32:08 jeffc ! 262: * CR9508 - Delete typed IPC code ! 263: * [1993/09/28 17:27:02 jeffc] ! 264: * ! 265: * Revision 1.2.6.6 1993/10/08 16:08:14 jeffc ! 266: * CR9792 - delete obsolete memory_object_data_write message. ! 267: * [1993/10/08 15:59:49 jeffc] ! 268: * ! 269: * Revision 1.2.6.5 1993/10/05 21:57:08 watkins ! 270: * New memory object attribute interfaces comply with spec. ! 271: * [1993/10/05 21:53:27 watkins] ! 272: * ! 273: * Revision 1.2.6.4 1993/09/16 18:38:39 jeffc ! 274: * CR9792 - delete defunct EMMI interfaces ! 275: * [1993/09/15 20:02:07 jeffc] ! 276: * ! 277: * Revision 1.2.6.3 1993/08/05 17:57:08 gm ! 278: * CR9627: Moved def_pager_setup and bootstrap code here. Removed ! 279: * EXT_PAGER code. Fixed up code problems with more agressive warning ! 280: * in gcc. Added full prototype support. Changed internal interfaces ! 281: * that had unions as return values to take pointer arguments instead. ! 282: * Delete bootstrap code since their is now a separate bootstrap task. ! 283: * Removed set_ras_address() since it should be provided by a machine ! 284: * dependent file on machines that need it. Changed to get priv ! 285: * ports using mach interfaces instead of argv. ! 286: * [1993/07/09 19:11:36 gm] ! 287: * ! 288: * Revision 1.2.6.2 1993/06/09 02:08:56 gm ! 289: * Conditionalize no_senders_check for untyped IPC. CR #9058. ! 290: * [1993/05/11 18:19:30 rod] ! 291: * ! 292: * Add header files to pick up definitions of Mach traps and ! 293: * wiring interfaces. ! 294: * [1993/05/14 15:37:15 jeffc] ! 295: * ! 296: * Fix ANSI C violations and warnings. ! 297: * [1993/05/13 21:05:22 jeffc] ! 298: * ! 299: * Remove dependency on own pathname. ! 300: * [1993/05/12 17:53:18 jeffc] ! 301: * ! 302: * Revision 1.2 1993/04/19 15:07:02 devrcs ! 303: * Added trailer support to untyped ipc. [[email protected], [email protected]] ! 304: * [1993/04/06 18:14:54 travos] ! 305: * ! 306: * Merge untyped ipc: ! 307: * Added untyped support to bootstrap_compat(). ! 308: * [1993/04/02 17:37:59 rod] ! 309: * ! 310: * Share more code when building the in kernel version ! 311: * of the pager. ! 312: * [93/03/19 bernadat] ! 313: * ! 314: * Fix memory_object_synchronize hang. ! 315: * [1993/03/15 13:21:59 david] ! 316: * ! 317: * memory_object_synchronize define twice ! 318: * [1993/03/03 15:09:30 david] ! 319: * ! 320: * remerge with 1.1.2.3 ! 321: * [1993/03/03 14:26:14 david] ! 322: * ! 323: * Add memory_object_synchronize stub ! 324: * [1993/03/03 11:04:05 david] ! 325: * ! 326: * Fixed a deadlock bug in internal pager configuration. ! 327: * [93/02/25 bernadat] ! 328: * ! 329: * moved out of mach_kernel directory ! 330: * [1993/02/27 13:56:35 david] ! 331: * ! 332: * Modified to use the same new interface (default_pager_object.defs) for both ! 333: * configurations. ! 334: * [1993/02/17 13:40:18 bruel] ! 335: * ! 336: * Added stubs for new exception interface. ! 337: * [93/02/11 bruel] ! 338: * ! 339: * Modified from mk78. ! 340: * Added the ufs_pager_option. ! 341: * [93/01/29 bruel] ! 342: * ! 343: * Yup, it works. Undefine CHECKSUM, debug and ! 344: * DEBUG_READER_CONFLICTS again. ! 345: * [92/12/03 ian] ! 346: * ! 347: * Update CHECKSUM to work with current dp_map union. ! 348: * [92/12/03 ian] ! 349: * ! 350: * Define debug CHECKSUM and DEBUG_READER_CONFLICTS. ! 351: * [92/11/28 ian] ! 352: * ! 353: * Eliminated use of old memory object calls (set_attributes, data_write, data_provided). ! 354: * [92/09/25 jsb] ! 355: * ! 356: * $EndLog$ ! 357: */ ! 358: /* CMU_HIST */ ! 359: /* ! 360: * Revision 2.12 92/07/20 13:32:18 cmaeda ! 361: * Added private version of set_ras_address for fast_tas support. ! 362: * [92/05/11 14:31:52 cmaeda] ! 363: * ! 364: * Revision 2.11 92/05/05 10:03:46 danner ! 365: * For merge purposes, backed-out the unstable stuff. ! 366: * [92/05/04 11:12:01 af] ! 367: * ! 368: * Now we can page an object across partitions. ! 369: * Initial rough ideas about automatically extending ! 370: * paging space. ! 371: * [92/03/11 02:23:58 af] ! 372: * ! 373: * Revision 2.10 92/03/06 13:58:48 rpd ! 374: * Fixed pager_dealloc_page calls in pager_dealloc (from af). ! 375: * Removed chatty printfs. ! 376: * [92/03/06 rpd] ! 377: * ! 378: * Revision 2.9 92/03/05 15:58:35 rpd ! 379: * Changed PAGEMAP_ENTRIES from 128 to 64. From af. ! 380: * [92/03/05 rpd] ! 381: * ! 382: * Revision 2.8 92/03/03 12:12:04 rpd ! 383: * Changed to catch exception messages and handle bootstrap requests. ! 384: * Added partition_init. ! 385: * [92/03/03 rpd] ! 386: * ! 387: * Revision 2.7 92/02/25 11:22:38 elf ! 388: * Accept creation of objects bigger than any one partition, in ! 389: * anticipation of the code that will page across partitions. ! 390: * Since we are at it, also proceed with no paging partitions: ! 391: * rely on killing unlucky objects on pageouts. ! 392: * [92/02/25 af] ! 393: * ! 394: * Revision 2.6 92/02/23 23:00:31 elf ! 395: * Copyright updated, corrected history. ! 396: * [92/02/23 elf] ! 397: * ! 398: * Revision 2.5 92/02/23 22:25:35 elf ! 399: * Improved handling of big objects, fixed a deadlock in ! 400: * object relocation, improved printouts. ! 401: * Now only crash if out of memory, otherwise use the old ! 402: * code that just marked the object as in-error. ! 403: * [92/02/23 13:25:49 af] ! 404: * ! 405: * As per jsb instructions, removed all NORMA conditionals. ! 406: * Rename port names to odd values, a trivial heuristic that ! 407: * makes name conflicts even more unlikely. ! 408: * [92/02/22 af] ! 409: * ! 410: * Refined the port name conflict problem. Instead of renaming ! 411: * ports that we send to, just set aside the memory that we cannot ! 412: * use. When objects get deleted put back the memory in the system. ! 413: * [92/02/21 af] ! 414: * ! 415: * Added renaming of request and name ports (from af). ! 416: * [92/02/21 danner] ! 417: * ! 418: * Many changes. Now supports adding/removing paging files, it does ! 419: * not immediately panic if a paging file fills up but relocates the ! 420: * object elsewhere, it uses the precious attribute in data_supply ! 421: * to reduce paging space usage (under USE_PRECIOUS conditional, ! 422: * enabled). ! 423: * [92/02/19 17:29:54 af] ! 424: * ! 425: * Two mods: changed bitmap ops to work one int at a time rather ! 426: * than one byte at a time. This helps under load, e.g. when the ! 427: * paging file is large and busy. Second mod to use port-to-pointer ! 428: * casting in lookups, rather than hash+list searching. This not ! 429: * only helps under load (I see >600 objects on my pmax) but also ! 430: * increases parallelism a little. ! 431: * Shrunk the code size by one page in the process. ! 432: * [92/02/14 01:44:23 af] ! 433: * ! 434: * Revision 2.4 92/01/23 15:19:41 rpd ! 435: * Changed to not include mig server interfaces. ! 436: * [92/01/23 rpd] ! 437: * ! 438: * Revision 2.3 92/01/14 16:43:14 rpd ! 439: * Moved mach/default_pager_object.defs to mach/default_pager.defs. ! 440: * Revised default_pager_info etc. for their new definitions. ! 441: * Removed (now) unnecessary #define's to rename kernel functions. ! 442: * [92/01/13 rpd] ! 443: * Added page_size to default_pager_info. ! 444: * Added default_pager_object_pages. ! 445: * [92/01/03 rpd] ! 446: * ! 447: * Updated to handle name ports from memory_object_create. ! 448: * Changed to remember the name ports associated with objects. ! 449: * Changed default_pager_objects to return the name ports. ! 450: * [91/12/28 rpd] ! 451: * ! 452: * Added default_pager_objects. ! 453: * [91/12/15 rpd] ! 454: * ! 455: * Revision 2.2 92/01/03 19:56:21 dbg ! 456: * Simplify locking. ! 457: * [91/10/02 dbg] ! 458: * ! 459: * Convert to run outside of kernel. ! 460: * [91/09/04 dbg] ! 461: * ! 462: * Revision 2.17 91/08/29 13:44:27 jsb ! 463: * A couple quick changes for NORMA_VM. Will be fixed later. ! 464: * ! 465: * Revision 2.16 91/08/28 16:59:29 jsb ! 466: * Fixed the default values of default_pager_internal_count and ! 467: * default_pager_external_count. ! 468: * [91/08/28 rpd] ! 469: * ! 470: * Revision 2.15 91/08/28 11:09:32 jsb ! 471: * Added seqnos_memory_object_change_completed. ! 472: * From dlb: use memory_object_data_supply for pagein when buffer is ! 473: * going to be deallocated. ! 474: * From me: don't use data_supply under NORMA_VM (will be fixed). ! 475: * [91/08/26 14:30:07 jsb] ! 476: * ! 477: * Changed to process requests in parallel when possible. ! 478: * ! 479: * Don't bother keeping track of mscount. ! 480: * [91/08/16 rpd] ! 481: * Added default_pager_info. ! 482: * [91/08/15 rpd] ! 483: * ! 484: * Added sequence numbers to the memory object interface. ! 485: * Changed to use no-senders notifications. ! 486: * Changed to keep track of port rights and not use mach_port_destroy. ! 487: * Added dummy supply-completed and data-return stubs. ! 488: * [91/08/13 rpd] ! 489: * ! 490: * Revision 2.14 91/05/18 14:28:32 rpd ! 491: * Don't give privileges to threads handling external objects. ! 492: * [91/04/06 rpd] ! 493: * Enhanced to use multiple threads, for performance and to avoid ! 494: * a deadlock caused by default_pager_object_create. ! 495: * Added locking to partitions. ! 496: * Added locking to pager_port_hashtable. ! 497: * Changed pager_port_hash to something reasonable. ! 498: * [91/04/03 rpd] ! 499: * ! 500: * Revision 2.13 91/05/14 15:21:41 mrt ! 501: * Correcting copyright ! 502: * ! 503: * Revision 2.12 91/03/16 14:41:26 rpd ! 504: * Updated for new kmem_alloc interface. ! 505: * Fixed memory_object_create to zero the new pager structure. ! 506: * [91/03/03 rpd] ! 507: * Removed thread_swappable. ! 508: * [91/01/18 rpd] ! 509: * ! 510: * Revision 2.11 91/02/05 17:00:49 mrt ! 511: * Changed to new copyright ! 512: * [91/01/28 14:54:31 mrt] ! 513: * ! 514: * Revision 2.10 90/09/09 14:31:01 rpd ! 515: * Use decl_simple_lock_data. ! 516: * [90/08/30 rpd] ! 517: * ! 518: * Revision 2.9 90/08/27 21:44:51 dbg ! 519: * Add definitions of NBBY, howmany. ! 520: * [90/07/16 dbg] ! 521: * ! 522: * Revision 2.8 90/06/02 14:45:22 rpd ! 523: * Changed default_pager_object_create so the out argument ! 524: * is a poly send right. ! 525: * [90/05/03 rpd] ! 526: * Removed references to keep_wired_memory. ! 527: * [90/04/29 rpd] ! 528: * Converted to new IPC. ! 529: * Removed data-request queue. ! 530: * [90/03/26 21:30:57 rpd] ! 531: * ! 532: * Revision 2.7 90/03/14 21:09:58 rwd ! 533: * Call default_pager_object_server and add ! 534: * default_pager_object_create ! 535: * [90/01/22 rwd] ! 536: * ! 537: * Revision 2.6 90/01/11 11:41:08 dbg ! 538: * Use bootstrap-task print routines. ! 539: * [89/12/20 dbg] ! 540: * ! 541: * De-lint. ! 542: * [89/12/06 dbg] ! 543: * ! 544: * Revision 2.5 89/12/08 19:52:03 rwd ! 545: * Turn off CHECKSUM ! 546: * [89/12/06 rwd] ! 547: * ! 548: * Revision 2.4 89/10/23 12:01:54 dbg ! 549: * Change pager_read_offset and pager_write_offset to return block ! 550: * number as function result. default_read()'s caller must now ! 551: * deallocate data if not the same as the data buffer passed in. ! 552: * Add register declarations and clean up loops a bit. ! 553: * [89/10/19 dbg] ! 554: * ! 555: * Oops - nothing like having your debugging code introduce bugs... ! 556: * [89/10/17 dbg] ! 557: * ! 558: * Revision 2.3 89/10/16 15:21:59 rwd ! 559: * debugging: checksum pages in each object. ! 560: * [89/10/04 dbg] ! 561: * ! 562: * Revision 2.2 89/09/08 11:22:06 dbg ! 563: * Wait for default_partition to be set. ! 564: * [89/09/01 dbg] ! 565: * ! 566: * Modified to call outside routines for read and write. ! 567: * Removed disk structure. Added part_create. ! 568: * Reorganized code. ! 569: * [89/07/11 dbg] ! 570: * ! 571: */ ! 572: /* CMU_ENDHIST */ ! 573: /* ! 574: * Mach Operating System ! 575: * Copyright (c) 1991,1990,1989 Carnegie Mellon University ! 576: * All Rights Reserved. ! 577: * ! 578: * Permission to use, copy, modify and distribute this software and its ! 579: * documentation is hereby granted, provided that both the copyright ! 580: * notice and this permission notice appear in all copies of the ! 581: * software, derivative works or modified versions, and any portions ! 582: * thereof, and that both notices appear in supporting documentation. ! 583: * ! 584: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" ! 585: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR ! 586: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. ! 587: * ! 588: * Carnegie Mellon requests users of this software to return to ! 589: * ! 590: * Software Distribution Coordinator or [email protected] ! 591: * School of Computer Science ! 592: * Carnegie Mellon University ! 593: * Pittsburgh PA 15213-3890 ! 594: * ! 595: * any improvements or extensions that they make and grant Carnegie Mellon ! 596: * the rights to redistribute these changes. ! 597: */ ! 598: ! 599: /* ! 600: * Default pager. ! 601: * Threads management. ! 602: * Requests handling. ! 603: */ ! 604: ! 605: #include "default_pager_internal.h" ! 606: #include <kern/host.h> ! 607: #include <kern/ledger.h> ! 608: #include <mach/host_info.h> ! 609: #include <ipc/ipc_space.h> ! 610: #include <vm/vm_kern.h> ! 611: ! 612: char my_name[] = "(default pager): "; ! 613: ! 614: #if DEFAULT_PAGER_DEBUG ! 615: int debug_mask = 0; ! 616: #endif /* DEFAULT_PAGER_DEBUG */ ! 617: ! 618: /* ! 619: * Use 16 Kbyte stacks instead of the default 64K. ! 620: * Use 4 Kbyte waiting stacks instead of the default 8K. ! 621: */ ! 622: ! 623: vm_size_t cthread_stack_size = 16 *1024; ! 624: extern vm_size_t cthread_wait_stack_size; ! 625: ! 626: int vm_page_mask; ! 627: int vm_page_shift; ! 628: ! 629: int norma_mk; ! 630: ! 631: boolean_t verbose; ! 632: ! 633: /* task_t default_pager_self; */ /* Our task port. */ ! 634: mutex_t dpt_lock; /* lock for the dpt array struct */ ! 635: default_pager_thread_t **dpt_array; ! 636: ! 637: MACH_PORT_FACE default_pager_default_set; /* Port set for "default" thread. */ ! 638: MACH_PORT_FACE default_pager_default_port;/* Port for memory_object_create. */ ! 639: MACH_PORT_FACE default_pager_internal_set; /* Port set for internal objects. */ ! 640: MACH_PORT_FACE default_pager_external_set; /* Port set for external objects. */ ! 641: ! 642: #define DEFAULT_PAGER_INTERNAL_COUNT (4) ! 643: ! 644: ! 645: /* Memory created by default_pager_object_create should mostly be resident. */ ! 646: #define DEFAULT_PAGER_EXTERNAL_COUNT (2) ! 647: ! 648: unsigned int default_pager_internal_count = DEFAULT_PAGER_INTERNAL_COUNT; ! 649: /* Number of "internal" threads. */ ! 650: unsigned int default_pager_external_count = DEFAULT_PAGER_EXTERNAL_COUNT; ! 651: /* Number of "external" threads. */ ! 652: ! 653: /* ! 654: * Forward declarations. ! 655: */ ! 656: boolean_t default_pager_notify_server(mach_msg_header_t *, ! 657: mach_msg_header_t *); ! 658: boolean_t default_pager_demux_object(mach_msg_header_t *, ! 659: mach_msg_header_t *); ! 660: boolean_t default_pager_demux_default(mach_msg_header_t *, ! 661: mach_msg_header_t *); ! 662: default_pager_thread_t *start_default_pager_thread(int, boolean_t); ! 663: void default_pager(void); ! 664: void default_pager_thread(void *); ! 665: void default_pager_initialize(MACH_PORT_FACE); ! 666: void default_pager_set_policy(MACH_PORT_FACE); ! 667: boolean_t dp_parse_argument(char *); /* forward; */ ! 668: unsigned int d_to_i(char *); /* forward; */ ! 669: ! 670: ! 671: extern int vstruct_def_clshift; ! 672: ! 673: ! 674: /* ! 675: * Initialize and Run the default pager ! 676: */ ! 677: void ! 678: default_pager(void) ! 679: { ! 680: int i, id; ! 681: static char here[] = "default_pager"; ! 682: mach_msg_options_t server_options; ! 683: default_pager_thread_t dpt; ! 684: kern_return_t kr; ! 685: ! 686: ! 687: ! 688: /* ! 689: * Give me space for the thread array and zero it. ! 690: */ ! 691: i = default_pager_internal_count + default_pager_external_count + 1; ! 692: dpt_array = (default_pager_thread_t **) ! 693: kalloc(i * sizeof(default_pager_thread_t *)); ! 694: memset(dpt_array, 0, i * sizeof(default_pager_thread_t *)); ! 695: ! 696: /* Setup my thread structure. */ ! 697: id = 0; ! 698: dpt.dpt_buffer = 0; ! 699: dpt.dpt_internal = FALSE; ! 700: dpt.dpt_initialized_p = TRUE; ! 701: dpt_array[0] = &dpt; ! 702: ! 703: /* ! 704: * Now we create the threads that will actually ! 705: * manage objects. ! 706: */ ! 707: ! 708: for (i = 0; i < default_pager_internal_count; i++) { ! 709: dpt_array[id] = (default_pager_thread_t *) ! 710: kalloc(sizeof (default_pager_thread_t)); ! 711: if (dpt_array[id] == NULL) ! 712: Panic("alloc pager thread"); ! 713: kr = vm_allocate(kernel_map, &((dpt_array[id])->dpt_buffer), ! 714: vm_page_size << vstruct_def_clshift, TRUE); ! 715: if (kr != KERN_SUCCESS) ! 716: Panic("alloc thread buffer"); ! 717: kr = vm_map_wire(kernel_map, (dpt_array[id])->dpt_buffer, ! 718: ((dpt_array[id])->dpt_buffer) ! 719: +(vm_page_size << vstruct_def_clshift), ! 720: VM_PROT_DEFAULT, ! 721: FALSE); ! 722: if (kr != KERN_SUCCESS) ! 723: Panic("wire thread buffer"); ! 724: (dpt_array[id])->dpt_internal = TRUE; ! 725: (dpt_array[id])->dpt_initialized_p = TRUE; ! 726: (dpt_array[id])->checked_out = FALSE; ! 727: id++; ! 728: } ! 729: DPT_LOCK_INIT(dpt_lock); ! 730: } ! 731: ! 732: ! 733: ! 734: ! 735: ! 736: ! 737: /* simple utility: only works for 2^n */ ! 738: int ! 739: local_log2( ! 740: unsigned int n) ! 741: { ! 742: register int i = 0; ! 743: ! 744: if(n == 0) return 0; ! 745: ! 746: while ((n & 1) == 0) { ! 747: i++; ! 748: n >>= 1; ! 749: } ! 750: return i; ! 751: } ! 752: ! 753: ! 754: ! 755: ! 756: /* another simple utility, d_to_i(char*) supporting only decimal ! 757: * and devoid of range checking; obscure name chosen deliberately ! 758: * to avoid confusion with semantic-rich POSIX routines */ ! 759: unsigned int ! 760: d_to_i(char * arg) ! 761: { ! 762: unsigned int rval = 0; ! 763: char ch; ! 764: ! 765: while ((ch = *arg++) && ch >= '0' && ch <= '9') { ! 766: rval *= 10; ! 767: rval += ch - '0'; ! 768: } ! 769: return(rval); ! 770: } ! 771: ! 772: ! 773: ! 774: ! 775: /* ! 776: * Check for non-disk-partition arguments of the form ! 777: * attribute=argument ! 778: * returning TRUE if one if found ! 779: */ ! 780: boolean_t dp_parse_argument(char *av) ! 781: { ! 782: char *rhs = av; ! 783: static char here[] = "dp_parse_argument"; ! 784: ! 785: /* Check for '-v' flag */ ! 786: ! 787: if (av[0] == '-' && av[1] == 'v' && av[2] == 0) { ! 788: verbose = TRUE ; ! 789: return TRUE; ! 790: } ! 791: ! 792: /* ! 793: * If we find a '=' followed by an argument in the string, ! 794: * check for known arguments ! 795: */ ! 796: while (*rhs && *rhs != '=') ! 797: rhs++; ! 798: if (*rhs && *++rhs) { ! 799: /* clsize=N pages */ ! 800: if (strprefix(av,"cl")) { ! 801: if (!bs_set_default_clsize(d_to_i(rhs))) ! 802: dprintf(("Bad argument (%s) - ignored\n", av)); ! 803: return(TRUE); ! 804: } ! 805: /* else if strprefix(av,"another_argument")) { ! 806: handle_another_argument(av); ! 807: return(TRUE); ! 808: } */ ! 809: } ! 810: return(FALSE); ! 811: } ! 812: ! 813: MACH_PORT_FACE default_pager_host_port = MACH_PORT_NULL; ! 814: ! 815: ! 816: int ! 817: start_def_pager(char *bs_device) ! 818: { ! 819: int my_node; ! 820: /* ! 821: MACH_PORT_FACE master_device_port; ! 822: */ ! 823: MACH_PORT_FACE security_port; ! 824: /* ! 825: MACH_PORT_FACE root_ledger_wired; ! 826: MACH_PORT_FACE root_ledger_paged; ! 827: */ ! 828: static char here[] = "main"; ! 829: int need_dp_init = 1; ! 830: ! 831: ! 832: ! 833: default_pager_host_port = ipc_port_make_send(realhost.host_priv_self); ! 834: /* ! 835: master_device_port = ipc_port_make_send(master_device_port); ! 836: root_ledger_wired = ipc_port_make_send(root_wired_ledger_port); ! 837: root_ledger_paged = ipc_port_make_send(root_paged_ledger_port); ! 838: */ ! 839: security_port = ipc_port_make_send(realhost.host_security_self); ! 840: ! 841: ! 842: #if NORMA_VM ! 843: norma_mk = 1; ! 844: #else ! 845: norma_mk = 0; ! 846: #endif ! 847: ! 848: ! 849: /* setup read buffers, etc */ ! 850: default_pager_initialize(default_pager_host_port); ! 851: default_pager(); ! 852: } ! 853: ! 854: /* ! 855: * Return TRUE if string 2 is a prefix of string 1. ! 856: */ ! 857: boolean_t ! 858: strprefix(register const char *s1, register const char *s2) ! 859: { ! 860: register int c; ! 861: ! 862: while ((c = *s2++) != '\0') { ! 863: if (c != *s1++) ! 864: return (FALSE); ! 865: } ! 866: return (TRUE); ! 867: } ! 868: ! 869: ! 870: kern_return_t ! 871: default_pager_info( ! 872: MACH_PORT_FACE pager, ! 873: default_pager_info_t *infop) ! 874: { ! 875: vm_size_t pages_total, pages_free; ! 876: ! 877: if (pager != default_pager_default_port) ! 878: return KERN_INVALID_ARGUMENT; ! 879: ! 880: bs_global_info(&pages_total, &pages_free); ! 881: ! 882: infop->dpi_total_space = ptoa(pages_total); ! 883: infop->dpi_free_space = ptoa(pages_free); ! 884: infop->dpi_page_size = vm_page_size; ! 885: ! 886: return KERN_SUCCESS; ! 887: } ! 888: ! 889: ! 890: void ! 891: default_pager_initialize( ! 892: MACH_PORT_FACE host_port) ! 893: { ! 894: kern_return_t kr; ! 895: static char here[] = "default_pager_initialize"; ! 896: ! 897: ! 898: /* ! 899: * Exported DMM port. ! 900: */ ! 901: default_pager_default_port = ipc_port_alloc_kernel(); ! 902: ! 903: ! 904: /* ! 905: * Export pager interfaces. ! 906: */ ! 907: #ifdef USER_PAGER ! 908: if ((kr = netname_check_in(name_server_port, "UserPager", ! 909: default_pager_self, ! 910: default_pager_default_port)) ! 911: != KERN_SUCCESS) { ! 912: dprintf(("netname_check_in returned 0x%x\n", kr)); ! 913: exit(1); ! 914: } ! 915: #else /* USER_PAGER */ ! 916: { ! 917: int clsize; ! 918: ipc_port_t DMM; ! 919: ! 920: DMM = ipc_port_make_send(default_pager_default_port); ! 921: clsize = (vm_page_size << vstruct_def_clshift); ! 922: kr = host_default_memory_manager(host_port, &DMM, clsize); ! 923: if ((kr != KERN_SUCCESS) || (DMM != MACH_PORT_NULL)) ! 924: Panic("default memory manager"); ! 925: ! 926: } ! 927: #endif /* USER_PAGER */ ! 928: ! 929: ! 930: /* ! 931: * Vm variables. ! 932: */ ! 933: vm_page_mask = vm_page_size - 1; ! 934: vm_page_shift = local_log2(vm_page_size); ! 935: ! 936: /* ! 937: * List of all vstructs. ! 938: */ ! 939: VSL_LOCK_INIT(); ! 940: queue_init(&vstruct_list.vsl_queue); ! 941: queue_init(&vstruct_list.vsl_leak_queue); ! 942: vstruct_list.vsl_count = 0; ! 943: ! 944: VSTATS_LOCK_INIT(&global_stats.gs_lock); ! 945: ! 946: bs_initialize(); ! 947: } ! 948:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.