vm_map.c (223677) | vm_map.c (223825) |
---|---|
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 --- 49 unchanged lines hidden (view full) --- 58 * rights to redistribute these changes. 59 */ 60 61/* 62 * Virtual memory mapping module. 63 */ 64 65#include <sys/cdefs.h> | 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 --- 49 unchanged lines hidden (view full) --- 58 * rights to redistribute these changes. 59 */ 60 61/* 62 * Virtual memory mapping module. 63 */ 64 65#include <sys/cdefs.h> |
66__FBSDID("$FreeBSD: head/sys/vm/vm_map.c 223677 2011-06-29 16:40:41Z alc $"); | 66__FBSDID("$FreeBSD: head/sys/vm/vm_map.c 223825 2011-07-06 20:06:44Z trasz $"); |
67 68#include <sys/param.h> 69#include <sys/systm.h> 70#include <sys/kernel.h> 71#include <sys/ktr.h> 72#include <sys/lock.h> 73#include <sys/mutex.h> 74#include <sys/proc.h> --- 238 unchanged lines hidden (view full) --- 313#endif 314 vmspace_zinit, vmspace_zfini, UMA_ALIGN_PTR, UMA_ZONE_NOFREE); 315} 316 317static void 318vmspace_container_reset(struct proc *p) 319{ 320 | 67 68#include <sys/param.h> 69#include <sys/systm.h> 70#include <sys/kernel.h> 71#include <sys/ktr.h> 72#include <sys/lock.h> 73#include <sys/mutex.h> 74#include <sys/proc.h> --- 238 unchanged lines hidden (view full) --- 313#endif 314 vmspace_zinit, vmspace_zfini, UMA_ALIGN_PTR, UMA_ZONE_NOFREE); 315} 316 317static void 318vmspace_container_reset(struct proc *p) 319{ 320 |
321#ifdef RACCT |
|
321 PROC_LOCK(p); 322 racct_set(p, RACCT_DATA, 0); 323 racct_set(p, RACCT_STACK, 0); 324 racct_set(p, RACCT_RSS, 0); 325 racct_set(p, RACCT_MEMLOCK, 0); 326 racct_set(p, RACCT_VMEM, 0); 327 PROC_UNLOCK(p); | 322 PROC_LOCK(p); 323 racct_set(p, RACCT_DATA, 0); 324 racct_set(p, RACCT_STACK, 0); 325 racct_set(p, RACCT_RSS, 0); 326 racct_set(p, RACCT_MEMLOCK, 0); 327 racct_set(p, RACCT_VMEM, 0); 328 PROC_UNLOCK(p); |
329#endif |
|
328} 329 330static inline void 331vmspace_dofree(struct vmspace *vm) 332{ 333 334 CTR1(KTR_VM, "vmspace_free: %p", vm); 335 --- 2964 unchanged lines hidden (view full) --- 3300 vm_offset_t end; 3301 size_t grow_amount, max_grow; 3302 rlim_t stacklim, vmemlim; 3303 int is_procstack, rv; 3304 struct ucred *cred; 3305#ifdef notyet 3306 uint64_t limit; 3307#endif | 330} 331 332static inline void 333vmspace_dofree(struct vmspace *vm) 334{ 335 336 CTR1(KTR_VM, "vmspace_free: %p", vm); 337 --- 2964 unchanged lines hidden (view full) --- 3302 vm_offset_t end; 3303 size_t grow_amount, max_grow; 3304 rlim_t stacklim, vmemlim; 3305 int is_procstack, rv; 3306 struct ucred *cred; 3307#ifdef notyet 3308 uint64_t limit; 3309#endif |
3310#ifdef RACCT |
|
3308 int error; | 3311 int error; |
3312#endif |
|
3309 3310Retry: 3311 PROC_LOCK(p); 3312 stacklim = lim_cur(p, RLIMIT_STACK); 3313 vmemlim = lim_cur(p, RLIMIT_VMEM); 3314 PROC_UNLOCK(p); 3315 3316 vm_map_lock_read(map); --- 82 unchanged lines hidden (view full) --- 3399 /* 3400 * If this is the main process stack, see if we're over the stack 3401 * limit. 3402 */ 3403 if (is_procstack && (ctob(vm->vm_ssize) + grow_amount > stacklim)) { 3404 vm_map_unlock_read(map); 3405 return (KERN_NO_SPACE); 3406 } | 3313 3314Retry: 3315 PROC_LOCK(p); 3316 stacklim = lim_cur(p, RLIMIT_STACK); 3317 vmemlim = lim_cur(p, RLIMIT_VMEM); 3318 PROC_UNLOCK(p); 3319 3320 vm_map_lock_read(map); --- 82 unchanged lines hidden (view full) --- 3403 /* 3404 * If this is the main process stack, see if we're over the stack 3405 * limit. 3406 */ 3407 if (is_procstack && (ctob(vm->vm_ssize) + grow_amount > stacklim)) { 3408 vm_map_unlock_read(map); 3409 return (KERN_NO_SPACE); 3410 } |
3411#ifdef RACCT |
|
3407 PROC_LOCK(p); 3408 if (is_procstack && 3409 racct_set(p, RACCT_STACK, ctob(vm->vm_ssize) + grow_amount)) { 3410 PROC_UNLOCK(p); 3411 vm_map_unlock_read(map); 3412 return (KERN_NO_SPACE); 3413 } 3414 PROC_UNLOCK(p); | 3412 PROC_LOCK(p); 3413 if (is_procstack && 3414 racct_set(p, RACCT_STACK, ctob(vm->vm_ssize) + grow_amount)) { 3415 PROC_UNLOCK(p); 3416 vm_map_unlock_read(map); 3417 return (KERN_NO_SPACE); 3418 } 3419 PROC_UNLOCK(p); |
3420#endif |
|
3415 3416 /* Round up the grow amount modulo SGROWSIZ */ 3417 grow_amount = roundup (grow_amount, sgrowsiz); 3418 if (grow_amount > stack_entry->avail_ssize) 3419 grow_amount = stack_entry->avail_ssize; 3420 if (is_procstack && (ctob(vm->vm_ssize) + grow_amount > stacklim)) { 3421 grow_amount = trunc_page((vm_size_t)stacklim) - 3422 ctob(vm->vm_ssize); --- 7 unchanged lines hidden (view full) --- 3430#endif 3431 3432 /* If we would blow our VMEM resource limit, no go */ 3433 if (map->size + grow_amount > vmemlim) { 3434 vm_map_unlock_read(map); 3435 rv = KERN_NO_SPACE; 3436 goto out; 3437 } | 3421 3422 /* Round up the grow amount modulo SGROWSIZ */ 3423 grow_amount = roundup (grow_amount, sgrowsiz); 3424 if (grow_amount > stack_entry->avail_ssize) 3425 grow_amount = stack_entry->avail_ssize; 3426 if (is_procstack && (ctob(vm->vm_ssize) + grow_amount > stacklim)) { 3427 grow_amount = trunc_page((vm_size_t)stacklim) - 3428 ctob(vm->vm_ssize); --- 7 unchanged lines hidden (view full) --- 3436#endif 3437 3438 /* If we would blow our VMEM resource limit, no go */ 3439 if (map->size + grow_amount > vmemlim) { 3440 vm_map_unlock_read(map); 3441 rv = KERN_NO_SPACE; 3442 goto out; 3443 } |
3444#ifdef RACCT |
|
3438 PROC_LOCK(p); 3439 if (racct_set(p, RACCT_VMEM, map->size + grow_amount)) { 3440 PROC_UNLOCK(p); 3441 vm_map_unlock_read(map); 3442 rv = KERN_NO_SPACE; 3443 goto out; 3444 } 3445 PROC_UNLOCK(p); | 3445 PROC_LOCK(p); 3446 if (racct_set(p, RACCT_VMEM, map->size + grow_amount)) { 3447 PROC_UNLOCK(p); 3448 vm_map_unlock_read(map); 3449 rv = KERN_NO_SPACE; 3450 goto out; 3451 } 3452 PROC_UNLOCK(p); |
3453#endif |
|
3446 3447 if (vm_map_lock_upgrade(map)) 3448 goto Retry; 3449 3450 if (stack_entry == next_entry) { 3451 /* 3452 * Growing downward. 3453 */ --- 83 unchanged lines hidden (view full) --- 3537 (stack_entry == next_entry) ? addr : addr - grow_amount, 3538 (stack_entry == next_entry) ? stack_entry->start : addr, 3539 (p->p_flag & P_SYSTEM) 3540 ? VM_MAP_WIRE_SYSTEM|VM_MAP_WIRE_NOHOLES 3541 : VM_MAP_WIRE_USER|VM_MAP_WIRE_NOHOLES); 3542 } 3543 3544out: | 3454 3455 if (vm_map_lock_upgrade(map)) 3456 goto Retry; 3457 3458 if (stack_entry == next_entry) { 3459 /* 3460 * Growing downward. 3461 */ --- 83 unchanged lines hidden (view full) --- 3545 (stack_entry == next_entry) ? addr : addr - grow_amount, 3546 (stack_entry == next_entry) ? stack_entry->start : addr, 3547 (p->p_flag & P_SYSTEM) 3548 ? VM_MAP_WIRE_SYSTEM|VM_MAP_WIRE_NOHOLES 3549 : VM_MAP_WIRE_USER|VM_MAP_WIRE_NOHOLES); 3550 } 3551 3552out: |
3553#ifdef RACCT |
|
3545 if (rv != KERN_SUCCESS) { 3546 PROC_LOCK(p); 3547 error = racct_set(p, RACCT_VMEM, map->size); 3548 KASSERT(error == 0, ("decreasing RACCT_VMEM failed")); 3549 error = racct_set(p, RACCT_STACK, ctob(vm->vm_ssize)); 3550 KASSERT(error == 0, ("decreasing RACCT_STACK failed")); 3551 PROC_UNLOCK(p); 3552 } | 3554 if (rv != KERN_SUCCESS) { 3555 PROC_LOCK(p); 3556 error = racct_set(p, RACCT_VMEM, map->size); 3557 KASSERT(error == 0, ("decreasing RACCT_VMEM failed")); 3558 error = racct_set(p, RACCT_STACK, ctob(vm->vm_ssize)); 3559 KASSERT(error == 0, ("decreasing RACCT_STACK failed")); 3560 PROC_UNLOCK(p); 3561 } |
3562#endif |
|
3553 3554 return (rv); 3555} 3556 3557/* 3558 * Unshare the specified VM space for exec. If other processes are 3559 * mapped to it, then create a new one. The new vmspace is null. 3560 */ --- 450 unchanged lines hidden --- | 3563 3564 return (rv); 3565} 3566 3567/* 3568 * Unshare the specified VM space for exec. If other processes are 3569 * mapped to it, then create a new one. The new vmspace is null. 3570 */ --- 450 unchanged lines hidden --- |