lkml.org 
[lkml]   [1996]   [Dec]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: memory crash

On Wed, 11 Dec 1996, Alan Cox wrote:

> > this. When a process is allocated memory, the initial memory comes from
> > a pool of shared zero-filled pages. These pages don't actually get
> > owned by a specific process until a process actually writes to one.
>
> So does linux

Hmm, so it seems. I just touched up that guy's little test program and
sure enough, reading from an unallocated page does not allocate a page (I
thought it did; wrong).

I would think a quick check of algorithms to be sure they did not
actually assign zeroes to arrays, and all should be fine?

I also got a curious result with the test program. I could malloc up to
6 megs of memory, but at 8 meg, malloc failed. Is malloc() using the
stack (which is the only thing limited to 8 meg)?

Result:
> ./memory
total used free shared buffers cached
Mem: 14916 11776 3140 2656 3584 6328
-/+ buffers: 1864 13052
Swap: 0 0 0
malloc(8388608) failed


Here is the slightly modified program:
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
char *buff;
char y;
long i;
long max = 1024*1024*8 /* 64 */;
system("free");

buff = malloc(max);
if( NULL == buff) {printf("malloc(%ld) failed\n", max); return 1;}

for(i=0; i<max; i+=4096) { y=buff[i]; printf(" %2x ", y); }
printf("\n");

system("free");

free( buff );
return 0;
}


--
William Burrow -- Fredericton Area Network, New Brunswick, Canada
Copyright 1996 William Burrow
Canada's federal regulator says it may regulate content on the Internet to
provide for more Canadian content. (Ottawa Citizen 15 Nov 96 D15)



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