aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
Diffstat (limited to 'mm')
-rw-r--r--mm/mmap.c48
-rw-r--r--mm/shmem.c2
2 files changed, 26 insertions, 24 deletions
diff --git a/mm/mmap.c b/mm/mmap.c
index c581df14d0de..214b6a258eeb 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1090,6 +1090,15 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
1090 mapping_cap_account_dirty(vma->vm_file->f_mapping); 1090 mapping_cap_account_dirty(vma->vm_file->f_mapping);
1091} 1091}
1092 1092
1093/*
1094 * We account for memory if it's a private writeable mapping,
1095 * and VM_NORESERVE wasn't set.
1096 */
1097static inline int accountable_mapping(unsigned int vm_flags)
1098{
1099 return (vm_flags & (VM_NORESERVE | VM_SHARED | VM_WRITE)) == VM_WRITE;
1100}
1101
1093unsigned long mmap_region(struct file *file, unsigned long addr, 1102unsigned long mmap_region(struct file *file, unsigned long addr,
1094 unsigned long len, unsigned long flags, 1103 unsigned long len, unsigned long flags,
1095 unsigned int vm_flags, unsigned long pgoff, 1104 unsigned int vm_flags, unsigned long pgoff,
@@ -1117,23 +1126,24 @@ munmap_back:
1117 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) 1126 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
1118 return -ENOMEM; 1127 return -ENOMEM;
1119 1128
1120 if (flags & MAP_NORESERVE) 1129 /*
1130 * Set 'VM_NORESERVE' if we should not account for the
1131 * memory use of this mapping. We only honor MAP_NORESERVE
1132 * if we're allowed to overcommit memory.
1133 */
1134 if ((flags & MAP_NORESERVE) && sysctl_overcommit_memory != OVERCOMMIT_NEVER)
1135 vm_flags |= VM_NORESERVE;
1136 if (!accountable)
1121 vm_flags |= VM_NORESERVE; 1137 vm_flags |= VM_NORESERVE;
1122 1138
1123 if (accountable && (!(flags & MAP_NORESERVE) || 1139 /*
1124 sysctl_overcommit_memory == OVERCOMMIT_NEVER)) { 1140 * Private writable mapping: check memory availability
1125 if (vm_flags & VM_SHARED) { 1141 */
1126 /* Check memory availability in shmem_file_setup? */ 1142 if (accountable_mapping(vm_flags)) {
1127 vm_flags |= VM_ACCOUNT; 1143 charged = len >> PAGE_SHIFT;
1128 } else if (vm_flags & VM_WRITE) { 1144 if (security_vm_enough_memory(charged))
1129 /* 1145 return -ENOMEM;
1130 * Private writable mapping: check memory availability 1146 vm_flags |= VM_ACCOUNT;
1131 */
1132 charged = len >> PAGE_SHIFT;
1133 if (security_vm_enough_memory(charged))
1134 return -ENOMEM;
1135 vm_flags |= VM_ACCOUNT;
1136 }
1137 } 1147 }
1138 1148
1139 /* 1149 /*
@@ -1184,14 +1194,6 @@ munmap_back:
1184 goto free_vma; 1194 goto free_vma;
1185 } 1195 }
1186 1196
1187 /* We set VM_ACCOUNT in a shared mapping's vm_flags, to inform
1188 * shmem_zero_setup (perhaps called through /dev/zero's ->mmap)
1189 * that memory reservation must be checked; but that reservation
1190 * belongs to shared memory object, not to vma: so now clear it.
1191 */
1192 if ((vm_flags & (VM_SHARED|VM_ACCOUNT)) == (VM_SHARED|VM_ACCOUNT))
1193 vma->vm_flags &= ~VM_ACCOUNT;
1194
1195 /* Can addr have changed?? 1197 /* Can addr have changed??
1196 * 1198 *
1197 * Answer: Yes, several device drivers can do it in their 1199 * Answer: Yes, several device drivers can do it in their
diff --git a/mm/shmem.c b/mm/shmem.c
index 5d0de96c9789..19d566ccdeea 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2628,7 +2628,7 @@ struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
2628 goto close_file; 2628 goto close_file;
2629 2629
2630#ifdef CONFIG_SHMEM 2630#ifdef CONFIG_SHMEM
2631 SHMEM_I(inode)->flags = flags & VM_ACCOUNT; 2631 SHMEM_I(inode)->flags = (flags & VM_NORESERVE) ? 0 : VM_ACCOUNT;
2632#endif 2632#endif
2633 d_instantiate(dentry, inode); 2633 d_instantiate(dentry, inode);
2634 inode->i_size = size; 2634 inode->i_size = size;