lkml.org 
[lkml]   [1998]   [Aug]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Small problem with malloc() tested on 2.1.117/115 (and maybe affecting others)
On Sat, 22 Aug 1998, Division by Zero wrote:

> I have found that when I malloc() memory and do not access it/clear it,
> I can malloc() a very large amount (around 2 gigabytes). I only have
> around 170 MB in swap and ram. If I immediately memset() after each

This is standard Unix semantics, read 'man 2 brk' for more info.
One of the purposes of this is to support sparse datasets and to
make sure that overruns don't scrabble over other data (some
malloc() implementations leave free space between allocations and
mprotect that so we can catch overruns).

> malloc(), I have found that malloc will properly return NULL when it
> cannot allocate more. Now the problem comes when I allocate all 2
> gigabytes, then after all that I loop again to memset() them. When it
> reaches beyond the bound of available ram, I find that my computer slows
> to a near halt (even running as normal user).

I have a patch out that kills the most 'bad' program when we run
out of memory. You already have it if you subscribe to linux-kernel,
otherwise you can use one of the linux-kernel archives to look it
up.

> I'm not sure how much of a bug this could really be considered, but

IMHO, it's somewhere halfway between a bug and a feature. The
benefits seem to outweigh the disadvantages however.

> usually when I malloc() I expect that I will have that memory there
> (assuming it did not return NULL) to use and will not have to worry
> about writing out into oblivion.

Strictly speaking, malloc(3) isn't even a kernel issue :-)
All libc does is ask for extension of the address space it
can use for the data segment. That doesn't have to mean
"I want to use this memory", instead it usually means "I
want to use some memory in this address range".

Rik.
+-------------------------------------------------------------------+
| Linux memory management tour guide. H.H.vanRiel@phys.uu.nl |
| Scouting Vries cubscout leader. http://www.phys.uu.nl/~riel/ |
+-------------------------------------------------------------------+


-
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.altern.org/andrebalsa/doc/lkml-faq.html

\
 
 \ /
  Last update: 2005-03-22 13:44    [W:2.088 / U:1.472 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site