Re: Memory overcommitting (was Re: http://www.redhat.com/redhat/)

Andi Kleen (andi@mlm.extern.lrz-muenchen.de)
22 Feb 1997 19:10:33 +0100


Eric Youngdale <eric@andante.jic.com> writes:

> >One thing that is missing in Linux is the possibility to *disable* the
> >overcommitment, which is very usefull for some applications...
>
> Agreed. I also agree that we should at least have the option
> to disable overcommitment for those people who feel that they need it.

Linux 2.0 doesn't allow overcommitment. The algorithm to detect it
is not 100% fool proof but it works in most of the cases. Some people
need overcommitment to run their Fortran programs.

I did a patch to allow overcommitment in 2.0.x (should work with 2.1.x
too).

-Andi

--- linux/mm/mmap.c-orig Sat Jul 20 21:40:42 1996
+++ linux/mm/mmap.c Sat Jul 20 21:40:48 1996
@@ -41,6 +41,8 @@
__S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
};

+int sysctl_overcommit_memory;
+
/*
* Check that a process has enough memory to allocate a
* new virtual mapping.
@@ -53,6 +55,11 @@
* fool it, but this should catch most mistakes.
*/
long freepages;
+
+ /* sometimes we want to use more memory than we have. */
+ if (sysctl_overcommit_memory)
+ return 1;
+
freepages = buffermem >> PAGE_SHIFT;
freepages += page_cache_size;
freepages >>= 1;
--- linux/kernel/sysctl.c-orig Sat Jul 20 21:43:09 1996
+++ linux/kernel/sysctl.c Sat Jul 20 22:09:26 1996
@@ -99,6 +99,7 @@
void *, size_t, void **);

extern char binfmt_java_interpreter[], binfmt_java_appletviewer[];
+extern int sysctl_overcommit_memory;

/* The default sysctl tables: */

@@ -161,6 +162,8 @@
{VM_BDFLUSH, "bdflush", &bdf_prm, 9*sizeof(int), 0600, NULL,
&proc_dointvec_minmax, &sysctl_intvec, NULL,
&bdflush_min, &bdflush_max},
+ {VM_OVERCOMMIT_MEMORY, "overcommit_memory", &sysctl_overcommit_memory,
+ sizeof(sysctl_overcommit_memory), 0644, NULL, &proc_dointvec},
{0}
};

--- linux/include/linux/sysctl.h-orig Sat Jul 20 21:45:54 1996
+++ linux/include/linux/sysctl.h Sat Jul 20 21:45:56 1996
@@ -68,6 +68,7 @@
#define VM_FREEPG 3 /* struct: Set free page thresholds */
#define VM_BDFLUSH 4 /* struct: Control buffer cache flushing */
#define VM_MAXID 5
+#define VM_OVERCOMMIT_MEMORY 7 /* allow mmaps/sbrk larger than memory+swap */

/* CTL_NET names: */
#define NET_CORE 1