
How The Kernel Manages Your Memory - fogus
http://duartes.org/gustavo/blog/post/how-the-kernel-manages-your-memory
======
xpaulbettsx
One of the most important bits to pull out of this article, is that when you
ask the kernel for memory, it doesn't actually do anything other than update
its accounting of available memory and VA space - when you _touch the page_ ,
you page fault and the kernel actually gives you a physical frame. The NT
kernel (and I suspect any other production OS) works the same way.

~~~
ot
AFAIK there is a difference between Linux and NT: Linux allows overcommitting,
while NT requires that every page has a "backing store", for example a
physical RAM page, a swap page or a memory mapped file.

Thus when you _touch the page_ , Linux may figure out that there is no memory
that page can be mapped to it, but now it is too late because the application
"believes" that the memory has been allocated. So the kernel kills the
application (or, to be correct, _an_ application) too free memory with an OOM
exception. This is one of the reasons why it is good to have loads of swap
even if the physical RAM is big enough for all the running processes.

~~~
nitrogen
Or, if you know you won't be running applications that allocate more than they
use, you can disable overcommission entirely.

------
jedsmith
All great reads: <http://duartes.org/gustavo/blog/best-of>

I've never heard of this guy, but I like him already. Anybody that can produce
documentation of this level of quality for a relatively advanced codebase is a
good person to have committing, or even just hanging around.

~~~
pwelch
I agree, the quality is really good. Thank you for pointing out the "Best of"
link. Another hour removed from "productivity" and moved to "always wanted to
read about" for my day. =)

------
zwieback
Great article, nice graphics. His other articles are very good too. I'd love
to see someone explaining the details of memory management for the ARM Linux
kernel with the same clarity.

------
shin_lao
Great article. If you want to know more about Windows memory layout here's a
couple of great books:

<http://technet.microsoft.com/en-us/sysinternals/bb963901>

[http://www.amazon.com/Windows-File-System-Internals-
Develope...](http://www.amazon.com/Windows-File-System-Internals-
Developers/dp/1565922492) (Yes it's about file systems but it's an awesome
book about Windows internals)

[http://www.amazon.com/Windows-Device-Development-Classic-
Rep...](http://www.amazon.com/Windows-Device-Development-Classic-
Reprints/dp/0976717522/ref=sr_1_6?s=books&ie=UTF8&qid=1300344720&sr=1-6)

------
DannoHung
I love this dude's blog, but I wish he'd actually post more new articles.

------
rw2-
Nice post. But it's Hacker _News_. Not "Hacker _OMG I've found a nice old
article_". ;-)

February 3, 2009 at 11:35 pm

~~~
rw2-
Hmmm, nobody seems to understand what ";-)" means.

~~~
scott_s
We do. Your post is still noise. This is a valuable article that most people
here have not seen - I hadn't, even though I have seen others from this
author. Which are all excellent, by the way. I upvoted this submission because
I love seeing such detailed systems articles on the frontpage.

~~~
pwelch
I agree. I enjoy finding detailed articles like this when I come to Hacker
News. Also, even though this article is old to a lot of people I have found a
new blog to follow with what appears to be well written articles.

