vm_glue.c (dd106ca74239cc01c195cebf818fa771a80d64ea) | vm_glue.c (675878e7326918678a032a023ba6f6ee6029d59a) |
---|---|
1/* 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * The Mach Operating System project at Carnegie-Mellon University. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 45 unchanged lines hidden (view full) --- 54 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 55 * School of Computer Science 56 * Carnegie Mellon University 57 * Pittsburgh PA 15213-3890 58 * 59 * any improvements or extensions that they make and grant Carnegie the 60 * rights to redistribute these changes. 61 * | 1/* 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * The Mach Operating System project at Carnegie-Mellon University. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 45 unchanged lines hidden (view full) --- 54 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 55 * School of Computer Science 56 * Carnegie Mellon University 57 * Pittsburgh PA 15213-3890 58 * 59 * any improvements or extensions that they make and grant Carnegie the 60 * rights to redistribute these changes. 61 * |
62 * $Id: vm_glue.c,v 1.52 1996/07/02 02:07:56 dyson Exp $ | 62 * $Id: vm_glue.c,v 1.53 1996/09/15 11:24:21 bde Exp $ |
63 */ 64 65#include <sys/param.h> 66#include <sys/systm.h> 67#include <sys/proc.h> 68#include <sys/resourcevar.h> 69#include <sys/buf.h> 70#include <sys/shm.h> --- 129 unchanged lines hidden (view full) --- 200 VM_WAIT; 201 } 202 203 p2->p_vmspace = vmspace_fork(p1->p_vmspace); 204 205 if (p1->p_vmspace->vm_shm) 206 shmfork(p1, p2); 207 | 63 */ 64 65#include <sys/param.h> 66#include <sys/systm.h> 67#include <sys/proc.h> 68#include <sys/resourcevar.h> 69#include <sys/buf.h> 70#include <sys/shm.h> --- 129 unchanged lines hidden (view full) --- 200 VM_WAIT; 201 } 202 203 p2->p_vmspace = vmspace_fork(p1->p_vmspace); 204 205 if (p1->p_vmspace->vm_shm) 206 shmfork(p1, p2); 207 |
208 /* 209 * Allocate a wired-down (for now) pcb and kernel stack for the 210 * process 211 */ | 208 pmap_new_proc(p2); |
212 | 209 |
213 pvp = &p2->p_vmspace->vm_pmap; | 210 up = p2->p_addr; |
214 215 /* | 211 212 /* |
216 * allocate object for the upages 217 */ 218 p2->p_vmspace->vm_upages_obj = upobj = vm_object_allocate( OBJT_DEFAULT, 219 UPAGES); 220 221 /* get a kernel virtual address for the UPAGES for this proc */ 222 up = (struct user *) kmem_alloc_pageable(u_map, UPAGES * PAGE_SIZE); 223 if (up == NULL) 224 panic("vm_fork: u_map allocation failed"); 225 226 for(i=0;i<UPAGES;i++) { 227 vm_page_t m; 228 229 /* 230 * Get a kernel stack page 231 */ 232 while ((m = vm_page_alloc(upobj, 233 i, VM_ALLOC_NORMAL)) == NULL) { 234 VM_WAIT; 235 } 236 237 /* 238 * Wire the page 239 */ 240 vm_page_wire(m); 241 PAGE_WAKEUP(m); 242 243 /* 244 * Enter the page into both the kernel and the process 245 * address space. 246 */ 247 pmap_enter( pvp, (vm_offset_t) kstack + i * PAGE_SIZE, 248 VM_PAGE_TO_PHYS(m), VM_PROT_READ|VM_PROT_WRITE, TRUE); 249 pmap_kenter(((vm_offset_t) up) + i * PAGE_SIZE, 250 VM_PAGE_TO_PHYS(m)); 251 m->flags &= ~PG_ZERO; 252 m->flags |= PG_MAPPED|PG_WRITEABLE; 253 m->valid = VM_PAGE_BITS_ALL; 254 } 255 256 p2->p_addr = up; 257 258 /* | |
259 * p_stats and p_sigacts currently point at fields in the user struct 260 * but not at &u, instead at p_addr. Copy p_sigacts and parts of 261 * p_stats; zero the rest of p_stats (statistics). 262 */ 263 p2->p_stats = &up->u_stats; 264 p2->p_sigacts = &up->u_sigacts; 265 up->u_sigacts = *p1->p_sigacts; 266 bzero(&up->u_stats.pstat_startzero, --- 46 unchanged lines hidden (view full) --- 313void 314faultin(p) 315 struct proc *p; 316{ 317 vm_offset_t i; 318 int s; 319 320 if ((p->p_flag & P_INMEM) == 0) { | 213 * p_stats and p_sigacts currently point at fields in the user struct 214 * but not at &u, instead at p_addr. Copy p_sigacts and parts of 215 * p_stats; zero the rest of p_stats (statistics). 216 */ 217 p2->p_stats = &up->u_stats; 218 p2->p_sigacts = &up->u_sigacts; 219 up->u_sigacts = *p1->p_sigacts; 220 bzero(&up->u_stats.pstat_startzero, --- 46 unchanged lines hidden (view full) --- 267void 268faultin(p) 269 struct proc *p; 270{ 271 vm_offset_t i; 272 int s; 273 274 if ((p->p_flag & P_INMEM) == 0) { |
321 pmap_t pmap = &p->p_vmspace->vm_pmap; 322 vm_page_t m; 323 vm_object_t upobj = p->p_vmspace->vm_upages_obj; | |
324 325 ++p->p_lock; | 275 276 ++p->p_lock; |
326#if defined(SWAP_DEBUG) 327 printf("swapping in %d\n", p->p_pid); 328#endif | |
329 | 277 |
330 for(i=0;i<UPAGES;i++) { 331 int s; 332 s = splvm(); 333retry: 334 if ((m = vm_page_lookup(upobj, i)) == NULL) { 335 if ((m = vm_page_alloc(upobj, i, VM_ALLOC_NORMAL)) == NULL) { 336 VM_WAIT; 337 goto retry; 338 } 339 } else { 340 if ((m->flags & PG_BUSY) || m->busy) { 341 m->flags |= PG_WANTED; 342 tsleep(m, PVM, "swinuw",0); 343 goto retry; 344 } 345 m->flags |= PG_BUSY; 346 } 347 vm_page_wire(m); 348 splx(s); | 278 pmap_swapin_proc(p); |
349 | 279 |
350 pmap_enter( pmap, (vm_offset_t) kstack + i * PAGE_SIZE, 351 VM_PAGE_TO_PHYS(m), VM_PROT_READ|VM_PROT_WRITE, TRUE); 352 pmap_kenter(((vm_offset_t) p->p_addr) + i * PAGE_SIZE, 353 VM_PAGE_TO_PHYS(m)); 354 if (m->valid != VM_PAGE_BITS_ALL) { 355 int rv; 356 rv = vm_pager_get_pages(upobj, 357 &m, 1, 0); 358 if (rv != VM_PAGER_OK) 359 panic("faultin: cannot get upages for proc: %d\n", p->p_pid); 360 m->valid = VM_PAGE_BITS_ALL; 361 } 362 PAGE_WAKEUP(m); 363 m->flags |= PG_MAPPED|PG_WRITEABLE; 364 } 365 | |
366 s = splhigh(); 367 368 if (p->p_stat == SRUN) 369 setrunqueue(p); 370 371 p->p_flag |= P_INMEM; 372 373 /* undo the effect of setting SLOCK above */ --- 162 unchanged lines hidden (view full) --- 536 537 (void) splhigh(); 538 p->p_flag &= ~P_INMEM; 539 p->p_flag |= P_SWAPPING; 540 if (p->p_stat == SRUN) 541 remrq(p); 542 (void) spl0(); 543 | 280 s = splhigh(); 281 282 if (p->p_stat == SRUN) 283 setrunqueue(p); 284 285 p->p_flag |= P_INMEM; 286 287 /* undo the effect of setting SLOCK above */ --- 162 unchanged lines hidden (view full) --- 450 451 (void) splhigh(); 452 p->p_flag &= ~P_INMEM; 453 p->p_flag |= P_SWAPPING; 454 if (p->p_stat == SRUN) 455 remrq(p); 456 (void) spl0(); 457 |
544 /* 545 * let the upages be paged 546 */ 547 for(i=0;i<UPAGES;i++) { 548 vm_page_t m; 549 if ((m = vm_page_lookup(p->p_vmspace->vm_upages_obj, i)) == NULL) 550 panic("swapout: upage already missing???"); 551 m->dirty = VM_PAGE_BITS_ALL; 552 vm_page_unwire(m); 553 vm_page_deactivate(m); 554 pmap_kremove( (vm_offset_t) p->p_addr + PAGE_SIZE * i); 555 } 556 pmap_remove(pmap, (vm_offset_t) kstack, 557 (vm_offset_t) kstack + PAGE_SIZE * UPAGES); | 458 pmap_swapout_proc(p); |
558 559 p->p_flag &= ~P_SWAPPING; 560 p->p_swtime = 0; 561} 562#endif /* !NO_SWAPPING */ | 459 460 p->p_flag &= ~P_SWAPPING; 461 p->p_swtime = 0; 462} 463#endif /* !NO_SWAPPING */ |