Patch: vm_enough_memory() (2.1.129)

Neil Conway (nconway.list@ukaea.org.uk)
Mon, 23 Nov 1998 17:26:35 +0000


This is a multi-part message in MIME format.
--------------9C4DE7CD857ABAA3E415AEB0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Here's my stab at a fix to the vm_enough_memory() function. This
currently underestimates available memory by large amounts (has been
wrong by over 200MB on my 512MB RAM + 512MB Swap machine).

It *tries* to do it the right way, but I'm no expert. In fact, it was
sufficiently easy to fix that I have a lingering suspicion that I've
missed the point.

I almost used si_meminfo() to find the actual number of *available*
physical pages, until I realised that the cache/buffers just use
num_physpages anyway for their lower/upper limits.

Neil
neil.conway@ukaea.org.uk
--------------9C4DE7CD857ABAA3E415AEB0
Content-Type: text/plain; charset=us-ascii; name="mmappatch.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="mmappatch.txt"

--- linux-2.1.129/mm/mmap.c.orig Mon Nov 16 22:19:11 1998
+++ linux-2.1.129/mm/mmap.c Mon Nov 23 16:54:58 1998
@@ -10,14 +10,15 @@
#include <linux/slab.h>
#include <linux/shm.h>
#include <linux/errno.h>
#include <linux/mman.h>
#include <linux/string.h>
#include <linux/pagemap.h>
#include <linux/swap.h>
+#include <linux/swapctl.h>
#include <linux/smp.h>
#include <linux/smp_lock.h>
#include <linux/init.h>
#include <linux/file.h>

#include <asm/uaccess.h>
#include <asm/system.h>
@@ -53,26 +54,31 @@
*/
int vm_enough_memory(long pages)
{
/* Stupid algorithm to decide if we have enough memory: while
* simple, it hopefully works in most obvious cases.. Easy to
* fool it, but this should catch most mistakes.
*/
+ /* 23/11/98 NJC: Somewhat less stupid version of algorithm,
+ * which tries to do "TheRightThing". Instead of using half of
+ * (buffers+cache), use the minimum values. Allow an extra 2%
+ * of num_physpages for safety margin.
+ */
+
long free;

/* Sometimes we want to use more memory than we have. */
if (sysctl_overcommit_memory)
return 1;

free = buffermem >> PAGE_SHIFT;
free += page_cache_size;
- free >>= 1;
free += nr_free_pages;
free += nr_swap_pages;
- free -= num_physpages >> 4;
+ free -= (page_cache.min_percent + buffer_mem.min_percent + 2)*num_physpages/100;
return free > pages;
}

/* Remove one vm structure from the inode's i_mmap ring. */
static inline void remove_shared_vm_struct(struct vm_area_struct *vma)
{
struct file * file = vma->vm_file;

--------------9C4DE7CD857ABAA3E415AEB0--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/