Skip to content

Commit 49f0ce5

Browse files
jeromemarchandtorvalds
authored andcommitted
mm: add overcommit_kbytes sysctl variable
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. [akpm@linux-foundation.org: coding-style fixes] [akpm@linux-foundation.org: fix nommu build] Signed-off-by: Jerome Marchand <jmarchan@redhat.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent aec6a88 commit 49f0ce5

8 files changed

Lines changed: 70 additions & 8 deletions

File tree

‎Documentation/sysctl/vm.txt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Currently, these files are in /proc/sys/vm:
4747
- numa_zonelist_order
4848
- oom_dump_tasks
4949
- oom_kill_allocating_task
50+
- overcommit_kbytes
5051
- overcommit_memory
5152
- overcommit_ratio
5253
- page-cluster
@@ -574,6 +575,17 @@ The default value is 0.
574575

575576
==============================================================
576577

578+
overcommit_kbytes:
579+
580+
When overcommit_memory is set to 2, the committed address space is not
581+
permitted to exceed swap plus this amount of physical RAM. See below.
582+
583+
Note: overcommit_kbytes is the counterpart of overcommit_ratio. Only one
584+
of them may be specified at a time. Setting one disables the other (which
585+
then appears as 0 when read).
586+
587+
==============================================================
588+
577589
overcommit_memory:
578590

579591
This value contains a flag that enables memory overcommitment.

‎Documentation/vm/overcommit-accounting‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ The Linux kernel supports the following overcommit handling modes
1414

1515
2 - Don't overcommit. The total address space commit
1616
for the system is not permitted to exceed swap + a
17-
configurable percentage (default is 50) of physical RAM.
18-
Depending on the percentage you use, in most situations
17+
configurable amount (default is 50%) of physical RAM.
18+
Depending on the amount you use, in most situations
1919
this means a process will not be killed while accessing
2020
pages but will receive errors on memory allocation as
2121
appropriate.
@@ -26,7 +26,8 @@ The Linux kernel supports the following overcommit handling modes
2626

2727
The overcommit policy is set via the sysctl `vm.overcommit_memory'.
2828

29-
The overcommit percentage is set via `vm.overcommit_ratio'.
29+
The overcommit amount can be set via `vm.overcommit_ratio' (percentage)
30+
or `vm.overcommit_kbytes' (absolute value).
3031

3132
The current overcommit limit and amount committed are viewable in
3233
/proc/meminfo as CommitLimit and Committed_AS respectively.

‎include/linux/mm.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ extern int sysctl_legacy_va_layout;
5757
extern unsigned long sysctl_user_reserve_kbytes;
5858
extern unsigned long sysctl_admin_reserve_kbytes;
5959

60+
extern int sysctl_overcommit_memory;
61+
extern int sysctl_overcommit_ratio;
62+
extern unsigned long sysctl_overcommit_kbytes;
63+
64+
extern int overcommit_ratio_handler(struct ctl_table *, int, void __user *,
65+
size_t *, loff_t *);
66+
extern int overcommit_kbytes_handler(struct ctl_table *, int, void __user *,
67+
size_t *, loff_t *);
68+
6069
#define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
6170

6271
/* to align the pointer to the (next) page boundary */

‎include/linux/mman.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
extern int sysctl_overcommit_memory;
1111
extern int sysctl_overcommit_ratio;
12+
extern unsigned long sysctl_overcommit_kbytes;
1213
extern struct percpu_counter vm_committed_as;
1314

1415
#ifdef CONFIG_SMP

‎kernel/sysctl.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@
9595
#if defined(CONFIG_SYSCTL)
9696

9797
/* External variables not in a header file. */
98-
extern int sysctl_overcommit_memory;
99-
extern int sysctl_overcommit_ratio;
10098
extern int max_threads;
10199
extern int suid_dumpable;
102100
#ifdef CONFIG_COREDUMP
@@ -1121,7 +1119,14 @@ static struct ctl_table vm_table[] = {
11211119
.data = &sysctl_overcommit_ratio,
11221120
.maxlen = sizeof(sysctl_overcommit_ratio),
11231121
.mode = 0644,
1124-
.proc_handler = proc_dointvec,
1122+
.proc_handler = overcommit_ratio_handler,
1123+
},
1124+
{
1125+
.procname = "overcommit_kbytes",
1126+
.data = &sysctl_overcommit_kbytes,
1127+
.maxlen = sizeof(sysctl_overcommit_kbytes),
1128+
.mode = 0644,
1129+
.proc_handler = overcommit_kbytes_handler,
11251130
},
11261131
{
11271132
.procname = "page-cluster",

‎mm/mmap.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ EXPORT_SYMBOL(vm_get_page_prot);
8686

8787
int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
8888
int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
89+
unsigned long sysctl_overcommit_kbytes __read_mostly;
8990
int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
9091
unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
9192
unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */

‎mm/nommu.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ unsigned long highest_memmap_pfn;
6060
struct percpu_counter vm_committed_as;
6161
int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
6262
int sysctl_overcommit_ratio = 50; /* default is 50% */
63+
unsigned long sysctl_overcommit_kbytes __read_mostly;
6364
int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
6465
int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
6566
unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */

‎mm/util.c‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,45 @@ struct address_space *page_mapping(struct page *page)
404404
return mapping;
405405
}
406406

407+
int overcommit_ratio_handler(struct ctl_table *table, int write,
408+
void __user *buffer, size_t *lenp,
409+
loff_t *ppos)
410+
{
411+
int ret;
412+
413+
ret = proc_dointvec(table, write, buffer, lenp, ppos);
414+
if (ret == 0 && write)
415+
sysctl_overcommit_kbytes = 0;
416+
return ret;
417+
}
418+
419+
int overcommit_kbytes_handler(struct ctl_table *table, int write,
420+
void __user *buffer, size_t *lenp,
421+
loff_t *ppos)
422+
{
423+
int ret;
424+
425+
ret = proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
426+
if (ret == 0 && write)
427+
sysctl_overcommit_ratio = 0;
428+
return ret;
429+
}
430+
407431
/*
408432
* Committed memory limit enforced when OVERCOMMIT_NEVER policy is used
409433
*/
410434
unsigned long vm_commit_limit(void)
411435
{
412-
return ((totalram_pages - hugetlb_total_pages())
413-
* sysctl_overcommit_ratio / 100) + total_swap_pages;
436+
unsigned long allowed;
437+
438+
if (sysctl_overcommit_kbytes)
439+
allowed = sysctl_overcommit_kbytes >> (PAGE_SHIFT - 10);
440+
else
441+
allowed = ((totalram_pages - hugetlb_total_pages())
442+
* sysctl_overcommit_ratio / 100);
443+
allowed += total_swap_pages;
444+
445+
return allowed;
414446
}
415447

416448

0 commit comments

Comments
 (0)