public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Pachev <sasha@mysql.com>
To: linux-kernel@vger.kernel.org
Subject: memory allocation mystery
Date: Fri, 6 Jul 2001 16:59:28 -0600	[thread overview]
Message-ID: <0107061659281B.17811@mysql> (raw)

Hello,

I have been investigating kernel behavior ( I am running 2.4.3) in out of 
memory conditions with swap completely disabled and discovered a rather 
interesting behavior. If you run the following code:

#include <stdio.h>
#include <stdlib.h>

#define LEAK_BLOCK (1024*1024)
#define MB (1024*1024)

int main()
{
  unsigned long total = 0;
  for (;;)
  {
    char* p, *p_end;
    if(!(p=malloc(LEAK_BLOCK)))
    {
      fprintf(stderr, "malloc() failed\n");
      exit(1);
    }
    p_end = p + LEAK_BLOCK;
    while(p < p_end)
      *p++ = 0;
    total += LEAK_BLOCK;
    printf("Allocated %d MB\n", total/MB);
  }
  
  return 0;   
}


the process eventually gets killed by the kernel, rather than getting an 
error from malloc() as you would logically expect

I have straced the process and see just a bunch of old_mmap() calls like this:

old_mmap(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 
0)
= 0x46b6a000

( in addition to writes to stdout, of course). So it looks like old_mmap() 
never returns an error.

Can somebody explain this behavior? To me it looks like a bug...

-- 
MySQL Development Team
For technical support contracts, visit https://order.mysql.com/
   __  ___     ___ ____  __ 
  /  |/  /_ __/ __/ __ \/ /   Sasha Pachev <sasha@mysql.com>
 / /|_/ / // /\ \/ /_/ / /__  MySQL AB, http://www.mysql.com/
/_/  /_/\_, /___/\___\_\___/  Provo, Utah, USA
       <___/                  

                 reply	other threads:[~2001-07-06 22:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=0107061659281B.17811@mysql \
    --to=sasha@mysql.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox