aboutsummaryrefslogtreecommitdiffstats
path: root/mm/mmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/mmap.c')
-rw-r--r--mm/mmap.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/mm/mmap.c b/mm/mmap.c
index eab6fcb65e11..e6ee12344b13 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -121,14 +121,26 @@ int __vm_enough_memory(long pages, int cap_sys_admin)
121 * only call if we're about to fail. 121 * only call if we're about to fail.
122 */ 122 */
123 n = nr_free_pages(); 123 n = nr_free_pages();
124
125 /*
126 * Leave reserved pages. The pages are not for anonymous pages.
127 */
128 if (n <= totalreserve_pages)
129 goto error;
130 else
131 n -= totalreserve_pages;
132
133 /*
134 * Leave the last 3% for root
135 */
124 if (!cap_sys_admin) 136 if (!cap_sys_admin)
125 n -= n / 32; 137 n -= n / 32;
126 free += n; 138 free += n;
127 139
128 if (free > pages) 140 if (free > pages)
129 return 0; 141 return 0;
130 vm_unacct_memory(pages); 142
131 return -ENOMEM; 143 goto error;
132 } 144 }
133 145
134 allowed = (totalram_pages - hugetlb_total_pages()) 146 allowed = (totalram_pages - hugetlb_total_pages())
@@ -150,7 +162,7 @@ int __vm_enough_memory(long pages, int cap_sys_admin)
150 */ 162 */
151 if (atomic_read(&vm_committed_space) < (long)allowed) 163 if (atomic_read(&vm_committed_space) < (long)allowed)
152 return 0; 164 return 0;
153 165error:
154 vm_unacct_memory(pages); 166 vm_unacct_memory(pages);
155 167
156 return -ENOMEM; 168 return -ENOMEM;