Re: Recursive malloc crashing Linux. (Well almost)

John Ripley (john@empeg.com)
Sat, 18 Dec 1999 00:43:19 +0000 (GMT)


This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.

--17434625-494112617-945477799=:19403
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Fri, 17 Dec 1999, Giuliano Pochini wrote:

> > # ./killmem
> > Allocating 256 amounts of 4MB == 1024MB
> > Successful
> > Filling block 0
> > Filling block 1
> > killmem: memory violation at pc=0x0200047c, lr=0x4005f7d8 (bad address=0x4065d000, code 1)
> > Bus error
> >
> > Which is kind of not very graceful. On my PC, 128MB ram, ~133MB swap, it
> > gets as far as block 34 (136MB) before causes a complete lockup (not even
> > magic sysrq works) - which is also not very graceful.
>
> It seems to crash when it tries to expand the stack and there is no available
> mem. If you try:
>
> while(1){
> malloc(256K);
> fill;
> }
>
> the program will be killed. But an infinite recurse will crash even if you
> don't malloc anything.

Sorry but this isn't my program you're describing --

My program (killmem.c, attached) doesn't recurse.

It allocates (in a loop) lots of memory in 4MB chunk mmaps. (1GB total)
It then fills each chunk one at a time until it dies.
This demonstrates the ability to allocate far more memory than is
available, and subsequently die when accessing it. This is overcommit,
even when overcommit is turned off.

Allocating memory in a single 1GB chunk fails gracefully, but allocating
in 4MB chunks works until you access it.

- John Ripley.

--17434625-494112617-945477799=:19403
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="killmem.c"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.04.9912180043190.19403@fatboy.internal.empeg.com>
Content-Description:
Content-Disposition: attachment; filename="killmem.c"

I2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8dW5pc3RkLmg+DQojaW5j
bHVkZSA8c3lzL21tYW4uaD4NCg0KI2RlZmluZSBOQlVGUwkJMjU2DQojZGVm
aW5lIE1NQVBfU0laRQkoNCoxMDQ4NTc2KQ0KDQptYWluKCkNCnsNCiAgICBp
bnQgaSwgajsNCiAgICBjaGFyICpidWZbTkJVRlNdLCAqcDsNCg0KICAgIHBy
aW50ZigiQWxsb2NhdGluZyAlZCBhbW91bnRzIG9mICVkTUIgPT0gJWRNQlxu
IiwNCgkgICBOQlVGUywgTU1BUF9TSVpFID4+IDIwLCAoTU1BUF9TSVpFID4+
IDIwKSAqIE5CVUZTKTsNCiAgICANCiAgICBmb3IoaT0wOyBpPE5CVUZTOyBp
KyspIHsNCglidWZbaV0gPSAoY2hhciAqKQ0KCSAgICBtbWFwKDAsIDQwOTYq
MTAyNCwgUFJPVF9SRUFEfFBST1RfV1JJVEUsDQoJCSBNQVBfQU5PTllNT1VT
fE1BUF9QUklWQVRFLCAtMSwgMCk7DQoJaWYoYnVmW2ldID09IE1BUF9GQUlM
RUQpIHsNCgkgICAgcHJpbnRmKCJGYWlsZWQgZm9yIGJsb2NrICVkXG4iLCBp
KTsNCgkgICAgcmV0dXJuIDE7DQoJfQ0KICAgIH0NCg0KICAgIHByaW50Zigi
U3VjY2Vzc2Z1bFxuIik7DQogICAgDQogICAgZm9yKGk9MDsgaTxOQlVGUzsg
aSsrKSB7DQoJcHJpbnRmKCJGaWxsaW5nIGJsb2NrICVkXG4iLCBpKTsNCgkN
CglwID0gYnVmW2ldOw0KCWZvcihqPU1NQVBfU0laRTsgajsgai0tKSAqcCsr
ID0gMDsNCiAgICB9DQoNCiAgICBwcmludGYoIkRvbmVcbiIpOw0KfQ0K
--17434625-494112617-945477799=:19403--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/