aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJerome Marchand <jmarchan@redhat.com>2013-11-12 18:08:31 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-11-12 22:09:11 -0500
commit00619bcc44d6b779aa366130b354153c222e4380 (patch)
tree5a885f81a351dfc6ca471823388d89a739406862
parent715ea41e60277f28f84d6c937737350e00955d56 (diff)
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>
-rw-r--r--fs/proc/meminfo.c5
-rw-r--r--include/linux/mman.h2
-rw-r--r--mm/mmap.c4
-rw-r--r--mm/nommu.c3
-rw-r--r--mm/util.c13
5 files changed, 18 insertions, 9 deletions
diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 59d85d608898..c805d5b69ba1 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -24,7 +24,6 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
24{ 24{
25 struct sysinfo i; 25 struct sysinfo i;
26 unsigned long committed; 26 unsigned long committed;
27 unsigned long allowed;
28 struct vmalloc_info vmi; 27 struct vmalloc_info vmi;
29 long cached; 28 long cached;
30 unsigned long pages[NR_LRU_LISTS]; 29 unsigned long pages[NR_LRU_LISTS];
@@ -37,8 +36,6 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
37 si_meminfo(&i); 36 si_meminfo(&i);
38 si_swapinfo(&i); 37 si_swapinfo(&i);
39 committed = percpu_counter_read_positive(&vm_committed_as); 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 cached = global_page_state(NR_FILE_PAGES) - 40 cached = global_page_state(NR_FILE_PAGES) -
44 total_swapcache_pages() - i.bufferram; 41 total_swapcache_pages() - i.bufferram;
@@ -147,7 +144,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
147 K(global_page_state(NR_UNSTABLE_NFS)), 144 K(global_page_state(NR_UNSTABLE_NFS)),
148 K(global_page_state(NR_BOUNCE)), 145 K(global_page_state(NR_BOUNCE)),
149 K(global_page_state(NR_WRITEBACK_TEMP)), 146 K(global_page_state(NR_WRITEBACK_TEMP)),
150 K(allowed), 147 K(vm_commit_limit()),
151 K(committed), 148 K(committed),
152 (unsigned long)VMALLOC_TOTAL >> 10, 149 (unsigned long)VMALLOC_TOTAL >> 10,
153 vmi.used >> 10, 150 vmi.used >> 10,
diff --git a/include/linux/mman.h b/include/linux/mman.h
index 92dc257251e4..7f7f8dae4b1d 100644
--- a/include/linux/mman.h
+++ b/include/linux/mman.h
@@ -87,4 +87,6 @@ calc_vm_flag_bits(unsigned long flags)
87 _calc_vm_trans(flags, MAP_DENYWRITE, VM_DENYWRITE ) | 87 _calc_vm_trans(flags, MAP_DENYWRITE, VM_DENYWRITE ) |
88 _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED ); 88 _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED );
89} 89}
90
91unsigned long vm_commit_limit(void);
90#endif /* _LINUX_MMAN_H */ 92#endif /* _LINUX_MMAN_H */
diff --git a/mm/mmap.c b/mm/mmap.c
index 3d3e224be771..803048e9c568 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -179,14 +179,12 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
179 goto error; 179 goto error;
180 } 180 }
181 181
182 allowed = (totalram_pages - hugetlb_total_pages()) 182 allowed = vm_commit_limit();
183 * sysctl_overcommit_ratio / 100;
184 /* 183 /*
185 * Reserve some for root 184 * Reserve some for root
186 */ 185 */
187 if (!cap_sys_admin) 186 if (!cap_sys_admin)
188 allowed -= sysctl_admin_reserve_kbytes >> (PAGE_SHIFT - 10); 187 allowed -= sysctl_admin_reserve_kbytes >> (PAGE_SHIFT - 10);
189 allowed += total_swap_pages;
190 188
191 /* 189 /*
192 * Don't let a single process grow so big a user can't recover 190 * Don't let a single process grow so big a user can't recover
diff --git a/mm/nommu.c b/mm/nommu.c
index ecd1f158548e..d8a957bb9e31 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1948,13 +1948,12 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
1948 goto error; 1948 goto error;
1949 } 1949 }
1950 1950
1951 allowed = totalram_pages * sysctl_overcommit_ratio / 100; 1951 allowed = vm_commit_limit();
1952 /* 1952 /*
1953 * Reserve some 3% for root 1953 * Reserve some 3% for root
1954 */ 1954 */
1955 if (!cap_sys_admin) 1955 if (!cap_sys_admin)
1956 allowed -= sysctl_admin_reserve_kbytes >> (PAGE_SHIFT - 10); 1956 allowed -= sysctl_admin_reserve_kbytes >> (PAGE_SHIFT - 10);
1957 allowed += total_swap_pages;
1958 1957
1959 /* 1958 /*
1960 * Don't let a single process grow so big a user can't recover 1959 * Don't let a single process grow so big a user can't recover
diff --git a/mm/util.c b/mm/util.c
index eaf63fc2c92f..f7bc2096071c 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -7,6 +7,9 @@
7#include <linux/security.h> 7#include <linux/security.h>
8#include <linux/swap.h> 8#include <linux/swap.h>
9#include <linux/swapops.h> 9#include <linux/swapops.h>
10#include <linux/mman.h>
11#include <linux/hugetlb.h>
12
10#include <asm/uaccess.h> 13#include <asm/uaccess.h>
11 14
12#include "internal.h" 15#include "internal.h"
@@ -398,6 +401,16 @@ struct address_space *page_mapping(struct page *page)
398 return mapping; 401 return mapping;
399} 402}
400 403
404/*
405 * Committed memory limit enforced when OVERCOMMIT_NEVER policy is used
406 */
407unsigned long vm_commit_limit(void)
408{
409 return ((totalram_pages - hugetlb_total_pages())
410 * sysctl_overcommit_ratio / 100) + total_swap_pages;
411}
412
413
401/* Tracepoints definitions. */ 414/* Tracepoints definitions. */
402EXPORT_TRACEPOINT_SYMBOL(kmalloc); 415EXPORT_TRACEPOINT_SYMBOL(kmalloc);
403EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc); 416EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc);