This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Controlling the garbage collector (GC) at RT?


Hi Hans and Chris (and whomever),

It would indeed be interesting to know why the Linux kernel kills
the application rather than returning failure.
According to 'man malloc' on a linux box (Debian 3.1):
BUGS
By default, Linux follows an optimistic memory allocation strategy.
This means that when malloc() returns non-NULL there is no guarantee
that the memory really is available. This is a really bad bug. In case
it turns out that the system is out of memory, one or more processes
will be killed by the infamous OOM killer. In case Linux is employed
under circumstances where it would be less desirable to suddenly lose
some randomly picked processes, and moreover the kernel version is suf-
ficiently recent, one can switch off this overcommitting behavior using
a command like
# echo 2 > /proc/sys/vm/overcommit_memory
See also the kernel Documentation directory, files vm/overcommit-
accounting and sysctl/vm.txt.
The man page is dated 1993-04-04, but I have also seen man pages dated "April 4, 1993" which have a completely different text. So it's not easy to determine what kernel/glibc version is required - experiment and see.
There certainly is a difference in behaviour - however, none of which
does the "correct".

Hans, you asked for the output. Below here it is - depending on the
"overcommit"-strategy chosen. There is obviously difference in
behaviour, between the default (0) and either 1 or 2, but the
application is still terminated.
(The application just allocates and stores additional 10000 bytes
forever until terminated.)

===================
=== 0 (default) ===
===================
# echo 0 > /proc/sys/vm/overcommit_memory
# ./mem3
*** MEM CHUNK TAKEN: 98304
*** MEM CHUNK TAKEN: 131072
*** MEM CHUNK TAKEN: 176128
*** MEM CHUNK TAKEN: 233472
*** MEM CHUNK TAKEN: 311296
*** MEM CHUNK TAKEN: 417792
*** MEM CHUNK TAKEN: 557056
*** MEM CHUNK TAKEN: 741376
*** MEM CHUNK TAKEN: 987136
*** MEM CHUNK TAKEN: 1318912
*** MEM CHUNK TAKEN: 1757184
*** MEM CHUNK TAKEN: 2342912
*** MEM CHUNK TAKEN: 3125248
*** MEM CHUNK TAKEN: 4165632
*** MEM CHUNK TAKEN: 5554176
*** MEM CHUNK TAKEN: 7405568
*** MEM CHUNK TAKEN: 8388608
*** MEM CHUNK TAKEN: 8388608
*** MEM CHUNK TAKEN: 8388608
*** MEM CHUNK TAKEN: 65536
*** MEM CHUNK TAKEN: 65536
=== last message repeated 20-30 times ===
Terminated

Kernel messages:
Out of Memory: Killed process 92 (mem3).
Out of Memory: Killed process 93 (mem3).
Out of Memory: Killed process 94 (mem3).

=========
=== 1 ===
=========
# echo 1 > /proc/sys/vm/overcommit_memory
# ./mem3
*** MEM CHUNK TAKEN: 98304
*** MEM CHUNK TAKEN: 131072
*** MEM CHUNK TAKEN: 176128
*** MEM CHUNK TAKEN: 233472
*** MEM CHUNK TAKEN: 311296
*** MEM CHUNK TAKEN: 417792
*** MEM CHUNK TAKEN: 557056
*** MEM CHUNK TAKEN: 741376
*** MEM CHUNK TAKEN: 987136
*** MEM CHUNK TAKEN: 1318912
*** MEM CHUNK TAKEN: 1757184
*** MEM CHUNK TAKEN: 2342912
*** MEM CHUNK TAKEN: 3125248
*** MEM CHUNK TAKEN: 4165632
*** MEM CHUNK TAKEN: 5554176
*** MEM CHUNK TAKEN: 7405568
*** MEM CHUNK TAKEN: 8388608
*** MEM CHUNK TAKEN: 8388608
*** MEM CHUNK TAKEN: 8388608
*** MEM CHUNK TAKEN: 8388608
Terminated
#

Out of Memory: Killed process 128 (mem3).
Out of Memory: Killed process 129 (mem3).
Out of Memory: Killed process 130 (mem3).

=========
=== 2 ===
=========
# echo 2 > /proc/sys/vm/overcommit_memory
# ./mem3
*** MEM CHUNK TAKEN: 98304
*** MEM CHUNK TAKEN: 131072
*** MEM CHUNK TAKEN: 176128
*** MEM CHUNK TAKEN: 233472
*** MEM CHUNK TAKEN: 311296
*** MEM CHUNK TAKEN: 417792
*** MEM CHUNK TAKEN: 557056
*** MEM CHUNK TAKEN: 741376
*** MEM CHUNK TAKEN: 987136
*** MEM CHUNK TAKEN: 1318912
*** MEM CHUNK TAKEN: 1757184
*** MEM CHUNK TAKEN: 2342912
*** MEM CHUNK TAKEN: 3125248
*** MEM CHUNK TAKEN: 4165632
*** MEM CHUNK TAKEN: 5554176
*** MEM CHUNK TAKEN: 7405568
*** MEM CHUNK TAKEN: 8388608
*** MEM CHUNK TAKEN: 8388608
*** MEM CHUNK TAKEN: 8388608
*** MEM CHUNK TAKEN: 8388608
Terminated
#

Out of Memory: Killed process 132 (mem3).
Out of Memory: Killed process 133 (mem3).
Out of Memory: Killed process 134 (mem3).





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]