-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

Caldarale, Charles R wrote:
>> From: Christopher Schultz [mailto:[EMAIL PROTECTED] 
>> Hmm.... perhaps I have a virtual memory limit. I have 1GB 
>> of physical RAM. While allocating a 3GB heap is pretty 
>> stupid for me, I still ought to be able to do it.
> 
> If your OS will allow, yes you should.  You may need to increase your
> swap file space, and you may burn out your hard drive thrashing pages in
> and out.

I think I just did using this little beauty:

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

/* 50 MB */
#define CHUNK_SIZE (1024 * 1024 * 50)

int main(int argc, char *arvg[])
{
  void *ptr;
  int i;
  unsigned long bytes = 0l;

  for( ; ;) {
    ptr = calloc((size_t)CHUNK_SIZE, (size_t)1);
    bytes += CHUNK_SIZE;

    /* write to our new memory */
    for(i=0; i<CHUNK_SIZE; ++i)
      *((char*)ptr + i) = (char)i;

    printf("Heap has now allocated %lu bytes\n", bytes);

    if(bytes > (unsigned long)(1024 * 1024 * 1024 * 3.9))
      fgetc(stdin);
  }
}

Oddly enough, it stopped printing stuff out after 1677721600 bytes.
Before I added the "write to our memory" loop, it ran very quickly and
completed (well, the fgetc was to pause so I could observe memory
usage). I guess that Linux not only does optimistic malloc, but also
optimistic calloc as well. I had hoped that zeroing-out the memory would
count as a "write", but apparently it does not.

Anyhow, I believe I'm running out of swap in this situation. I think I
only have a gig of swap on this development machine, which means that I
have a hard limit of 2GB anyway.

Anyone care to try this program on their many-gigabyted development box?

>> My ulimit man page sucks. Anyone know how to change the virtual memory
>> limits on Linux 2.6?
> 
> Here's a link for SUSE:
> http://en.opensuse.org/SDB:Ulimit_for_Protection_Against_%22Out_of_memor
> y%22

Thanks for the link. Probably won't help me with my 1GB of virtual
memory. Heh.

>> If the heap can grow and shrink, then how can the VM hope to 
>> get one bigass memory chunk for the heap?
> 
> The JVM reserves - but does not commit - the -Xmx size during
> initialization.  If that's not available, the JVM won't start.  Once
> allocated, commits and decommits occur to expand and shrink the in-use
> size.

Aah, I see. So the heap is actually fixed (to the maximum value) but the
internal management of the heap will fluctuate.

>> Still, the only remaining reason that 2GB+ wouldn't work is
>> because of a (potential) 2GB contiguous memory allocation 
>> restriction. I see no such restriction in the malloc or brk
>> man pages on my system.  What gives?
> 
> Those are typically generic descriptions aimed at application
> programmers.  What we're discussing here is OS internals, and you'll
> rarely see those documented anywhere.  If you're lucky, the OS vendor
> will have such limitiations squirreled away in some appendix to its
> installation guide.

Well, since this is Linux, there really isn't an operating guide. I
suppose the man pages couldn't include that information, anyway, since
it's a kernel setting chosen at kernel build-time. But, the GNU malloc
man page does describe the "OOM killer" behavior exhibited by Linux
kernels (under certain configurations). I had expected that this other
issue might have been covered as well.

I still can't find any documentation about a 2GB contiguous allocation
limit for Linux anywhere. Is this just "common knowledge" that nobody
has bothered to verify?

I mean, this is entirely academic at this point, but it would be nice to
actually know the truth instead of everyone just posting their 5th-hand
repeated guesses.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF+BYu9CaO5/Lv0PARAhZGAKC1u/BtCWSdI6eIGeBuH5qXtD1JZQCfTTPw
DaJRF41SVbVFJMBgfozB3lA=
=qd9B
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to