- Reduce kernel size by removing unnecessary pointer indirections.

GENERIC kernel size reduced in 16 bytes and RACCT kernel in 336 bytes.

Suggested by:	alc
Reviewed by:	alc
Approved by:	kib (mentor)
MFC after:	1 week
This commit is contained in:
Andrey Zonov 2013-01-10 12:43:58 +00:00
parent 1a71c5b935
commit 3ac7d29722
3 changed files with 17 additions and 19 deletions

View File

@ -3281,8 +3281,7 @@ vm_map_stack(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize,
} }
if (!old_mlock && map->flags & MAP_WIREFUTURE) { if (!old_mlock && map->flags & MAP_WIREFUTURE) {
if (ptoa(vmspace_wired_count(curproc->p_vmspace)) + if (ptoa(pmap_wired_count(map->pmap)) + init_ssize > lmemlim) {
init_ssize > lmemlim) {
vm_map_unlock(map); vm_map_unlock(map);
return (KERN_NO_SPACE); return (KERN_NO_SPACE);
} }
@ -3505,8 +3504,7 @@ vm_map_growstack(struct proc *p, vm_offset_t addr)
grow_amount = limit - ctob(vm->vm_ssize); grow_amount = limit - ctob(vm->vm_ssize);
#endif #endif
if (!old_mlock && map->flags & MAP_WIREFUTURE) { if (!old_mlock && map->flags & MAP_WIREFUTURE) {
if (ptoa(vmspace_wired_count(p->p_vmspace)) + grow_amount > if (ptoa(pmap_wired_count(map->pmap)) + grow_amount > lmemlim) {
lmemlim) {
vm_map_unlock_read(map); vm_map_unlock_read(map);
rv = KERN_NO_SPACE; rv = KERN_NO_SPACE;
goto out; goto out;
@ -3514,7 +3512,7 @@ vm_map_growstack(struct proc *p, vm_offset_t addr)
#ifdef RACCT #ifdef RACCT
PROC_LOCK(p); PROC_LOCK(p);
if (racct_set(p, RACCT_MEMLOCK, if (racct_set(p, RACCT_MEMLOCK,
ptoa(vmspace_wired_count(p->p_vmspace)) + grow_amount)) { ptoa(pmap_wired_count(map->pmap)) + grow_amount)) {
PROC_UNLOCK(p); PROC_UNLOCK(p);
vm_map_unlock_read(map); vm_map_unlock_read(map);
rv = KERN_NO_SPACE; rv = KERN_NO_SPACE;
@ -3645,7 +3643,7 @@ vm_map_growstack(struct proc *p, vm_offset_t addr)
KASSERT(error == 0, ("decreasing RACCT_VMEM failed")); KASSERT(error == 0, ("decreasing RACCT_VMEM failed"));
if (!old_mlock) { if (!old_mlock) {
error = racct_set(p, RACCT_MEMLOCK, error = racct_set(p, RACCT_MEMLOCK,
ptoa(vmspace_wired_count(p->p_vmspace))); ptoa(pmap_wired_count(map->pmap)));
KASSERT(error == 0, ("decreasing RACCT_MEMLOCK failed")); KASSERT(error == 0, ("decreasing RACCT_MEMLOCK failed"));
} }
error = racct_set(p, RACCT_STACK, ctob(vm->vm_ssize)); error = racct_set(p, RACCT_STACK, ctob(vm->vm_ssize));

View File

@ -1038,6 +1038,7 @@ sys_mlock(td, uap)
struct proc *proc; struct proc *proc;
vm_offset_t addr, end, last, start; vm_offset_t addr, end, last, start;
vm_size_t npages, size; vm_size_t npages, size;
vm_map_t map;
unsigned long nsize; unsigned long nsize;
int error; int error;
@ -1055,8 +1056,9 @@ sys_mlock(td, uap)
if (npages > vm_page_max_wired) if (npages > vm_page_max_wired)
return (ENOMEM); return (ENOMEM);
proc = td->td_proc; proc = td->td_proc;
map = &proc->p_vmspace->vm_map;
PROC_LOCK(proc); PROC_LOCK(proc);
nsize = ptoa(npages + vmspace_wired_count(proc->p_vmspace)); nsize = ptoa(npages + pmap_wired_count(map->pmap));
if (nsize > lim_cur(proc, RLIMIT_MEMLOCK)) { if (nsize > lim_cur(proc, RLIMIT_MEMLOCK)) {
PROC_UNLOCK(proc); PROC_UNLOCK(proc);
return (ENOMEM); return (ENOMEM);
@ -1071,13 +1073,13 @@ sys_mlock(td, uap)
if (error != 0) if (error != 0)
return (ENOMEM); return (ENOMEM);
#endif #endif
error = vm_map_wire(&proc->p_vmspace->vm_map, start, end, error = vm_map_wire(map, start, end,
VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES); VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES);
#ifdef RACCT #ifdef RACCT
if (error != KERN_SUCCESS) { if (error != KERN_SUCCESS) {
PROC_LOCK(proc); PROC_LOCK(proc);
racct_set(proc, RACCT_MEMLOCK, racct_set(proc, RACCT_MEMLOCK,
ptoa(vmspace_wired_count(proc->p_vmspace))); ptoa(pmap_wired_count(map->pmap)));
PROC_UNLOCK(proc); PROC_UNLOCK(proc);
} }
#endif #endif
@ -1151,7 +1153,7 @@ sys_mlockall(td, uap)
if (error != KERN_SUCCESS) { if (error != KERN_SUCCESS) {
PROC_LOCK(td->td_proc); PROC_LOCK(td->td_proc);
racct_set(td->td_proc, RACCT_MEMLOCK, racct_set(td->td_proc, RACCT_MEMLOCK,
ptoa(vmspace_wired_count(td->td_proc->p_vmspace))); ptoa(pmap_wired_count(map->pmap)));
PROC_UNLOCK(td->td_proc); PROC_UNLOCK(td->td_proc);
} }
#endif #endif
@ -1485,16 +1487,15 @@ vm_mmap(vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot,
return (ENOMEM); return (ENOMEM);
} }
if (!old_mlock && map->flags & MAP_WIREFUTURE) { if (!old_mlock && map->flags & MAP_WIREFUTURE) {
if (ptoa(vmspace_wired_count(td->td_proc->p_vmspace)) + if (ptoa(pmap_wired_count(map->pmap)) + size >
size > lim_cur(td->td_proc, RLIMIT_MEMLOCK)) { lim_cur(td->td_proc, RLIMIT_MEMLOCK)) {
racct_set_force(td->td_proc, RACCT_VMEM, racct_set_force(td->td_proc, RACCT_VMEM,
map->size); map->size);
PROC_UNLOCK(td->td_proc); PROC_UNLOCK(td->td_proc);
return (ENOMEM); return (ENOMEM);
} }
error = racct_set(td->td_proc, RACCT_MEMLOCK, error = racct_set(td->td_proc, RACCT_MEMLOCK,
ptoa(vmspace_wired_count(td->td_proc->p_vmspace)) + ptoa(pmap_wired_count(map->pmap)) + size);
size);
if (error != 0) { if (error != 0) {
racct_set_force(td->td_proc, RACCT_VMEM, racct_set_force(td->td_proc, RACCT_VMEM,
map->size); map->size);

View File

@ -118,7 +118,7 @@ sys_obreak(td, uap)
} }
if (new > old) { if (new > old) {
if (!old_mlock && vm->vm_map.flags & MAP_WIREFUTURE) { if (!old_mlock && vm->vm_map.flags & MAP_WIREFUTURE) {
if (ptoa(vmspace_wired_count(td->td_proc->p_vmspace)) + if (ptoa(pmap_wired_count(vm->vm_map.pmap)) +
(new - old) > lmemlim) { (new - old) > lmemlim) {
error = ENOMEM; error = ENOMEM;
goto done; goto done;
@ -146,7 +146,7 @@ sys_obreak(td, uap)
} }
if (!old_mlock && vm->vm_map.flags & MAP_WIREFUTURE) { if (!old_mlock && vm->vm_map.flags & MAP_WIREFUTURE) {
error = racct_set(td->td_proc, RACCT_MEMLOCK, error = racct_set(td->td_proc, RACCT_MEMLOCK,
ptoa(vmspace_wired_count(td->td_proc->p_vmspace)) + ptoa(pmap_wired_count(vm->vm_map.pmap)) +
(new - old)); (new - old));
if (error != 0) { if (error != 0) {
racct_set_force(td->td_proc, RACCT_DATA, racct_set_force(td->td_proc, RACCT_DATA,
@ -176,8 +176,7 @@ sys_obreak(td, uap)
racct_set_force(td->td_proc, RACCT_VMEM, vm->vm_map.size); racct_set_force(td->td_proc, RACCT_VMEM, vm->vm_map.size);
if (!old_mlock && vm->vm_map.flags & MAP_WIREFUTURE) { if (!old_mlock && vm->vm_map.flags & MAP_WIREFUTURE) {
racct_set_force(td->td_proc, RACCT_MEMLOCK, racct_set_force(td->td_proc, RACCT_MEMLOCK,
ptoa(vmspace_wired_count( ptoa(pmap_wired_count(vm->vm_map.pmap)));
td->td_proc->p_vmspace)));
} }
PROC_UNLOCK(td->td_proc); PROC_UNLOCK(td->td_proc);
#endif #endif
@ -212,7 +211,7 @@ sys_obreak(td, uap)
racct_set_force(td->td_proc, RACCT_VMEM, vm->vm_map.size); racct_set_force(td->td_proc, RACCT_VMEM, vm->vm_map.size);
if (!old_mlock && vm->vm_map.flags & MAP_WIREFUTURE) { if (!old_mlock && vm->vm_map.flags & MAP_WIREFUTURE) {
racct_set_force(td->td_proc, RACCT_MEMLOCK, racct_set_force(td->td_proc, RACCT_MEMLOCK,
ptoa(vmspace_wired_count(td->td_proc->p_vmspace))); ptoa(pmap_wired_count(vm->vm_map.pmap)));
} }
PROC_UNLOCK(td->td_proc); PROC_UNLOCK(td->td_proc);
#endif #endif