Hacker News new | past | comments | ask | show | jobs | submit login
How The Kernel Manages Your Memory (duartes.org)
191 points by fogus on March 16, 2011 | hide | past | favorite | 18 comments



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.


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.


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


This point is in fact extremely important in understanding the behavior of real systems. The analogy I've used to explain it to students is that a memory map (mmap) or brk operation is like getting building permits from the city. You haven't created new buildings, but you've received permission to do so.


Some Unixes that are meant to support real-time applications allow you to do an actual allocation. e.g., AIX had PSALLOC=early.


See also mlock and mlockall for an approximation of this:

http://linux.die.net/man/2/mlockall


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.


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. =)


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.


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... (Yes it's about file systems but it's an awesome book about Windows internals)

http://www.amazon.com/Windows-Device-Development-Classic-Rep...


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


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

February 3, 2009 at 11:35 pm


> What to Submit: [...] If you had to reduce it to a sentence, the answer might be: anything that gratifies one's intellectual curiosity.

http://ycombinator.com/newsguidelines.html


I know you meant it jokingly but I come to Hacker News to find good technical/business posts like this one. Great thing about the internet is there are many old still valuable articles out there, many of which some people have not read yet. What might be an old article to you can still be new to other people.


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


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.


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.


Ok. Fair point.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: