All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J.A. Magallon" <jamagallon@able.es>
To: Ralf Hildebrandt <Ralf.Hildebrandt@charite.de>
Cc: linux-kernel@vger.kernel.org
Subject: Re: 2.4.20-aa and LARGE Squid process -> SIGSEGV
Date: Fri, 20 Dec 2002 23:37:54 +0100	[thread overview]
Message-ID: <20021220223754.GA10139@werewolf.able.es> (raw)
In-Reply-To: <20021220114837.GC13591@charite.de>; from Ralf.Hildebrandt@charite.de on Fri, Dec 20, 2002 at 12:48:37 +0100


On 2002.12.20 Ralf Hildebrandt wrote:
>Hi!
[real problem snipped]
>
>Then we wrote a program which allocates large amounts of memory:
>
>--- snip ---
>#include <stdlib.h>
>#include <stdio.h>
>
>main(){
>  char *buf;
>  long c;
>  FILE *fp;
>
>  fp = fopen("/dev/null","a");
>  while(1){
>    buf = (char *)malloc(100000000);
>    c = random();
>    if (c > 100000000)
>      continue;
>    fprintf(fp,"%c",buf[c]);
>    printf("hier\n");
>  }
>}
>--- snip ---
>
>And we found that this program will be killed with a SIGSEGV as well.
>

Normal. You are running OOM. Look at what you do:

    while (1)
    {
         malloc(much mem)
         // do not free the mem !!!!
    }

So in a couple steps you are OOM.

I suppose what you want to do is

    buf = malloc(...)
    while (1)
        touch random page

But...you 'touch' is read-only (the printf), so the page will never
really be allocated. Try with this:

#include <stdlib.h>

// 4Gb
#define SZ 4*1024*1024*1024

main(){
    char *buf;

    buf = malloc(SZ);
    if (!buf)
    {
        perror("bad try");
        exit(1);
    }
    while(1){
        buf[random()%SZ] = 0;
    }
}

Ah, with 2Gb of ram you will need to compile with 3Gb userspace,
to let a one only process allocate a chunk of mem that does not fit
into core memory. Or, easier, run several instances...

-- 
J.A. Magallon <jamagallon@able.es>      \                 Software is like sex:
werewolf.able.es                         \           It's better when it's free
Mandrake Linux release 9.1 (Cooker) for i586
Linux 2.4.20-jam2 (gcc 3.2 (Mandrake Linux 9.1 3.2-4mdk))

  reply	other threads:[~2002-12-20 22:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-20 11:48 2.4.20-aa and LARGE Squid process -> SIGSEGV Ralf Hildebrandt
2002-12-20 22:37 ` J.A. Magallon [this message]
2002-12-20 22:57   ` Ralf Hildebrandt
2002-12-21  0:13     ` J.A. Magallon
2002-12-21  7:52       ` Ralf Hildebrandt
2002-12-21  8:28         ` Reuben Farrelly
2002-12-21  9:06           ` Ralf Hildebrandt
2002-12-21  9:17             ` Reuben Farrelly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021220223754.GA10139@werewolf.able.es \
    --to=jamagallon@able.es \
    --cc=Ralf.Hildebrandt@charite.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.