1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/*
* Copyright (c) 1996, 1998, 1999 University of Utah and the Flux Group.
* All rights reserved.
*
* This file is part of the Flux OSKit. The OSKit is free software, also known
* as "open source;" you can redistribute it and/or modify it under the terms
* of the GNU General Public License (GPL), version 2, as published by the Free
* Software Foundation (FSF). To explore alternate licensing terms, contact
* the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
*
* The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have
* received a copy of the GPL along with the OSKit; see the file COPYING. If
* not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
*/
/*
* Notes:
*
* What about locking and other issues of execution environments.
*
* I'm not using superpages at all. That complicates things 'cause anytime
* an application wants to modify a page in a superpage, the entire superpage
* has to be broken up into invidual pages. Too nasty for a first draft.
*
* Unused memory cannot be protected since the lmm requires write
* access to the pages to maintain the free lists. Besides, there is
* no telling what memory the kernel will access. This means the applicaton
* can write anything it wants to, except non-existent memory.
*
* I am allowing just READ and READ/WRITE prots. PROT_NONE is not
* allowed.
*
* Should morecore be redefined so that memory shortages in the malloc pool
* are handled properly?
*
* Pages are read and written to/from the swap area through the virtual
* address.
*/
/*
* Things to possibly do:
*
* 1) External pager interface. Add export of policy for selecting pages
* to aid in discardable page.
*
* 2) Provide support for specifying discardable pages (SML paper) and
* a way to flush disardable pages from the system.
*
* 3) In the threads world, use a thread for a simple pageout daemon.
*/
#include "svm_internal.h"
/*
* Use the AMM to track virtual mappings.
*/
amm_t svm_amm;
/*
* Application level SEGV handler for page faults.
*/
int (*svm_segv_handler)(oskit_addr_t la, int rw);
/*
* Enabled?
*/
int svm_enabled = 0;
/*
* Thread safe locking.
*/
oskit_lock_t *svm_lock = 0;
/*
* The VM region starts after the end of physical memory, and extends
* as far as possible.
*/
void
svm_init(oskit_absio_t *pager_absio)
{
oskit_lock_mgr_t *lock_mgr;
if (svm_enabled)
return;
/*
* Machine dependent initialization.
*/
svm_machdep_init();
/*
* This turns on paging!
*/
base_paging_load();
/*
* Initialize the stuff for catching stack overflow.
*/
svm_redzone_init();
/*
* See if thread-safe locks are required.
*/
if (oskit_lookup_first(&oskit_lock_mgr_iid, (void *) &lock_mgr))
panic("svm_init: oskit_lookup_first");
if (lock_mgr) {
if (oskit_lock_mgr_allocate_lock(lock_mgr, &svm_lock))
panic("svm_init: oskit_lock_mgr_allocate_lock");
}
/*
* XXX: Must turn this on before starting the pager. See mem.c
*/
svm_enabled = 1;
/*
* Initialize the pager if requested.
*/
if (pager_absio) {
if (svm_pager_init(pager_absio))
panic("svm_init: Could init the pager!\n");
}
/*
* Hook in a new page fault handler.
*/
base_trap_handlers[T_PAGE_FAULT] = svm_page_fault_handler;
/*
* and initialize the application level handler to null so
* that the default is to send a SIGSEGV to the application.
*/
svm_segv_handler = 0;
}
void
svm_shutdown()
{
extern int svm_pagein_count, svm_pageout_count;
extern int svm_pagein_time, svm_pageout_time;
extern int svm_swapread_time, svm_swapwrite_time;
extern int svm_swapwrite_count, svm_swapread_count;
printf("svm_shutdown: swapread count: %d pages. time %d\n"
" swapwrite count: %d pages. time %d\n",
svm_swapread_count, svm_swapread_time,
svm_swapwrite_count, svm_swapwrite_time);
printf("svm_shutdown: pagein count: %d pages. time %d\n"
" pageout count: %d pages. time %d\n",
svm_pagein_count, svm_pagein_time,
svm_pageout_count, svm_pageout_time);
}
|