diff options
Diffstat (limited to 'mm/mmap.c')
-rw-r--r-- | mm/mmap.c | 34 |
1 files changed, 13 insertions, 21 deletions
@@ -122,9 +122,17 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin) | |||
122 | return 0; | 122 | return 0; |
123 | 123 | ||
124 | if (sysctl_overcommit_memory == OVERCOMMIT_GUESS) { | 124 | if (sysctl_overcommit_memory == OVERCOMMIT_GUESS) { |
125 | unsigned long n; | 125 | free = global_page_state(NR_FREE_PAGES); |
126 | free += global_page_state(NR_FILE_PAGES); | ||
127 | |||
128 | /* | ||
129 | * shmem pages shouldn't be counted as free in this | ||
130 | * case, they can't be purged, only swapped out, and | ||
131 | * that won't affect the overall amount of available | ||
132 | * memory in the system. | ||
133 | */ | ||
134 | free -= global_page_state(NR_SHMEM); | ||
126 | 135 | ||
127 | free = global_page_state(NR_FILE_PAGES); | ||
128 | free += nr_swap_pages; | 136 | free += nr_swap_pages; |
129 | 137 | ||
130 | /* | 138 | /* |
@@ -136,34 +144,18 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin) | |||
136 | free += global_page_state(NR_SLAB_RECLAIMABLE); | 144 | free += global_page_state(NR_SLAB_RECLAIMABLE); |
137 | 145 | ||
138 | /* | 146 | /* |
139 | * Leave the last 3% for root | ||
140 | */ | ||
141 | if (!cap_sys_admin) | ||
142 | free -= free / 32; | ||
143 | |||
144 | if (free > pages) | ||
145 | return 0; | ||
146 | |||
147 | /* | ||
148 | * nr_free_pages() is very expensive on large systems, | ||
149 | * only call if we're about to fail. | ||
150 | */ | ||
151 | n = nr_free_pages(); | ||
152 | |||
153 | /* | ||
154 | * Leave reserved pages. The pages are not for anonymous pages. | 147 | * Leave reserved pages. The pages are not for anonymous pages. |
155 | */ | 148 | */ |
156 | if (n <= totalreserve_pages) | 149 | if (free <= totalreserve_pages) |
157 | goto error; | 150 | goto error; |
158 | else | 151 | else |
159 | n -= totalreserve_pages; | 152 | free -= totalreserve_pages; |
160 | 153 | ||
161 | /* | 154 | /* |
162 | * Leave the last 3% for root | 155 | * Leave the last 3% for root |
163 | */ | 156 | */ |
164 | if (!cap_sys_admin) | 157 | if (!cap_sys_admin) |
165 | n -= n / 32; | 158 | free -= free / 32; |
166 | free += n; | ||
167 | 159 | ||
168 | if (free > pages) | 160 | if (free > pages) |
169 | return 0; | 161 | return 0; |