Dennis Glatting <[EMAIL PROTECTED]> writes:
> On Monday 07 May 2001 08:10 am, Dag-Erling Smorgrav wrote:
> > malloc() will return NULL only if you hit a resource limit or exhaust
> > address space. There may or may not be memory (real or virtual)
> > available at that time.
> Isn't memory exhaustion a resource limit?
What is memory exhaustion?
Namespace exhaustion will cause malloc() to fail. But FreeBSD
overcommits memory, so exhaustion of physical and virtual memory will
manifest itself as an unsatisfiable page fault, which will cause the
kernel to start killing more-or-less-random processes until some
memory is available again.
> Explain the bug and malloc() behaviour. According to the malloc() man
The bug: I believe you meant "i -= j" when you wrote "i =- j". The
result is that i becomes negative and in all likelihood you smash the
Regarding malloc(), you seem to believe that malloc() allocates
*exactly* the amount you ask, no more, no less, and actually allocates
physical or virtual memory. It doesn't. First of all, it allocates
memory of its own for bookkeeping purposes, which your program doesn't
account for. Second, it usually allocates a little bit more than you
asked for, and keeps the leftovers for later. Third, it only
allocates namespace. Actual memory (physical or virtual) is allocated
by the kernel the first time you touch a page.
What's more, your program does extra stuff (such as needlessly fork()
/ exec()ing sync(1) instead of just calling sync(2), which doesn't
serve any purpose anyway, since virtual memory isn't managed by the
file system code, so sync(2) doesn't affect it) which consumes memory,
which further invalidates your results (for instance, memory
exhaustion while running sync(1) could cause the kernel to randomly
kill your program)
> I assert memory exhaustion is would return "unsuccessful" on the
> malloc() call, no?
No, just namespace exhaustion, which your program won't even come
Dag-Erling Smorgrav - [EMAIL PROTECTED]
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message