mm: factor commit limit calculation
Subsystems (6)
PATCH v4 1/2 mm: factor commit limit calculation
Change since v3:
- rebase on 3.12-rc5
The same calculation is currently done in three differents places. Factor that code so future changes has to be made at only one place.
--- fs/proc/meminfo.c | 5 +---- include/linux/mman.h | 12 ++++++++++++ mm/mmap.c | 4 +--- mm/nommu.c | 3 +-- 4 files changed, 15 insertions(+), 9 deletions(-)
fs/proc/meminfo.c +1 -4
@@ -24,7 +24,6 @@ static int meminfo_proc_show(struct seq_file *m, void *v) {struct sysinfo i;unsigned long committed; -unsigned long allowed;struct vmalloc_info vmi;long cached;unsigned long pages[NR_LRU_LISTS ];
@@ -37,8 +36,6 @@ static int meminfo_proc_show(struct seq_file *m, void *v)si_meminfo (&i);si_swapinfo (&i); committed =percpu_counter_read_positive (&vm_committed_as); - allowed = ((totalram_pages -hugetlb_total_pages ()) - * sysctl_overcommit_ratio /100 ) + total_swap_pages; cached =global_page_state (NR_FILE_PAGES ) -total_swapcache_pages () - i.bufferram;
@@ -147,7 +144,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)K (global_page_state (NR_UNSTABLE_NFS )),K (global_page_state (NR_BOUNCE )),K (global_page_state (NR_WRITEBACK_TEMP )), -K (allowed), +K (vm_commit_limit ()),K (committed), (unsigned long )VMALLOC_TOTAL >>10 , vmi.used >> 10,
include/linux/mman.h +12 -0
@@ -7,6 +7,9 @@#include <linux/atomic.h> #include <uapi/linux/mman.h> +#include <linux/hugetlb.h> +#include <linux/swap.h> +extern int sysctl_overcommit_memory;extern int sysctl_overcommit_ratio;extern struct percpu_counter vm_committed_as;
@@ -87,4 +90,13 @@ calc_vm_flag_bits(unsigned long flags)_calc_vm_trans (flags,MAP_DENYWRITE ,VM_DENYWRITE ) | _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED ); } + +/* +* Commited memory limit enforced when OVERCOMMIT_NEVER policy is used +*/ +static inline unsigned long vm_commit_limit () +{ +return ((totalram_pages -hugetlb_total_pages ()) + * sysctl_overcommit_ratio /100 ) + total_swap_pages; +}#endif /* _LINUX_MMAN_H */
mm/mmap.c +1 -3
@@ -179,14 +179,12 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin) goto error; } - allowed = (totalram_pages -hugetlb_total_pages ()) - * sysctl_overcommit_ratio /100 ; + allowed =vm_commit_limit ();/* * Reserve some for root */ if (!cap_sys_admin) allowed -= sysctl_admin_reserve_kbytes >> (PAGE_SHIFT -10 ); - allowed += total_swap_pages;/* * Don't let a single process grow so big a user can't recover
mm/nommu.c +1 -2
@@ -1948,13 +1948,12 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin) goto error; } - allowed = totalram_pages * sysctl_overcommit_ratio /100 ; + allowed =vm_commit_limit ();/* * Reserve some 3% for root */ if (!cap_sys_admin) allowed -= sysctl_admin_reserve_kbytes >> (PAGE_SHIFT -10 ); - allowed += total_swap_pages;/* * Don't let a single process grow so big a user can't recover
Signature · 7 lines
1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v4 2/2 mm: allow to set overcommit ratio more precisely
Changes since v3:
- rebase on 3.12-rc5
Changes since v2:
- updates documentation
Changes since v1:
- use overcommit_ratio_ppm instead of overcommit_kbytes
- keep both variables in sync
Some applications that run on HPC clusters are designed around the availability of RAM and the overcommit ratio is fine tuned to get the maximum usage of memory without swapping. With growing memory, the 1% of all RAM grain provided by overcommit_ratio has become too coarse for these workload (on a 2TB machine it represents no less than 20GB).
This patch adds the new overcommit_ratio_ppm sysctl variable that allow to set overcommit ratio with a part per million precision. The old overcommit_ratio variable can still be used to set and read the ratio with a 1% precision. That way, overcommit_ratio interface isn't broken in any way that I can imagine.
--- Documentation/sysctl/vm.txt | 10 +++++ Documentation/vm/overcommit-accounting | 7 ++-- include/linux/mman.h | 6 ++-- include/linux/sysctl.h | 2 + kernel/sysctl.c | 63 ++++++++++++++++++++++++++++++-- mm/mmap.c | 2 +- mm/nommu.c | 2 +- 7 files changed, 81 insertions(+), 11 deletions(-)
Documentation/sysctl/vm.txt +10 -0
@@ -49,6 +49,7 @@ Currently, these files are in /proc/sys/vm: - oom_kill_allocating_task - overcommit_memory - overcommit_ratio +- overcommit_ratio_ppm - page-cluster - panic_on_oom - percpu_pagelist_fraction
@@ -599,6 +600,15 @@ overcommit_ratio: When overcommit_memory is set to 2, the committed address space is not permitted to exceed swap plus this percentage of physical RAM. See above. +If overcommit_ratio_ppm has been set, overcommit_ratio shows a +rounded value. + +============================================================== + +overcommit_ratio_ppm: + +Same as overcommit_ratio, but allows to set the ratio with a finer +grain (part per million). ==============================================================
Documentation/vm/overcommit-accounting +4 -3
@@ -14,8 +14,8 @@ The Linux kernel supports the following overcommit handling modes 2 - Don't overcommit. The total address space commit for the system is not permitted to exceed swap + a - configurable percentage (default is 50) of physical RAM. - Depending on the percentage you use, in most situations + configurable ratio (default is 50%) of physical RAM. + Depending on the ratio you use, in most situations this means a process will not be killed while accessing pages but will receive errors on memory allocation as appropriate.
@@ -26,7 +26,8 @@ The Linux kernel supports the following overcommit handling modes The overcommit policy is set via the sysctl `vm.overcommit_memory'. -The overcommit percentage is set via `vm.overcommit_ratio'. +The overcommit percentage is set via `vm.overcommit_ratio' or +`vm.overcommit_ratio_ppm'. The current overcommit limit and amount committed are viewable in /proc/meminfo as CommitLimit and Committed_AS respectively.
include/linux/mman.h +3 -3
@@ -11,7 +11,7 @@#include <linux/swap.h> extern int sysctl_overcommit_memory; -extern int sysctl_overcommit_ratio; +extern int sysctl_overcommit_ratio_ppm;extern struct percpu_counter vm_committed_as;#ifdef CONFIG_SMP
@@ -96,7 +96,7 @@ calc_vm_flag_bits(unsigned long flags)*/ static inline unsigned long vm_commit_limit () { -return ((totalram_pages -hugetlb_total_pages ()) - * sysctl_overcommit_ratio /100 ) + total_swap_pages; +return ((u64) (totalram_pages -hugetlb_total_pages ()) + * sysctl_overcommit_ratio_ppm /100000 ) + total_swap_pages; }#endif /* _LINUX_MMAN_H */
include/linux/sysctl.h +2 -0
@@ -51,6 +51,8 @@ extern int proc_dointvec_userhz_jiffies(struct ctl_table *, int, void __user *, size_t *, loff_t *);extern int proc_dointvec_ms_jiffies (struct ctl_table *,int ,void __user *,size_t *,loff_t *); +extern int proc_dointvec_percent_ppm (struct ctl_table *,int , +void __user *,size_t *,loff_t *);extern int proc_doulongvec_minmax (struct ctl_table *,int ,void __user *,size_t *,loff_t *); extern int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int,
kernel/sysctl.c +60 -3
81 lines not on this page · raw message
mm/mmap.c +1 -1
@@ -85,7 +85,7 @@ pgprot_t vm_get_page_prot(unsigned long vm_flags)EXPORT_SYMBOL (vm_get_page_prot);int sysctl_overcommit_memory__read_mostly =OVERCOMMIT_GUESS ;/* heuristic overcommit */ -int sysctl_overcommit_ratio__read_mostly =50 ;/* default is 50% */ +int sysctl_overcommit_ratio_ppm__read_mostly =500000 ;/* default is 50% */ int sysctl_max_map_count__read_mostly =DEFAULT_MAX_MAP_COUNT ;unsigned long sysctl_user_reserve_kbytes__read_mostly =1UL <<17 ;/* 128MB */ unsigned long sysctl_admin_reserve_kbytes__read_mostly =1UL <<13 ;/* 8MB */
mm/nommu.c +1 -1
@@ -59,7 +59,7 @@ unsigned long max_mapnr;unsigned long highest_memmap_pfn;struct percpu_counter vm_committed_as;int sysctl_overcommit_memory =OVERCOMMIT_GUESS ;/* heuristic overcommit */ -int sysctl_overcommit_ratio =50 ;/* default is 50% */ +int sysctl_overcommit_ratio_ppm =500000 ;/* default is 50% */ int sysctl_max_map_count =DEFAULT_MAX_MAP_COUNT ;int sysctl_nr_trim_pages =CONFIG_NOMMU_INITIAL_TRIM_EXCESS ;unsigned long sysctl_user_reserve_kbytes__read_mostly =1UL <<17 ;/* 128MB */
Signature · 7 lines
1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH v4 2/2] mm: allow to set overcommit ratio more precisely
Quoted 7 lines · On Fri, 18 Oct 2013 14:56:59 +0200 Jerome Marchand <[email protected]> wrote:
Some applications that run on HPC clusters are designed around the availability of RAM and the overcommit ratio is fine tuned to get the maximum usage of memory without swapping. With growing memory, the 1% of all RAM grain provided by
overcommit_ratiohas become too coarse for these workload (on a 2TB machine it represents no less than 20GB).
Quoted 5 lines
This patch adds the new
overcommit_ratio_ppmsysctl variable that allow to set overcommit ratio with a part per million precision. The oldovercommit_ratiovariable can still be used to set and read the ratio with a 1% precision. That way,overcommit_ratiointerface isn't broken in any way that I can imagine.
The way we've permanently squished this mistake in the past is to switch to "bytes". See /proc/sys/vm/*bytes.
Would that approach work in this case?
Re: [PATCH v4 2/2] mm: allow to set overcommit ratio more precisely
----- Original Message -----
Quoted 22 lines
From: "Andrew Morton" <[email protected]>
To: "Jerome Marchand" <[email protected]>
Cc: [email protected], [email protected], "dave hansen" <[email protected]>
Sent: Wednesday, November 6, 2013 12:53:19 AM
Subject: Re: [PATCH v4 2/2] mm: allow to set overcommit ratio more preciselyQuoted 7 lines · On Fri, 18 Oct 2013 14:56:59 +0200 Jerome Marchand <[email protected]> wrote:
Some applications that run on HPC clusters are designed around the availability of RAM and the overcommit ratio is fine tuned to get the maximum usage of memory without swapping. With growing memory, the 1% of all RAM grain provided by
overcommit_ratiohas become too coarse for these workload (on a 2TB machine it represents no less than 20GB).Quoted 5 lines
This patch adds the new
overcommit_ratio_ppmsysctl variable that allow to set overcommit ratio with a part per million precision. The oldovercommit_ratiovariable can still be used to set and read the ratio with a 1% precision. That way,overcommit_ratiointerface isn't broken in any way that I can imagine.
Quoted 5 lines
The way we've permanently squished this mistake in the past is to switch to "bytes". See
/proc/sys/vm/*bytes.Would that approach work in this case?
That was my first version of this patch (actually "kbytes" to avoid overflow).
Dave raised the issue that it silently breaks the user interface:overcommit_ratio is zero while the system behaves differently.
Jerome
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH v4 2/2] mm: allow to set overcommit ratio more precisely
Quoted 28 lines · On Wed, 6 Nov 2013 03:42:20 -0500 (EST) Jerome Marchand <[email protected]>…
----- Original Message -----
Quoted 25 lines
From: "Andrew Morton" <[email protected]>
To: "Jerome Marchand" <[email protected]>
Cc: [email protected], [email protected], "dave hansen" <[email protected]>
Sent: Wednesday, November 6, 2013 12:53:19 AM
Subject: Re: [PATCH v4 2/2] mm: allow to set overcommit ratio more preciselyQuoted 7 lines · On Fri, 18 Oct 2013 14:56:59 +0200 Jerome Marchand <[email protected]> wrote:
Some applications that run on HPC clusters are designed around the availability of RAM and the overcommit ratio is fine tuned to get the maximum usage of memory without swapping. With growing memory, the 1% of all RAM grain provided by
overcommit_ratiohas become too coarse for these workload (on a 2TB machine it represents no less than 20GB).Quoted 5 lines
This patch adds the new
overcommit_ratio_ppmsysctl variable that allow to set overcommit ratio with a part per million precision. The oldovercommit_ratiovariable can still be used to set and read the ratio with a 1% precision. That way,overcommit_ratiointerface isn't broken in any way that I can imagine.The way we've permanently squished this mistake in the past is to switch to "bytes". See
/proc/sys/vm/*bytes.
Quoted 7 lines
Quoted 2 lines
Would that approach work in this case?
That was my first version of this patch (actually "kbytes" to avoid overflow).
Dave raised the issue that it silently breaks the user interface:overcommit_ratiois zero while the system behaves differently.
I don't understand that at all. We keep overcommit_ratio as-is, with the same default values and add a different way of altering it. That should be back-compatible?
Re: [PATCH v4 2/2] mm: allow to set overcommit ratio more precisely
Quoted 9 lines · Andrew Morton
Quoted 4 lines · On Wed, 6 Nov 2013 03:42:20 -0500 (EST) Jerome Marchand <[email protected]>…
That was my first version of this patch (actually "kbytes" to avoid overflow).
Dave raised the issue that it silently breaks the user interface:overcommit_ratiois zero while the system behaves differently.I don't understand that at all. We keep
overcommit_ratioas-is, with the same default values and add a different way of altering it. That should be back-compatible?
Reading the old thread, I think my main point was that we shouldn't output overcommit_ratio=0 when overcommit_bytes>0. We need to round up for numbers less than 1 so that folks don't think overcommit_ratio is _off_.
I was really just trying to talk you in to cramming the extra precision in to the _existing_ sysctl. :) I don't think bytes vs. ratio is really that big of a deal.
Re: [PATCH v4 2/2] mm: allow to set overcommit ratio more precisely
----- Original Message -----
Quoted 14 lines
From: "Dave Hansen" <[email protected]>
To: "Andrew Morton" <[email protected]>, "Jerome Marchand" <[email protected]>
Cc: [email protected], [email protected]
Sent: Thursday, November 7, 2013 12:49:54 AM
Subject: Re: [PATCH v4 2/2] mm: allow to set overcommit ratio more preciselyQuoted 7 lines · Andrew Morton
Quoted 4 lines · On Wed, 6 Nov 2013 03:42:20 -0500 (EST) Jerome Marchand <[email protected]>…
That was my first version of this patch (actually "kbytes" to avoid overflow).
Dave raised the issue that it silently breaks the user interface:overcommit_ratiois zero while the system behaves differently.
Quoted 7 lines
Quoted 3 lines
I don't understand that at all. We keep
overcommit_ratioas-is, with the same default values and add a different way of altering it. That should be back-compatible?Reading the old thread, I think my main point was that we shouldn't output overcommit_ratio=0 when overcommit_bytes>0. We need to round up for numbers less than 1 so that folks don't think
overcommit_ratiois _off_.
This is not how current *bytes work. Also the *ratio and *bytes value would diverge if the amount of memory changes (e.g. memory hotplug).
Quoted 5 lines
I was really just trying to talk you in to cramming the extra precision in to the _existing_ sysctl. :) I don't think bytes vs. ratio is really that big of a deal.
If everybody agrees on overcommit_kbytes, I can resend my original patch.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v5 1/1 mm: add overcommit_kbytes sysctl variable
In reply to Jerome MarchandChanges since v4:
- revert to my initial overcommit_kbytes design as it is more consistent with current *_ratio/*_bytes implementation for other variables.
Some applications that run on HPC clusters are designed around the availability of RAM and the overcommit ratio is fine tuned to get the maximum usage of memory without swapping. With growing memory, the 1%-of-all-RAM grain provided by overcommit_ratio has become too coarse for these workload (on a 2TB machine it represents no less than 20GB).
This patch adds the new overcommit_kbytes sysctl variable that allow a much finer grain.
--- Documentation/sysctl/vm.txt | 12 ++++++++++++ Documentation/vm/overcommit-accounting | 7 ++++--- include/linux/mm.h | 5 +++++ include/linux/mman.h | 1 + kernel/sysctl.c | 10 +++++++++- mm/mmap.c | 25 +++++++++++++++++++++++++ mm/nommu.c | 1 + mm/util.c | 12 ++++++++++-- 8 files changed, 67 insertions(+), 6 deletions(-)
Documentation/sysctl/vm.txt +12 -0
@@ -47,6 +47,7 @@ Currently, these files are in /proc/sys/vm: - numa_zonelist_order - oom_dump_tasks - oom_kill_allocating_task +- overcommit_kbytes - overcommit_memory - overcommit_ratio - page-cluster
@@ -574,6 +575,17 @@ The default value is 0. ============================================================== +overcommit_kbytes: + +When overcommit_memory is set to 2, the committed address space is not +permitted to exceed swap plus this amount of physical RAM. See below. + +Note: overcommit_kbytes is the counterpart of overcommit_ratio. Only one +of them may be specified at a time. Setting one disable the other (which +then appears as 0 when read). + +============================================================== + overcommit_memory: This value contains a flag that enables memory overcommitment.
Documentation/vm/overcommit-accounting +4 -3
@@ -14,8 +14,8 @@ The Linux kernel supports the following overcommit handling modes 2 - Don't overcommit. The total address space commit for the system is not permitted to exceed swap + a - configurable percentage (default is 50) of physical RAM. - Depending on the percentage you use, in most situations + configurable amount (default is 50%) of physical RAM. + Depending on the amount you use, in most situations this means a process will not be killed while accessing pages but will receive errors on memory allocation as appropriate.
@@ -26,7 +26,8 @@ The Linux kernel supports the following overcommit handling modes The overcommit policy is set via the sysctl `vm.overcommit_memory'. -The overcommit percentage is set via `vm.overcommit_ratio'. +The overcommit amount can be set via `vm.overcommit_ratio' (percentage) +or `vm.overcommit_kbytes' (absolute value). The current overcommit limit and amount committed are viewable in /proc/meminfo as CommitLimit and Committed_AS respectively.
include/linux/mm.h +5 -0
@@ -57,6 +57,11 @@ extern int sysctl_legacy_va_layout;extern unsigned long sysctl_user_reserve_kbytes;extern unsigned long sysctl_admin_reserve_kbytes; +extern int overcommit_ratio_handler (struct ctl_table *,int ,void __user *, +size_t *,loff_t *); +extern int overcommit_kbytes_handler (struct ctl_table *,int ,void __user *, +size_t *,loff_t *); +#define nth_page (page,n) pfn_to_page(page_to_pfn((page)) + (n))/* to align the pointer to the (next) page boundary */
include/linux/mman.h +1 -0
@@ -9,6 +9,7 @@extern int sysctl_overcommit_memory;extern int sysctl_overcommit_ratio; +extern unsigned long sysctl_overcommit_kbytes;extern struct percpu_counter vm_committed_as;#ifdef CONFIG_SMP
kernel/sysctl.c +9 -1
@@ -97,6 +97,7 @@/* External variables not in a header file. */ extern int sysctl_overcommit_memory;extern int sysctl_overcommit_ratio; +extern unsigned long sysctl_overcommit_kbytes;extern int max_threads;extern int suid_dumpable;#ifdef CONFIG_COREDUMP
@@ -1128,7 +1129,14 @@ static struct ctl_table vm_table[] = { .data = &sysctl_overcommit_ratio, .maxlen = sizeof(sysctl_overcommit_ratio), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = overcommit_ratio_handler, + }, + { + .procname = "overcommit_kbytes", + .data = &sysctl_overcommit_kbytes, + .maxlen = sizeof(sysctl_overcommit_kbytes), + .mode = 0644, + .proc_handler = overcommit_kbytes_handler, }, { .procname = "page-cluster",
mm/mmap.c +25 -0
@@ -86,6 +86,7 @@ EXPORT_SYMBOL(vm_get_page_prot);int sysctl_overcommit_memory__read_mostly =OVERCOMMIT_GUESS ;/* heuristic overcommit */ int sysctl_overcommit_ratio__read_mostly =50 ;/* default is 50% */ +unsigned long sysctl_overcommit_kbytes__read_mostly =0 ;int sysctl_max_map_count__read_mostly =DEFAULT_MAX_MAP_COUNT ;unsigned long sysctl_user_reserve_kbytes__read_mostly =1UL <<17 ;/* 128MB */ unsigned long sysctl_admin_reserve_kbytes__read_mostly =1UL <<13 ;/* 8MB */
@@ -95,6 +96,30 @@ unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */*/ struct percpu_counter vm_committed_as____cacheline_aligned_in_smp ; +int overcommit_ratio_handler (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos) +{ +int ret; + + ret =proc_dointvec (table, write, buffer, lenp, ppos); +if (ret ==0 && write) + sysctl_overcommit_kbytes =0 ; +return ret; +} + +int overcommit_kbytes_handler (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos) +{ +int ret; + + ret =proc_doulongvec_minmax (table, write, buffer, lenp, ppos); +if (ret ==0 && write) + sysctl_overcommit_ratio =0 ; +return ret; +} +/* * The global memory commitment made in the system can be a metric * that can be used to drive ballooning decisions when Linux is hosted
mm/nommu.c +1 -0
@@ -60,6 +60,7 @@ unsigned long highest_memmap_pfn;struct percpu_counter vm_committed_as;int sysctl_overcommit_memory =OVERCOMMIT_GUESS ;/* heuristic overcommit */ int sysctl_overcommit_ratio =50 ;/* default is 50% */ +unsigned long sysctl_overcommit_kbytes__read_mostly =0 ;int sysctl_max_map_count =DEFAULT_MAX_MAP_COUNT ;int sysctl_nr_trim_pages =CONFIG_NOMMU_INITIAL_TRIM_EXCESS ;unsigned long sysctl_user_reserve_kbytes__read_mostly =1UL <<17 ;/* 128MB */
mm/util.c +10 -2
@@ -406,8 +406,16 @@ struct address_space *page_mapping(struct page *page)*/ unsigned long vm_commit_limit (void ) { -return ((totalram_pages -hugetlb_total_pages ()) - * sysctl_overcommit_ratio /100 ) + total_swap_pages; +unsigned long allowed; + +if (sysctl_overcommit_kbytes) + allowed = sysctl_overcommit_kbytes >> (PAGE_SHIFT -10 ); +else + allowed = ((totalram_pages -hugetlb_total_pages ()) + * sysctl_overcommit_ratio /100 ); + allowed += total_swap_pages; + +return allowed; }
Signature · 9 lines
1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH v5] mm: add overcommit_kbytes sysctl variable
Quoted 13 lines · On Tue, 03 Dec 2013 14:33:35 +0100 Jerome Marchand <[email protected]> wrote:
Changes since v4:
- revert to my initialovercommit_kbytesdesign as it is more consistent with current *_ratio/*_bytes implementation for other variables.Some applications that run on HPC clusters are designed around the availability of RAM and the overcommit ratio is fine tuned to get the maximum usage of memory without swapping. With growing memory, the 1%-of-all-RAM grain provided by
overcommit_ratiohas become too coarse for these workload (on a 2TB machine it represents no less than 20GB).
Quoted 2 lines
This patch adds the new
overcommit_kbytessysctl variable that allow a much finer grain.
Seems OK to me.
Documentation/sysctl/vm.txt The default value is 0. · line 584
Quoted 13 lines
Documentation/sysctl/vm.txt +7
-0@@ -574,6 +575,17 @@ The default value is 0. ============================================================== +overcommit_kbytes: + +When overcommit_memory is set to 2, the committed address space is not +permitted to exceed swap plus this amount of physical RAM. See below. + +Note: overcommit_kbytes is the counterpart of overcommit_ratio. Only one +of them may be specified at a time. Setting one disable the other (which
Documentation/sysctl/vm.txt renamed from Documentation/sysctl/vm.txt~mm-add-overcommit_kbytes-sysctl-variable-fix +1 -1
@@ -581,7 +581,7 @@ When overcommit_memory is set to 2, the permitted to exceed swap plus this amount of physical RAM. See below. Note: overcommit_kbytes is the counterpart of overcommit_ratio. Only one -of them may be specified at a time. Setting one disable the other (which +of them may be specified at a time. Setting one disables the other (which then appears as 0 when read). ==============================================================
Please do use checkpatch.
From: Andrew Morton <[email protected]>
Subject: mm-add-overcommit_kbytes-sysctl-variable-checkpatch-fixes
WARNING: Non-standard signature: Signed-of-by:
#13:
WARNING: externs should be avoided in .c files
#115: FILE: kernel/sysctl.c:100:
+extern unsigned long sysctl_overcommit_kbytes;
ERROR: do not initialise globals to 0 or NULL #142: FILE: mm/mmap.c:89:
+unsigned long sysctl_overcommit_kbytes __read_mostly = 0;
ERROR: do not initialise globals to 0 or NULL #184: FILE: mm/nommu.c:63:
+unsigned long sysctl_overcommit_kbytes __read_mostly = 0;
total: 2 errors, 2 warnings, 145 lines checked
./patches/mm-add-overcommit_kbytes-sysctl-variable.patch has style problems, please review.
If any of these errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Please run checkpatch prior to sending patches
---
include/linux/mm.h | 4 ++++ kernel/sysctl.c | 3 --- mm/mmap.c | 2 +- mm/nommu.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-)
include/linux/mm.h renamed from include/linux/mm.h~mm-add-overcommit_kbytes-sysctl-variable-checkpatch-fixes +4 -0
@@ -57,6 +57,10 @@ extern int sysctl_legacy_va_layout;extern unsigned long sysctl_user_reserve_kbytes;extern unsigned long sysctl_admin_reserve_kbytes; +extern int sysctl_overcommit_memory; +extern int sysctl_overcommit_ratio; +extern unsigned long sysctl_overcommit_kbytes; +extern int overcommit_ratio_handler (struct ctl_table *,int ,void __user *,size_t *,loff_t *); extern int overcommit_kbytes_handler(struct ctl_table *, int, void __user *,
kernel/sysctl.c renamed from kernel/sysctl.c~mm-add-overcommit_kbytes-sysctl-variable-checkpatch-fixes +0 -3
@@ -95,9 +95,6 @@#if defined(CONFIG_SYSCTL )/* External variables not in a header file. */ -extern int sysctl_overcommit_memory; -extern int sysctl_overcommit_ratio; -extern unsigned long sysctl_overcommit_kbytes;extern int max_threads;extern int suid_dumpable;#ifdef CONFIG_COREDUMP
mm/mmap.c renamed from mm/mmap.c~mm-add-overcommit_kbytes-sysctl-variable-checkpatch-fixes +1 -1
@@ -86,7 +86,7 @@ EXPORT_SYMBOL(vm_get_page_prot);int sysctl_overcommit_memory__read_mostly =OVERCOMMIT_GUESS ;/* heuristic overcommit */ int sysctl_overcommit_ratio__read_mostly =50 ;/* default is 50% */ -unsigned long sysctl_overcommit_kbytes__read_mostly =0 ; +unsigned long sysctl_overcommit_kbytes__read_mostly ;int sysctl_max_map_count__read_mostly =DEFAULT_MAX_MAP_COUNT ;unsigned long sysctl_user_reserve_kbytes__read_mostly =1UL <<17 ;/* 128MB */ unsigned long sysctl_admin_reserve_kbytes__read_mostly =1UL <<13 ;/* 8MB */
mm/nommu.c renamed from mm/nommu.c~mm-add-overcommit_kbytes-sysctl-variable-checkpatch-fixes +1 -1
@@ -60,7 +60,7 @@ unsigned long highest_memmap_pfn;struct percpu_counter vm_committed_as;int sysctl_overcommit_memory =OVERCOMMIT_GUESS ;/* heuristic overcommit */ int sysctl_overcommit_ratio =50 ;/* default is 50% */ -unsigned long sysctl_overcommit_kbytes__read_mostly =0 ; +unsigned long sysctl_overcommit_kbytes__read_mostly ;int sysctl_max_map_count =DEFAULT_MAX_MAP_COUNT ;int sysctl_nr_trim_pages =CONFIG_NOMMU_INITIAL_TRIM_EXCESS ;unsigned long sysctl_user_reserve_kbytes__read_mostly =1UL <<17 ;/* 128MB */
_
Re: [PATCH v5] mm: add overcommit_kbytes sysctl variable
In reply to Jerome MarchandHi,
On Tue, Dec 3, 2013 at 5:33 AM, Jerome Marchand <[email protected]> wrote:
[...]
Quoted 76 lines
kernel/sysctl.c +9
-1@@ -97,6 +97,7 @@/* External variables not in a header file. */ extern int sysctl_overcommit_memory;extern int sysctl_overcommit_ratio; +extern unsigned long sysctl_overcommit_kbytes;extern int max_threads;extern int suid_dumpable;#ifdef CONFIG_COREDUMP @@ -1128,7 +1129,14 @@ static struct ctl_table vm_table[] = { .data = &sysctl_overcommit_ratio, .maxlen = sizeof(sysctl_overcommit_ratio), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = overcommit_ratio_handler, + }, + { + .procname = "overcommit_kbytes", + .data = &sysctl_overcommit_kbytes, + .maxlen = sizeof(sysctl_overcommit_kbytes), + .mode = 0644, + .proc_handler = overcommit_kbytes_handler, }, { .procname = "page-cluster",mm/mmap.c +25
-0@@ -86,6 +86,7 @@ EXPORT_SYMBOL(vm_get_page_prot);int sysctl_overcommit_memory__read_mostly =OVERCOMMIT_GUESS ;/* heuristic overcommit */ int sysctl_overcommit_ratio__read_mostly =50 ;/* default is 50% */ +unsigned long sysctl_overcommit_kbytes__read_mostly =0 ;int sysctl_max_map_count__read_mostly =DEFAULT_MAX_MAP_COUNT ;unsigned long sysctl_user_reserve_kbytes__read_mostly =1UL <<17 ;/* 128MB */ unsigned long sysctl_admin_reserve_kbytes__read_mostly =1UL <<13 ;/* 8MB */ @@ -95,6 +96,30 @@ unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */*/ struct percpu_counter vm_committed_as____cacheline_aligned_in_smp ; +int overcommit_ratio_handler (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos) +{ +int ret; + + ret =proc_dointvec (table, write, buffer, lenp, ppos); +if (ret ==0 && write) + sysctl_overcommit_kbytes =0 ; +return ret; +} + +int overcommit_kbytes_handler (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos) +{ +int ret; + + ret =proc_doulongvec_minmax (table, write, buffer, lenp, ppos); +if (ret ==0 && write) + sysctl_overcommit_ratio =0 ; +return ret; +} +/* * The global memory commitment made in the system can be a metric * that can be used to drive ballooning decisions when Linux is hosted mm/nommu.c +0
-0
mm/nommu.c unsigned long highest_memmap_pfn; · line 66
Quoted 7 lines
mm/nommu.c +1
-0@@ -60,6 +60,7 @@ unsigned long highest_memmap_pfn;struct percpu_counter vm_committed_as;int sysctl_overcommit_memory =OVERCOMMIT_GUESS ;/* heuristic overcommit */ int sysctl_overcommit_ratio =50 ;/* default is 50% */ +unsigned long sysctl_overcommit_kbytes__read_mostly =0 ;int sysctl_max_map_count =DEFAULT_MAX_MAP_COUNT ;int sysctl_nr_trim_pages =CONFIG_NOMMU_INITIAL_TRIM_EXCESS ;unsigned long sysctl_user_reserve_kbytes__read_mostly =1UL <<17 ;/* 128MB */
You add the variable on the nommu side, but not the functions to handle the sysctl. So things fail to compile on !MMU builds with:
kernel/built-in.o:(.data+0x4e0): undefined reference to overcommit_ratio_handler' kernel/built-in.o:(.data+0x504): undefined reference to overcommit_kbytes_handler'
I don't know mm well enough to tell if copying and pasting the code over verbatim is the right thing to do, or if there's a preferred other location (that is shared) to move it to?
-Olof
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 6 lines · On Fri, 18 Oct 2013 14:56:58 +0200 Jerome Marchand <[email protected]> wrote:
Change since v3:
- rebase on 3.12-rc5The same calculation is currently done in three differents places. Factor that code so future changes has to be made at only one place.
lgtm.
Quoted 15 lines
include/linux/mman.h +3
-0@@ -7,6 +7,9 @@#include <linux/atomic.h> #include <uapi/linux/mman.h> +#include <linux/hugetlb.h> +#include <linux/swap.h> +extern int sysctl_overcommit_memory;extern int sysctl_overcommit_ratio;extern struct percpu_counter vm_committed_as;@@ -87,4 +90,13 @@ calc_vm_flag_bits(unsigned long flags)_calc_vm_trans (flags,MAP_DENYWRITE ,VM_DENYWRITE ) |_calc_vm_trans (flags,MAP_LOCKED ,VM_LOCKED );
include/linux/mman.h calc_vm_flag_bits(unsigned long flags) · line 101
Quoted 10 lines
include/linux/mman.h +9
-0} + +/* +* Commited memory limit enforced when OVERCOMMIT_NEVER policy is used +*/ +static inline unsigned long vm_commit_limit () +{ +return ((totalram_pages -hugetlb_total_pages ()) + * sysctl_overcommit_ratio /100 ) + total_swap_pages; +}
Not sure I like this part much. This function is large and slow and doesn't merit inlining, plus it requires worsening our nested-include mess. This?
Also, it should be vm_commit_limit(void).
From: Andrew Morton <[email protected]>
Subject: mm-factor-commit-limit-calculation-fix
---
include/linux/mman.h | 12 +----------- mm/mmap.c | 9 +++++++++ 2 files changed, 10 insertions(+), 11 deletions(-)
diff -puN fs/proc/meminfo.c~mm-factor-commit-limit-calculation-fix fs/proc/meminfo.c
include/linux/mman.h renamed from include/linux/mman.h~mm-factor-commit-limit-calculation-fix +1 -11
@@ -7,9 +7,6 @@#include <linux/atomic.h> #include <uapi/linux/mman.h> -#include <linux/hugetlb.h> -#include <linux/swap.h> -extern int sysctl_overcommit_memory;extern int sysctl_overcommit_ratio;extern struct percpu_counter vm_committed_as;
@@ -91,12 +88,5 @@ calc_vm_flag_bits(unsigned long flags) _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED ); } -/* -* Commited memory limit enforced when OVERCOMMIT_NEVER policy is used -*/ -static inline unsigned long vm_commit_limit () -{ -return ((totalram_pages -hugetlb_total_pages ()) - * sysctl_overcommit_ratio /100 ) + total_swap_pages; -} +unsigned long vm_commit_limit (void );#endif /* _LINUX_MMAN_H */
mm/mmap.c renamed from mm/mmap.c~mm-factor-commit-limit-calculation-fix +9 -0
@@ -110,6 +110,15 @@ unsigned long vm_memory_committed(void)EXPORT_SYMBOL_GPL (vm_memory_committed);/* +* Commited memory limit enforced when OVERCOMMIT_NEVER policy is used +*/ +unsigned long vm_commit_limit (void ) +{ +return ((totalram_pages -hugetlb_total_pages ()) + * sysctl_overcommit_ratio /100 ) + total_swap_pages; +} + +/* * Check that a process has enough memory to allocate a new virtual * mapping. 0 means there is enough memory for the allocation to * succeed and -ENOMEM implies there is not.
diff -puN mm/nommu.c~mm-factor-commit-limit-calculation-fix mm/nommu.c diff -puN mm/util.c~mm-factor-commit-limit-calculation-fix mm/util.c diff -puN include/linux/mm.h~mm-factor-commit-limit-calculation-fix include/linux/mm.h _
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>