aboutsummaryrefslogtreecommitdiffstats
path: root/mm/mmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/mmap.c')
-rw-r--r--mm/mmap.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/mm/mmap.c b/mm/mmap.c
index 834b2d785f1e..a0e7153a79e6 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -86,6 +86,7 @@ EXPORT_SYMBOL(vm_get_page_prot);
86 86
87int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */ 87int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
88int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */ 88int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
89unsigned long sysctl_overcommit_kbytes __read_mostly;
89int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT; 90int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
90unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */ 91unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
91unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */ 92unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
@@ -1190,6 +1191,24 @@ static inline unsigned long round_hint_to_min(unsigned long hint)
1190 return hint; 1191 return hint;
1191} 1192}
1192 1193
1194static inline int mlock_future_check(struct mm_struct *mm,
1195 unsigned long flags,
1196 unsigned long len)
1197{
1198 unsigned long locked, lock_limit;
1199
1200 /* mlock MCL_FUTURE? */
1201 if (flags & VM_LOCKED) {
1202 locked = len >> PAGE_SHIFT;
1203 locked += mm->locked_vm;
1204 lock_limit = rlimit(RLIMIT_MEMLOCK);
1205 lock_limit >>= PAGE_SHIFT;
1206 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
1207 return -EAGAIN;
1208 }
1209 return 0;
1210}
1211
1193/* 1212/*
1194 * The caller must hold down_write(&current->mm->mmap_sem). 1213 * The caller must hold down_write(&current->mm->mmap_sem).
1195 */ 1214 */
@@ -1251,16 +1270,8 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
1251 if (!can_do_mlock()) 1270 if (!can_do_mlock())
1252 return -EPERM; 1271 return -EPERM;
1253 1272
1254 /* mlock MCL_FUTURE? */ 1273 if (mlock_future_check(mm, vm_flags, len))
1255 if (vm_flags & VM_LOCKED) { 1274 return -EAGAIN;
1256 unsigned long locked, lock_limit;
1257 locked = len >> PAGE_SHIFT;
1258 locked += mm->locked_vm;
1259 lock_limit = rlimit(RLIMIT_MEMLOCK);
1260 lock_limit >>= PAGE_SHIFT;
1261 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
1262 return -EAGAIN;
1263 }
1264 1275
1265 if (file) { 1276 if (file) {
1266 struct inode *inode = file_inode(file); 1277 struct inode *inode = file_inode(file);
@@ -2591,18 +2602,9 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
2591 if (error & ~PAGE_MASK) 2602 if (error & ~PAGE_MASK)
2592 return error; 2603 return error;
2593 2604
2594 /* 2605 error = mlock_future_check(mm, mm->def_flags, len);
2595 * mlock MCL_FUTURE? 2606 if (error)
2596 */ 2607 return error;
2597 if (mm->def_flags & VM_LOCKED) {
2598 unsigned long locked, lock_limit;
2599 locked = len >> PAGE_SHIFT;
2600 locked += mm->locked_vm;
2601 lock_limit = rlimit(RLIMIT_MEMLOCK);
2602 lock_limit >>= PAGE_SHIFT;
2603 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
2604 return -EAGAIN;
2605 }
2606 2608
2607 /* 2609 /*
2608 * mm->mmap_sem is required to protect against another thread 2610 * mm->mmap_sem is required to protect against another thread