I thought this my interest the Group
----- Original Message -----
From: "Ian Bruntlett" <[EMAIL PROTECTED]>
To: "Richard Downer" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, September 11, 2003 6:17 PM
Subject: Re: [edlug] Running out of memory gracefully. > Hi Richard, > > On Monday 08 September 2003 11:09 pm, Richard Downer wrote: > > I'm feeling in a technical mood. I'll have a go at answering this. > [snip] > > Linux does "overcommit" on memory. This is because the amount of "free > > memory" available is not as easy to calculate as you might think. > > > Linux has a feature called shared copy-on-write memory. It's used when > > implementing the fork() system call. What fork() does is take the > > current process and make a (near) exact copy of it -- including all of > > its memory. Now to actually do a byte-for-byte copy of all of a > > process's address space will be slow, so Linux doesn't do it. Instead > > it marks the processes memory pages as shared copy-on-write. Both > > processes share the same memory pages. This is fine as long as they are > > both doing reading only. As soon as either process writes to the shared > > memory, only then is a copy made. This gives the illusion that each > > process has its own copy of the original memory space, when in fact much > > of it can be shared. > fork() is interesting but I propose that job creation be handled differently. > I used a system on the Sinclair QL called Qdos (later called Minerva, SMS2) > and it had kernel calls to allocate space in the transient jobs area IIRC and > to creat a job. Instead of having fork() exec() I propose that there be a > variant of exec that creates another process and loading the job from file > into that process. The need for fancy VM work is removed. OTOH fork() is > probably implemented using VM pointer manipulation and is probably very > cheap. Maybe my idea is not needed. > > [snip over commit explanation] > > Having said all that, if your system runs out of memory, a NULL from > > malloc() is probably the least of your problems. How can you fix the > > problem if the system is swapping like crazy and there's no memory to > > start a shell? That's not very graceful ;-) > A NULL from malloc (or a C++ exception from new) is not a problem. In fact > its one way a well behaved Unix program can go "ok I've run out of memory, > I'll free up some space and return to a sensible state". I *want* malloc to > return NULL if the system has run out of memory - its part of its > standardised behaviour and all sorts of programs (including daemons) would do > well to make proper use of it. > > > Ian > > - > ---------------------------------------------------------------------- > You can find the EdLUG mailing list FAQ list at: > http://www.edlug.org.uk/list_faq.html |