Re: Overcomittable memory

From: Andreas Bombe (
Date: Thu Mar 16 2000 - 13:11:24 EST

On Wed, Mar 15, 2000 at 04:00:42PM +0100, Rask Ingemann Lambertsen wrote:
> Den 14-Mar-00 00:06:14 skrev bert hubert følgende om "Re: Overcomittable memory (Was: Linux 2.2.15pre12)":
> > On Mon, Mar 13, 2000 at 12:13:37PM +0000, Paul Jakma wrote:
> [cut programs not reacting appropriately to malloc() returning NULL)
> >> then they should be fixed...
> > Most of the time there is no proper way to deal with OOM. Being really out
> > of memory probably means that you can't format your error message for
> > example.
> Well, guess what, then you won't get any error message, unless you were
> clever enough to have allocated a string buffer previously.

Allocated and touched.

        int i;
        char *ptr = malloc(1024);

        if (!ptr) thats_tough();

        for (i = 0; i < 1024; i++) ptr[i] = 0;

Only then you can be sure that this memory is there, because malloc
gave you a pointer and the for loop didn't get you killed. This works
because we sabotage COW through this, forcing a copy of the global COW
zero page[1] if the malloc returns newly allocated pages (and doesn't
reuse existing ones, in which case memory is there already). And you
should also touch your stack, while you're at it.

[1] In the case of the global zero page it's not a real copy, Linux
    just clears the allocated page.

          Andreas E. Bombe <>                DSA key 0x04880A44

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to Please read the FAQ at

This archive was generated by hypermail 2b29 : Thu Mar 23 2000 - 21:00:19 EST