From: Jie Zhang <jzhang918@gmail.com>
To: "linux-os (Dick Johnson)" <linux-os@analogic.com>
Cc: Linux kernel <linux-kernel@vger.kernel.org>, lars.friedrich@wago.com
Subject: Re: Question on the current behaviour of malloc () on Linux
Date: Thu, 22 Dec 2005 15:21:11 +0800 [thread overview]
Message-ID: <6f48278f0512212321w3dd39ca6ldb1c814c6322127@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.61.0512211259090.12113@chaos.analogic.com>
On 12/22/05, linux-os (Dick Johnson) <linux-os@analogic.com> wrote:
>
> On Wed, 21 Dec 2005, Jie Zhang wrote:
>
> > Hi,
> >
> > I first asked this question on uClinux mailing list. My first question
> > is <http://mailman.uclinux.org/pipermail/uclinux-dev/2005-December/036042.html>.
> > Although I found this issue on uClinux, it's also can be demostrated
> > on Linux. This is a small program:
> >
>
> Another FAQ....
>
> > $> cat test2.c
> > #include <stdio.h>
> > #include <stdlib.h>
> >
> > int
> > main ()
> > {
> > char *p;
> > int i, j;
> > for (i = 0;; i++)
> > {
> > p = (char *) malloc (8 * 1024 * 1024);
> > if (p)
> > for (j = 0; j < 8 * 1024 * 1024; j++)
> > p[j] = 0x55;
> > else
> > {
> > printf ("%d fail\n", i);
> > break;
> > }
> > }
> > return 0;
> > }
> >
> > When I run it on my Linux notebook, it will be killed. I expect to see
> > it prints out "fail".
>
> Your expectations are not based upon any logic, only wishes.
>
According to SuSv3, I think my expectation is completely based upon
logic. Actually, overcommitting is based upon wishes I think. It
wishes application not use all the memory it allocated.
>
>
> To make your wishes come true execute:
> echo "1" >/proc/sys/vm/overcommit_memory
> ... as a super-user.
>
> That will make malloc() fail when there isn't any more virtual
> memory.
That's what I'm looking for. Thanks.
Jie
prev parent reply other threads:[~2005-12-22 7:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-21 17:36 Jie Zhang
2005-12-21 17:39 ` Arjan van de Ven
2005-12-21 18:05 ` Jesper Juhl
2005-12-21 18:07 ` Jesper Juhl
2005-12-22 7:15 ` Jie Zhang
2005-12-21 18:06 ` linux-os (Dick Johnson)
2005-12-21 19:00 ` Jesper Juhl
2005-12-22 7:21 ` Jie Zhang [this message]
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=6f48278f0512212321w3dd39ca6ldb1c814c6322127@mail.gmail.com \
--to=jzhang918@gmail.com \
--cc=lars.friedrich@wago.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-os@analogic.com \
/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®