Commit 00619bcc44d6b779aa366130b354153c222e4380

Authored by Jerome Marchand
Committed by Linus Torvalds
1 parent 715ea41e60

mm: factor commit limit calculation

The same calculation is currently done in three differents places.
Factor that code so future changes has to be made at only one place.

[akpm@linux-foundation.org: uninline vm_commit_limit()]
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 5 changed files with 18 additions and 9 deletions Side-by-side Diff

... ... @@ -24,7 +24,6 @@
24 24 {
25 25 struct sysinfo i;
26 26 unsigned long committed;
27   - unsigned long allowed;
28 27 struct vmalloc_info vmi;
29 28 long cached;
30 29 unsigned long pages[NR_LRU_LISTS];
... ... @@ -37,8 +36,6 @@
37 36 si_meminfo(&i);
38 37 si_swapinfo(&i);
39 38 committed = percpu_counter_read_positive(&vm_committed_as);
40   - allowed = ((totalram_pages - hugetlb_total_pages())
41   - * sysctl_overcommit_ratio / 100) + total_swap_pages;
42 39  
43 40 cached = global_page_state(NR_FILE_PAGES) -
44 41 total_swapcache_pages() - i.bufferram;
... ... @@ -147,7 +144,7 @@
147 144 K(global_page_state(NR_UNSTABLE_NFS)),
148 145 K(global_page_state(NR_BOUNCE)),
149 146 K(global_page_state(NR_WRITEBACK_TEMP)),
150   - K(allowed),
  147 + K(vm_commit_limit()),
151 148 K(committed),
152 149 (unsigned long)VMALLOC_TOTAL >> 10,
153 150 vmi.used >> 10,
include/linux/mman.h
... ... @@ -87,5 +87,7 @@
87 87 _calc_vm_trans(flags, MAP_DENYWRITE, VM_DENYWRITE ) |
88 88 _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED );
89 89 }
  90 +
  91 +unsigned long vm_commit_limit(void);
90 92 #endif /* _LINUX_MMAN_H */
... ... @@ -179,14 +179,12 @@
179 179 goto error;
180 180 }
181 181  
182   - allowed = (totalram_pages - hugetlb_total_pages())
183   - * sysctl_overcommit_ratio / 100;
  182 + allowed = vm_commit_limit();
184 183 /*
185 184 * Reserve some for root
186 185 */
187 186 if (!cap_sys_admin)
188 187 allowed -= sysctl_admin_reserve_kbytes >> (PAGE_SHIFT - 10);
189   - allowed += total_swap_pages;
190 188  
191 189 /*
192 190 * Don't let a single process grow so big a user can't recover
... ... @@ -1948,13 +1948,12 @@
1948 1948 goto error;
1949 1949 }
1950 1950  
1951   - allowed = totalram_pages * sysctl_overcommit_ratio / 100;
  1951 + allowed = vm_commit_limit();
1952 1952 /*
1953 1953 * Reserve some 3% for root
1954 1954 */
1955 1955 if (!cap_sys_admin)
1956 1956 allowed -= sysctl_admin_reserve_kbytes >> (PAGE_SHIFT - 10);
1957   - allowed += total_swap_pages;
1958 1957  
1959 1958 /*
1960 1959 * Don't let a single process grow so big a user can't recover
... ... @@ -7,6 +7,9 @@
7 7 #include <linux/security.h>
8 8 #include <linux/swap.h>
9 9 #include <linux/swapops.h>
  10 +#include <linux/mman.h>
  11 +#include <linux/hugetlb.h>
  12 +
10 13 #include <asm/uaccess.h>
11 14  
12 15 #include "internal.h"
... ... @@ -397,6 +400,16 @@
397 400 mapping = NULL;
398 401 return mapping;
399 402 }
  403 +
  404 +/*
  405 + * Committed memory limit enforced when OVERCOMMIT_NEVER policy is used
  406 + */
  407 +unsigned long vm_commit_limit(void)
  408 +{
  409 + return ((totalram_pages - hugetlb_total_pages())
  410 + * sysctl_overcommit_ratio / 100) + total_swap_pages;
  411 +}
  412 +
400 413  
401 414 /* Tracepoints definitions. */
402 415 EXPORT_TRACEPOINT_SYMBOL(kmalloc);