mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wolfgang Wander <wwc@rentec.com>
To: linux-kernel@vger.kernel.org
Subject: Re: Leaks in mmap address space: 2.6.11.4
Date: Fri, 15 Apr 2005 17:54:38 -0400	[thread overview]
Message-ID: <16992.14366.232980.673857@gargle.gargle.HOWL> (raw)
In-Reply-To: <200504151646.j3FGkLQ00256@troll.rentec.com>

Here is another program that illustrates the problem which this time
in C and without using glibc allocation schemes.

----------------------------------------------------------------------
/* run in 32 bit mode on 64Bit kernel, >4GB of RAM is helpful */

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>

#define bsz 600         /* number of mmaps to keep */
#define large 9500000   /* some odd large number */
#define success 1000000 /* number of iterations before we believe we are ok*/

                        /* program fails here on 2.6.11.4 kernel after 52K iterations 
                           with a fragmented /proc/self/mmap, 2.4 kernels behave fine */
void
aLLocator()
{

  char* bvec[bsz];
  unsigned int i;
  memset( bvec,0,sizeof(bvec));
	 
  for(  i = 0; i < success ; ++i ) {
    unsigned oidx;
    unsigned kidx;
    int len;
    kidx = i % bsz;
    oidx = (i+bsz/10) % bsz;
    len = (oidx & 7) ? ((oidx&7)* 1048576) : large;
    if( bvec[oidx] ) { munmap( bvec[oidx], len ); bvec[oidx] = 0; }
    len = (kidx & 7) ? ((kidx&7)* 1048576) : large;
    bvec[kidx] = (char*)(mmap(0, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0));
    if( bvec[kidx] == (char*)(-1) ) {
      printf("Failed after %d rounds\n", i);
      break;
    }
  }
}

int main() {
  FILE *f;
  int c;

  aLLocator();

  f = fopen( "/proc/self/maps", "r" );
  while( (c = fgetc(f)) != EOF )
    putchar(c);
  fclose(f);
  
  return 0;
}
----------------------------------------------------------------------

Wolfgang Wander writes:
 > Hi,
 > 
 >   we are running some pretty large applications in 32bit mode on 64bit
 >   AMD kernels (8GB Ram, Dual AMD64 CPUs, SMP).  Kernel is 2.6.11.4 or
 >   2.4.21.
 > 
 >   Some of these applications run consistently out of memory but only
 >   on 2.6 machines.  In fact large memory allocations that libc answers
 >   with private mmaps seem to contribute to the problem: 2.4 kernels
 >   are able to combine these mmaps to large chunks whereas 2.6
 >   generates a rather fragmented /proc/self/maps table.
 > 
 >   The following C++ program reproduces the error (compiled statically
 >   on a 32bit machine to get exactly the same executable for 2.4 and
 >   2.6 environments):

  reply	other threads:[~2005-04-15 21:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-15 16:46 Wolfgang Wander
2005-04-15 21:54 ` Wolfgang Wander [this message]
2005-04-21 14:49   ` Avoiding maps fragmentation Was: " Wolfgang Wander

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=16992.14366.232980.673857@gargle.gargle.HOWL \
    --to=wwc@rentec.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

all inboxes | Powered by JetHome®