Deleted Added
full compact
vm_mmap.c (220373) vm_mmap.c (223825)
1/*-
2 * Copyright (c) 1988 University of Utah.
3 * Copyright (c) 1991, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * the Systems Programming Group of the University of Utah Computer
8 * Science Department.

--- 27 unchanged lines hidden (view full) ---

36 * @(#)vm_mmap.c 8.4 (Berkeley) 1/12/94
37 */
38
39/*
40 * Mapped file (mmap) interface to VM
41 */
42
43#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1988 University of Utah.
3 * Copyright (c) 1991, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * the Systems Programming Group of the University of Utah Computer
8 * Science Department.

--- 27 unchanged lines hidden (view full) ---

36 * @(#)vm_mmap.c 8.4 (Berkeley) 1/12/94
37 */
38
39/*
40 * Mapped file (mmap) interface to VM
41 */
42
43#include <sys/cdefs.h>
44__FBSDID("$FreeBSD: head/sys/vm/vm_mmap.c 220373 2011-04-05 20:23:59Z trasz $");
44__FBSDID("$FreeBSD: head/sys/vm/vm_mmap.c 223825 2011-07-06 20:06:44Z trasz $");
45
46#include "opt_compat.h"
47#include "opt_hwpmc_hooks.h"
48
49#include <sys/param.h>
50#include <sys/systm.h>
51#include <sys/lock.h>
52#include <sys/mutex.h>

--- 961 unchanged lines hidden (view full) ---

1014 pmap_wired_count(vm_map_pmap(&proc->p_vmspace->vm_map)));
1015 if (nsize > lim_cur(proc, RLIMIT_MEMLOCK)) {
1016 PROC_UNLOCK(proc);
1017 return (ENOMEM);
1018 }
1019 PROC_UNLOCK(proc);
1020 if (npages + cnt.v_wire_count > vm_page_max_wired)
1021 return (EAGAIN);
45
46#include "opt_compat.h"
47#include "opt_hwpmc_hooks.h"
48
49#include <sys/param.h>
50#include <sys/systm.h>
51#include <sys/lock.h>
52#include <sys/mutex.h>

--- 961 unchanged lines hidden (view full) ---

1014 pmap_wired_count(vm_map_pmap(&proc->p_vmspace->vm_map)));
1015 if (nsize > lim_cur(proc, RLIMIT_MEMLOCK)) {
1016 PROC_UNLOCK(proc);
1017 return (ENOMEM);
1018 }
1019 PROC_UNLOCK(proc);
1020 if (npages + cnt.v_wire_count > vm_page_max_wired)
1021 return (EAGAIN);
1022#ifdef RACCT
1022 PROC_LOCK(proc);
1023 error = racct_set(proc, RACCT_MEMLOCK, nsize);
1024 PROC_UNLOCK(proc);
1025 if (error != 0)
1026 return (ENOMEM);
1023 PROC_LOCK(proc);
1024 error = racct_set(proc, RACCT_MEMLOCK, nsize);
1025 PROC_UNLOCK(proc);
1026 if (error != 0)
1027 return (ENOMEM);
1028#endif
1027 error = vm_map_wire(&proc->p_vmspace->vm_map, start, end,
1028 VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES);
1029 error = vm_map_wire(&proc->p_vmspace->vm_map, start, end,
1030 VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES);
1031#ifdef RACCT
1029 if (error != KERN_SUCCESS) {
1030 PROC_LOCK(proc);
1031 racct_set(proc, RACCT_MEMLOCK,
1032 ptoa(pmap_wired_count(vm_map_pmap(&proc->p_vmspace->vm_map))));
1033 PROC_UNLOCK(proc);
1034 }
1032 if (error != KERN_SUCCESS) {
1033 PROC_LOCK(proc);
1034 racct_set(proc, RACCT_MEMLOCK,
1035 ptoa(pmap_wired_count(vm_map_pmap(&proc->p_vmspace->vm_map))));
1036 PROC_UNLOCK(proc);
1037 }
1038#endif
1035 return (error == KERN_SUCCESS ? 0 : ENOMEM);
1036}
1037
1038#ifndef _SYS_SYSPROTO_H_
1039struct mlockall_args {
1040 int how;
1041};
1042#endif

--- 26 unchanged lines hidden (view full) ---

1069 return (ENOMEM);
1070 }
1071 PROC_UNLOCK(td->td_proc);
1072#else
1073 error = priv_check(td, PRIV_VM_MLOCK);
1074 if (error)
1075 return (error);
1076#endif
1039 return (error == KERN_SUCCESS ? 0 : ENOMEM);
1040}
1041
1042#ifndef _SYS_SYSPROTO_H_
1043struct mlockall_args {
1044 int how;
1045};
1046#endif

--- 26 unchanged lines hidden (view full) ---

1073 return (ENOMEM);
1074 }
1075 PROC_UNLOCK(td->td_proc);
1076#else
1077 error = priv_check(td, PRIV_VM_MLOCK);
1078 if (error)
1079 return (error);
1080#endif
1081#ifdef RACCT
1077 PROC_LOCK(td->td_proc);
1078 error = racct_set(td->td_proc, RACCT_MEMLOCK, map->size);
1079 PROC_UNLOCK(td->td_proc);
1080 if (error != 0)
1081 return (ENOMEM);
1082 PROC_LOCK(td->td_proc);
1083 error = racct_set(td->td_proc, RACCT_MEMLOCK, map->size);
1084 PROC_UNLOCK(td->td_proc);
1085 if (error != 0)
1086 return (ENOMEM);
1087#endif
1082
1083 if (uap->how & MCL_FUTURE) {
1084 vm_map_lock(map);
1085 vm_map_modflags(map, MAP_WIREFUTURE, 0);
1086 vm_map_unlock(map);
1087 error = 0;
1088 }
1089
1090 if (uap->how & MCL_CURRENT) {
1091 /*
1092 * P1003.1-2001 mandates that all currently mapped pages
1093 * will be memory resident and locked (wired) upon return
1094 * from mlockall(). vm_map_wire() will wire pages, by
1095 * calling vm_fault_wire() for each page in the region.
1096 */
1097 error = vm_map_wire(map, vm_map_min(map), vm_map_max(map),
1098 VM_MAP_WIRE_USER|VM_MAP_WIRE_HOLESOK);
1099 error = (error == KERN_SUCCESS ? 0 : EAGAIN);
1100 }
1088
1089 if (uap->how & MCL_FUTURE) {
1090 vm_map_lock(map);
1091 vm_map_modflags(map, MAP_WIREFUTURE, 0);
1092 vm_map_unlock(map);
1093 error = 0;
1094 }
1095
1096 if (uap->how & MCL_CURRENT) {
1097 /*
1098 * P1003.1-2001 mandates that all currently mapped pages
1099 * will be memory resident and locked (wired) upon return
1100 * from mlockall(). vm_map_wire() will wire pages, by
1101 * calling vm_fault_wire() for each page in the region.
1102 */
1103 error = vm_map_wire(map, vm_map_min(map), vm_map_max(map),
1104 VM_MAP_WIRE_USER|VM_MAP_WIRE_HOLESOK);
1105 error = (error == KERN_SUCCESS ? 0 : EAGAIN);
1106 }
1107#ifdef RACCT
1101 if (error != KERN_SUCCESS) {
1102 PROC_LOCK(td->td_proc);
1103 racct_set(td->td_proc, RACCT_MEMLOCK,
1104 ptoa(pmap_wired_count(vm_map_pmap(&td->td_proc->p_vmspace->vm_map))));
1105 PROC_UNLOCK(td->td_proc);
1106 }
1108 if (error != KERN_SUCCESS) {
1109 PROC_LOCK(td->td_proc);
1110 racct_set(td->td_proc, RACCT_MEMLOCK,
1111 ptoa(pmap_wired_count(vm_map_pmap(&td->td_proc->p_vmspace->vm_map))));
1112 PROC_UNLOCK(td->td_proc);
1113 }
1114#endif
1107
1108 return (error);
1109}
1110
1111#ifndef _SYS_SYSPROTO_H_
1112struct munlockall_args {
1113 register_t dummy;
1114};

--- 18 unchanged lines hidden (view full) ---

1133 /* Clear the MAP_WIREFUTURE flag from this vm_map. */
1134 vm_map_lock(map);
1135 vm_map_modflags(map, 0, MAP_WIREFUTURE);
1136 vm_map_unlock(map);
1137
1138 /* Forcibly unwire all pages. */
1139 error = vm_map_unwire(map, vm_map_min(map), vm_map_max(map),
1140 VM_MAP_WIRE_USER|VM_MAP_WIRE_HOLESOK);
1115
1116 return (error);
1117}
1118
1119#ifndef _SYS_SYSPROTO_H_
1120struct munlockall_args {
1121 register_t dummy;
1122};

--- 18 unchanged lines hidden (view full) ---

1141 /* Clear the MAP_WIREFUTURE flag from this vm_map. */
1142 vm_map_lock(map);
1143 vm_map_modflags(map, 0, MAP_WIREFUTURE);
1144 vm_map_unlock(map);
1145
1146 /* Forcibly unwire all pages. */
1147 error = vm_map_unwire(map, vm_map_min(map), vm_map_max(map),
1148 VM_MAP_WIRE_USER|VM_MAP_WIRE_HOLESOK);
1149#ifdef RACCT
1141 if (error == KERN_SUCCESS) {
1142 PROC_LOCK(td->td_proc);
1143 racct_set(td->td_proc, RACCT_MEMLOCK, 0);
1144 PROC_UNLOCK(td->td_proc);
1145 }
1150 if (error == KERN_SUCCESS) {
1151 PROC_LOCK(td->td_proc);
1152 racct_set(td->td_proc, RACCT_MEMLOCK, 0);
1153 PROC_UNLOCK(td->td_proc);
1154 }
1155#endif
1146
1147 return (error);
1148}
1149
1150#ifndef _SYS_SYSPROTO_H_
1151struct munlock_args {
1152 const void *addr;
1153 size_t len;

--- 18 unchanged lines hidden (view full) ---

1172 size = uap->len;
1173 last = addr + size;
1174 start = trunc_page(addr);
1175 end = round_page(last);
1176 if (last < addr || end < addr)
1177 return (EINVAL);
1178 error = vm_map_unwire(&td->td_proc->p_vmspace->vm_map, start, end,
1179 VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES);
1156
1157 return (error);
1158}
1159
1160#ifndef _SYS_SYSPROTO_H_
1161struct munlock_args {
1162 const void *addr;
1163 size_t len;

--- 18 unchanged lines hidden (view full) ---

1182 size = uap->len;
1183 last = addr + size;
1184 start = trunc_page(addr);
1185 end = round_page(last);
1186 if (last < addr || end < addr)
1187 return (EINVAL);
1188 error = vm_map_unwire(&td->td_proc->p_vmspace->vm_map, start, end,
1189 VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES);
1190#ifdef RACCT
1180 if (error == KERN_SUCCESS) {
1181 PROC_LOCK(td->td_proc);
1182 racct_sub(td->td_proc, RACCT_MEMLOCK, ptoa(end - start));
1183 PROC_UNLOCK(td->td_proc);
1184 }
1191 if (error == KERN_SUCCESS) {
1192 PROC_LOCK(td->td_proc);
1193 racct_sub(td->td_proc, RACCT_MEMLOCK, ptoa(end - start));
1194 PROC_UNLOCK(td->td_proc);
1195 }
1196#endif
1185 return (error == KERN_SUCCESS ? 0 : ENOMEM);
1186}
1187
1188/*
1189 * vm_mmap_vnode()
1190 *
1191 * MPSAFE
1192 *

--- 345 unchanged lines hidden ---
1197 return (error == KERN_SUCCESS ? 0 : ENOMEM);
1198}
1199
1200/*
1201 * vm_mmap_vnode()
1202 *
1203 * MPSAFE
1204 *

--- 345 unchanged lines hidden ---