Re: http://www.redhat.com/redhat/ [Memory Overcommit]

Miguel de Icaza (miguel@nuclecu.unam.mx)
20 Feb 1997 17:26:15 -0600


> To whom it may concern:
>
> We are trying to do some software development on our machine
> that runs RedHat Linux (Intel - Pentium). One of the
> developers has asked me if there is any kind of fix for a
> problem with malloc. The problem seems to be that when you
> use the malloc command, you can allocate memory that is not
> available to allocate. Has anybody else reported this? If
> you need more information, I can get it to you.

I have the impression that the kernel was checking against memory
overcommit since some 1.3.xx kernel version, this is from the
mm/mmap.c file, function sys_brk:

/*
* Check if we have enough memory..
*/
if (!vm_enough_memory((newbrk-oldbrk) >> PAGE_SHIFT))
goto out;

Maybe the problem is in the vm_enough_memory routine:

/*
* Check that a process has enough memory to allocate a
* new virtual mapping.
*/
static inline 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.
*/
long freepages;
freepages = buffermem >> PAGE_SHIFT;
freepages += page_cache_size;
freepages >>= 1;
freepages += nr_free_pages;
freepages += nr_swap_pages;
freepages -= num_physpages >> 4;
return freepages > pages;
}

In any case, an easy fix (that does not require upgrading the kernel
to a probably fixed version) is to use malloc and then do a memset on
the region. Probably cmalloc can do this.

Cheers,
Miguel.

-- 
miguel@roxanne.nuclecu.unam.mx     
The GNU Midnight Commander: http://mc.blackdown.org/mc
Linux/SPARC project:        http://www.geog.ubc.ca/sparclinux.html