Re: Overcommitable memory??

From: James Sutherland (jas88@cam.ac.uk)
Date: Fri Mar 17 2000 - 05:08:50 EST


On Fri, 17 Mar 2000, David Whysong wrote:

> On Fri, 17 Mar 2000, James Sutherland wrote:
> >On Fri, 17 Mar 2000, David Whysong wrote:
> >
> >> So malloc() returns success when I ask for an 800 megabyte array on a
> >> machine with only ~640 megabytes of free virtual memory.
> >
> >It's not supposed to do that, AIUI - malloc() will only succeed if either
> >(a) overcommit_memory is enabled (which disables all sanity checking - you
> >want 2Gb on a 4Mb 386? Here it is...) OR (b) the system stands a *chance*
> >of successfully allocating it (i.e. it has the amount you requested free).
>
> That's more or less what it does (see below). The problem is, what do you
> mean by "free" memory? -- there are several ways to measure this, none of
> which are all that useful.

Well, the kernel's definition is:
free = (buffermem >> PAGE_SHIFT) + (page_cache_size + nr_free_pages +
        nr_swap_pages) - (page_cache.min_percent + buffer_mem.min_percent
        +2)*num_physpages/100;

It then returns (free > pages), where pages was the number of pages
requested. (If sysctl_overcommit_memory is non-zero, it ALWAYS returns 1,
bypassing the above checks.)

In other words, it works out (roughly) how much VM is "available", and
checks whether you have requested less than that amount.

> >It doesn't ALLOCATE that memory to you immediately - but it is supposed to
> >check that it could do, if needed. (So the source appears to indicate,
> >anyway.)
>
> I'm not looking at the kernel source (big mistake in this mailing list, I
> know...), I'm looking at it from an app developer's point of view. From my
> experiments, it seems that with /proc/sys/vm/overcommit_memory=0, malloc()
> will succeed so long as you ask for less than the total RAM+swap on the
> machine. If overcommit_memory=1 anything goes.

Close - but it's not the TOTAL RAM+swap, it's the FREE RAM+swap. Your
experiment indicated you had managed to malloc() more than this, though,
even with sysctl_overcommit_memory == 0?

James.

-
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/



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