Slashdot Mirror


Linux 2.4 VM Documentation

popoutman writes "Mel Gorman has announced the availability of a guide to the 2.4 kernel VM including a walkthrough of the VM code. Anyone interested in obtaining a solid understanding of the Linux 2.4 VM will certainly want to take a look at this documentation. Mel says that the effort is at least several weeks from being finished, but that he's releasing it now with the hopes of getting feedback to be sure he's on the right track. He also notes that the 2.5 VM is still too much of a moving target for him to document it just yet." See also a Kerneltrap story.

42 of 115 comments (clear)

  1. Here's a tip for the author. by gpinzone · · Score: 2, Insightful

    Somewhere in your document, you ought to explain what "VM" stands for. That goes for the poster as well.

    1. Re:Here's a tip for the author. by tprox · · Score: 2, Interesting

      It stands for Virtual Machine, though I know what you mean about explaining acronyms.

    2. Re:Here's a tip for the author. by tomhartung · · Score: 2, Informative

      Down a ways on the page we see the title of one of the documents: "Understanding the Linux Virtual Memory Manager."

      As a (an ex-)Java guy I immediately thought it stood for "Virtual Machine."

      --
      See my blog at tomwhartung.com for my resu
    3. Re:Here's a tip for the author. by iggymanz · · Score: 3, Informative

      heh, it can stand for a few things in the realm of computers:
      1. virtual memory (using secondary storage to allow the program to address more memory locations than there is in physical RAM)
      2. virtual machine (a machine implemented in software on a real machine, which *could* have different opcodes, or the same ones as the real machine)
      3. VM - the operating system by IBM which allows one of their mainframes to act like many (stands for virtual machine)

      ( Also, there's the VM in VMS, the DEC Vax and Alpha operating system, which stands for VIrtual Memory as in #1)

    4. Re:Here's a tip for the author. by gpinzone · · Score: 2

      Then it should be called the Linux VMM, no? I can guess at a possible meaning, too...but I shouldn't have to.

    5. Re:Here's a tip for the author. by thodi · · Score: 5, Insightful

      People who don't know what it stands for would not want to read the document anyway, don't you think?

  2. always nice to see some documentation by mark_lybarger · · Score: 2, Insightful

    but this kernel has been out now since 04-Jan-2001. i know it took them a while to shake out the vm system, but the kernel is now stale. anybody who needs to know the internals of how vm works in the 2.4 kernel already knows. the rest of us just argue on /. about why there wasn't lots of testing done in past releases or about how you don't make big changes in a supposidly stable release series.

    i'm sure those who need to know though are full aware of the vm workings of the 2.6 kernel (ibm, redhat, oracle, rik, google, etc).

    Linux: the big player everyone likes to root for, but noone wants to put in the lineup.

  3. Where I work by oliverthered · · Score: 5, Funny

    We design aned document things first, work out the bugs in the high level design and then code.

    Well maybe not all the time and with serveral itterations, but I only manage your credit raiting, not you kernel VM.

    --
    thank God the internet isn't a human right.
  4. every developer worth his salt knows... by syle · · Score: 5, Funny

    ...that virtual memory works because of small, magical faeries and gnomes.

    --

    /syle

    1. Re:every developer worth his salt knows... by SpaceLifeForm · · Score: 2
      --
      You are being MICROattacked, from various angles, in a SOFT manner.
    2. Re:every developer worth his salt knows... by FroMan · · Score: 2, Funny

      How would this be modded informative... I'd like to meta-meta mod that moderation to +1 Funny along with this post as +1 Funny.

      --
      Norris/Palin 2012
      Fact: We deserve leaders who can kick your ass and field dress your carcass.
  5. VM: Does it really matter? by XaXXon · · Score: 4, Interesting

    I've always wondered why, in today's world of gigabytes of memory in personal computers, why such a big deal is made about virtual memory..

    I'm not trying to troll, and maybe someone can explain this to me, but as far as I know, VM is used when a computer runs out of RAM. You take some of what's in the RAM and toss it on to the hard drive. When you need it again, you reload it back into RAM and use it.

    I've got 1.5GB of RAM in the box I'm typing this on, and the only reason I don't have more is that I have no use for it.

    At my work, we've got some systems that can eat up 2GB of RAM, but we just put 4GB in the box and don't worry about it. We've found that if we let anything touch VM it slows things down way too much.

    Anyways, I was hoping someone could enlighten me as to why VM has been such a big deal recently.

  6. Re:This should be helpful by sporadek · · Score: 5, Funny
    As a tip for best results I suggeest using the Extreme Documentation method when writing your docs, it's saved time on the order of Olog(n) for me and a proven time saving technique.

    Define your function "Olog", please. Surely Mr. "Wagner LLC Consulting Co. - Getting it right the first time" couldn't have meant O(log n)... :)

  7. Re:VM: Does it really matter? by GGardner · · Score: 5, Informative
    I've always wondered why, in today's world of gigabytes of memory in personal computers, why such a big deal is made about virtual memory..

    This is a good question -- there are several features the VM system allows for in addition to overcommitting physical memory. If your system has enough memory to run with no swap/paging space set up, the VM system still provides these features without ever paging or swapping out memory.

    The first is demand paging. That is, only those pages of an executable that are needed are brought into memory, and on-demand. Yes, this saves memory, but more importantly, it makes program startup much faster. Without demand paging, the whole program would need to be brought into memory at startup. Nowadays, when disks are much slower relative to CPUs, than they used to be, this makes a big difference, especially in the Unix shell-pipeline style of programming, where you run many different short-lived programs.

    Secondly, the VM system allows for shared memory segments between processes. This allows for shared memory, threads and shared libraries.

    Finally, the VM system implements caching of the file system, which we all know and love as a good use for all the memory we stuff into our machines now.

  8. Re:VM: Does it really matter? by Jack+Greenbaum · · Score: 2, Informative
    Secondly, the VM system allows for shared memory segments between processes. This allows for shared memory, threads and shared libraries. Um. Don't you mean it enforces memory separation between processes?

    -- Jack

  9. Documentation and uncommunicative maintainer by FeatureBug · · Score: 4, Informative

    Documenting the VM is a good idea. I hope it is accepted into the /Documentation directory in 2.4.x kernel tarballs but I'm not sure whether you'd get a reply from the maintainer, Marcelo Tosatti. I sent him a carefully written email in August 2002 documenting an invalid config in 2.4.19 which causes the build process to fail. It was disappointing he never responded and apparently did not fix the bug which is still present in 2.4.20 and more recent patches.

    1. Re:Documentation and uncommunicative maintainer by FeatureBug · · Score: 2

      Ok, I sympathise with his daily email overload but maybe he should delegate some of his workw , like dealing with kernel email? There are many other qualified people who have offered to help with maintaining 2.4.x kernels. That would be better than silently dropping email. Maintaining a relatively common Linux kernel series like 2.4.x is such an important job we should not have to rely on one overloaded person -- that's an unnecessary bottleneck. This is not a criticism of Marcelo's quality of work, which I think is very high. I am suggesting that he should delegate at least the work of dealing with kernel email.

    2. Re:Documentation and uncommunicative maintainer by FeatureBug · · Score: 2

      From other people's comments it sounds like Marcelo is too overloaded even to deal with all the bug fixes he receives by email, let alone the bug reports. He silently drops fixes as well as bug reports, so my point is he should delegate some of his heavy workload, such as dealing with email, to the many other qualified people who have offered to help as maintainers of 2.4.x kernels. For some reason he hasn't accepted any of those offers of help.

      LKML is a very high traffic mailing list. I'm wary of adding to that flood of email. However, due to the lack of response from Marcelo I will probably email LKML.

  10. Re:VM: Does it really matter? by GGardner · · Score: 5, Interesting
    Um. Don't you mean it enforces memory separation between processes?

    Good point -- this is such a given on Unix systems that I didn't word it very well. What I should have said is that it enforces memory separation and protection between most memory segments and most processes, and allows for sharing of segments when explicitly setup. This is perhaps the most important thing the VM system does.

  11. Re:JVM by axxackall · · Score: 5, Funny

    yeah, right. let's also integrate to the kernel Perl, Python, Tcl, Lua, Emacs (for Elisp), Guile, Hugs, OCAML, Bash, Apache (for PHP) and Gecko (I want my Mozilla to work faster too!). I wonder, why is X server still not there? And don't forget about at least two CORBA brokers: Gnorba (everyone would love faster Gnome) and OmniOrb (just for a case). Hey, let's put everything into the kernel! Ooops... It's not kernel anymore and it doesn't want to run either. What was the mistake?

    --

    Less is more !
  12. Re:VM: Does it really matter? by heh2k · · Score: 3, Informative

    VM does NOT mean just paging/swapping. that is a small part of it. mac os and windows users constantly misuse the term. the vm does demand paging, copy-on-write, file/page cache, buffer cache, shared mem, mmapped files, and more. the most important of which is protection.

  13. Re:Better document... by cgh4be · · Score: 2, Informative

    You're looking for NetBSD

    Platforms supported:
    acorn26 acorn32 algor alpha amiga amigappc arc arm32 atari bebox cats cesfic cobalt dreamcast evbarm evbmips evbppc evbsh3 evbsh5 hp300 hp700 hpcarm hpcmips hpcsh i386 luna68k mac68k macppc mipsco mmeye mvme68k mvmeppc netwinder news68k newsmips next68k ofppc pc532 playstation2 pmax pmppc prep sandpoint sbmips sgimips shark sparc sparc64 sun2 sun3 vax x68k x86_64

  14. Re:Better document... by AtrN · · Score: 2
    Being a "computer science guy" and being interested in "computing in general" means you should not limit yourself to a single kernel. Learn, look around, be all that you can be :)

    Also, since we're talking VM systems here, I see little need for a CPU with an MMU in a toaster and you'd likely be using the MMU-less Linux in that case. However there may be valid reasons for needing virtual memory in your toaster's OS but I really just want something that slightly burns bread (yes I know about the voice controlled one done at UW) which can be done very cheaply these days. Bettter be a fancy toaster!

  15. Re:Pretty good English for a foreigner by iggymanz · · Score: 2

    ..but is it English speaking by choice? Check this out.

  16. Re:JVM by PetiePooo · · Score: 5, Funny

    I suspect it would be a waste of your time. Lets look at a bit of history.

    There used to be a kernel-space HTTP server. It was integrated into the kernel for a specific reason: zero-copy access to the network interface memory. It was fast and relatively feature-poor. If it crashed (fortunately, a rare occurance), you got a kernel panic.
    Along came a user-space, zero-copy HTTP server. It was faster and had a few more features to boot. Being a user-space program, if it crashed, you got a core-dump. It could also be run in a chroot jail, a gigantic step more secure than running in ring-0.

    Two lessons can be read from this:
    1. Don't integrate something with the kernel unless there is a specific advantage you hope to gain from it. Will making a JVM part of the kernel really speed it up? Are you sure?
    2. Don't under-estimate the speed of a properly designed user-space Linux program. The kernel developers have done a magnificant job tuning the kernel and providing APIs for performance-critical apps.

  17. Re:This should be helpful by glrotate · · Score: 2

    FreeBSD has had commercial success?

  18. Re:JVM by CableModemSniper · · Score: 4, Funny

    OMG! You've reverse-engineered windows!

    --
    Why not fork?
  19. Re:VM: Does it really matter? by tstoneman · · Score: 2, Informative

    If you are asking this question, it really means you have not worked on systems that do not have virtual memory, like DOS.

    Virtual Memory means virtualizing a process's access to memory such that the memory addresses it accesses isn't necessarily the same physical memory address. It allows for complete memory separation between processes, which offers a vast amount of protection so that processes can't crash other processes.

    The only alternative to Virtual Memory is to use actual physical memory addresses. This was exactly the case with DOS. In DOS you would have to manage memory and make sure your process (it's single-threaded... remember?!?) didn't overwrite memory that it didn't own. Everything in memory could be accessed from every single process.

    With virtual memory, two processes could access memory location 0x1000000 and it would map to different physical memory addresses. In fact, the OS will give each process a full memory address range that is completely usuable by the process without any fear of stepping over someone else's memory. This effectively separates processes and prevents a hell of a lot of corruption because of memory bugs in programs.

    This really simplifies programming because whenever we get a memory address from malloc, we don't have to do anything about making sure we don't step over someone else's memory information.

    What you are in fact talking about is paging, the act of having a backing store of information on hard drive. This allows you to keep track of more memory than you physically have, by swapping memory back and forth from physical memory to a hard drive. Any unused memory would be paged to disk.

    Yes, today you can have gigabytes of memory, and when running Mozilla, boy you really don't need virtual memory.

    But what about 10 years from now, when Microsoft Office takes up 50 GB of hard drive space, and 16 GB of memory?

    Virtual memory is a way of abstracting memory use on a per process basis, and it's inclusion in most modern operating systems is one of the reasons why things are relatively stable these days, compared to the old DOS days, anyway.

  20. Different VM by be-fan · · Score: 4, Interesting

    I did a lot of research on VMs about a year ago, and while the different VM systems out there really are interesting they're all kind of limited by the whole "page-level protection" model we've stuck with since the '70s. There are a lot of clever algorithms in the FreeBSD and 2.4 VMs to deal with high load and paging, but the core VM stuff (mapping memory, protection, sharing etc) is largely the same, and is limited by the MMU capabilities of current CPUs. All CPUs basically seperate processes into unique memory contexts, and map (using some sort of page table or reverse page table) physical memory pages of fixed size into the contexts. This solution is sub-optimal for object oriented systems with large scale sharing (the page tables get unweildy, and certain secondary structures, like reverse maps*, grow out of control). What I'd like to see is something new, just for the hell of it being new.

    Here's what I'm thinking. Ditch pages and memory contexts entirely. Instead, divy up a 64-bit virtual address space among individual processes, say 48 bits apiece. If a process wants to access memory outside it's 48-bits, it would need to access it through special pointers (which, thanks to a tagged-RAM architecture) could written to by the OS (allowing the OS to define its own protection and sharing mechanisms). Does anybody know of any existing systems that work even vaguely like this? Or of a different MMU architecture at all? I was hoping that AMD might at least include software TLB management, because there is some nifty stuff you can do with that, but it looks like Hammer will use the same VM mechanism that came out with the 386!

    --
    A deep unwavering belief is a sure sign you're missing something...
    1. Re:Different VM by Wesley+Felter · · Score: 2

      Here's what I'm thinking. Ditch pages and memory contexts entirely. Instead, divy up a 64-bit virtual address space among individual processes, say 48 bits apiece. If a process wants to access memory outside it's 48-bits, it would need to access it through special pointers (which, thanks to a tagged-RAM architecture) could written to by the OS (allowing the OS to define its own protection and sharing mechanisms).

      Look, it's AS/400!

      Doing something "just for the hell of it being new" doesn't seem too popular among CPU manufacturers who are trying to actually make money.

    2. Re:Different VM by be-fan · · Score: 2

      Um, it's called 'innovation.' I mean, we could have stuck with segmentation forever (or better yet, overlays!) but aren't you glad we didn't?

      PS> Hm. I knew AS/400 had a tagged RAM architecture, but I was under the impression that it was for marking crypto data. Could a scheme like the above be implemented on AS/400, and if so, where can I find some reference info about the MMU?

      --
      A deep unwavering belief is a sure sign you're missing something...
    3. Re:Different VM by Wesley+Felter · · Score: 2

      Doing something different just to be different is not innovation. Doing something different because it's better is innovation. In this case, I don't think there's much benefit to single-address-space systems.

      I knew AS/400 had a tagged RAM architecture, but I was under the impression that it was for marking crypto data. Could a scheme like the above be implemented on AS/400, and if so, where can I find some reference info about the MMU?

      My impression is that OS/400 has a single address space and a single level store. The hardware is mostly undocumented AFAIK.

  21. Re:This should be helpful by be-fan · · Score: 2

    Uruk-Hai and it was Saurumon.

    --
    A deep unwavering belief is a sure sign you're missing something...
  22. Re:VM: Does it really matter? by Pseudonym · · Score: 5, Informative
    I've always wondered why, in today's world of gigabytes of memory in personal computers, why such a big deal is made about virtual memory.

    Because it's important. :-)

    Some people think that virtual memory means paging to secondary memory, such as disk. It doesn't. Virtual memory systems can support this, but many OSes (e.g. QNX) support virtual memory with no disk paging. (OK, QNX does support disk paging, but only as an afterthought, so that QNX can be self-compiled. GCC takes a lot of memory.)

    Virtual memory provides a virtual address space for each process. The benefits include:

    • The system can avoid memory fragmentation because contiguous virtual pages do not need to be contiguous in physical memory.
    • Processes don't step on each others' address spaces.
    • Separate instances of the same program can share program text space and shared libraries.
    • Different processes can use the same addresses for different purposes.
    • Processes can share memory between each other in a controlled manner (for example, one process may have read-only access to some region, or memory can be shared between a parent and child process via a read-only or copy-on-write mechanism).
    • Processes on different physical machines can share memory. (This can be done using the standard Unix interface. No extra kernel support is required.)
    • Processes can view files as memory (e.g. using mmap), reading in only as much of the file as is necessary.
    • Processes can allocate large regions of memory and only have the amount of those regions which they actually use backed up by physical memory (whether that is primary or secondary memory).
    • The OS has a lot more freedom in how to lay out a process in physical memory to optimise cache usage.

    This is just off the top of my head.

    --
    sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
  23. Re:VM: Does it really matter? by nathanh · · Score: 2
    I've always wondered why, in today's world of gigabytes of memory in personal computers, why such a big deal is made about virtual memory.

    Because VM is not just used for swap. It's also used for memory protection, buffer caching, shared libraries, demand paging, and dozens of other performance improvements.

  24. copulating modules by ghassanm · · Score: 2, Funny

    2.1.2 Browsing the Code

    Generally, related operations are clustered together in the same file and there is not much copulation between modules.

    I hope the discovery channel will do a special on copulating modules some day. I've seen module coupling but no copulation yet.

    1. Re:copulating modules by Mel · · Score: 2, Funny

      > I hope the discovery channel will do a special on copulating
      > modules some day. I've seen module coupling but no copulation yet

      Haven't you ever heard of sexy code? Is is meant to be taken literally, isn't it?

      (typo corrected in the work in progress version)

  25. Re:MORE documentation needed. by inode_buddha · · Score: 2

    cd /usr/src/linux
    make sgmldocs psdocs pdfdocs htmldocs mandocs

    However, I also subscribe to the relevant mailing lists, and review them daily.

    HTH

    --
    C|N>K
  26. Re:Is late documentation a problem with Open Sourc by inode_buddha · · Score: 2

    I truly think this should be modded as "Insightful", it's quite true in my experience.
    The cure that I use for this is to read the code comments and subscribe to the mailing lists.

    --
    C|N>K
  27. So any clues why VM goes zombie? by Jayfar · · Score: 3, Interesting

    5 root 9 0 0 0 0 Z 0.0 0.0 0:18 kswapd

    My kswapd went zombie after ~18days uptime; it had gone zombie after about 70 days prior to that reboot. I've found references to this occurance ...going back at least through 2.2 kernels and it still happens with 2.4.18 (not the latest, but no real reason for me to build a new kernel unless it solves this). I've never read a thread on this that arrives at a solution or even a description of what is going on. I first encountered it when I went from Mandrake 8 (2.4.8 kernel) to 8.1 (2.4.18).

    Fortunately, I have plenty ram and this doesn't seem to otherwise affect anything.

  28. Re:VM: Does it really matter? by sjames · · Score: 2, Informative

    Another benefit is sparse allocation. When memory is allocated, it's all mapped to a zero filled page and marked copy on write. That allows programs to allocate massive arrays that are expected to be primarily filled with zeros without actually requiring that much memory. When a value is writen, a new page is allocated and mapped into the virtual space.

    If desired, a file can be mmaped into the array instead to provide a simple persistant storage.

    IIRC, suspend to disk is (or at least can be) also accomplished through VM.

    The VM also allows an x86 system to have more than 4GB of ram. No single process can have more than a total of 4G (counting the kernel space) but using PAE, more than a total of 4GB can be allocated to multiple processes through the VM.

    Although Linux doesn't do this, some OSes completely replace the filesystem with a VM. All files and directories are objects and are demand paged.

  29. Re:VM: Does it really matter? by Pseudonym · · Score: 2, Insightful
    If desired, a file can be mmaped into the array instead to provide a simple persistant storage.

    Mmap is way, way more useful than that.

    The key benefit of mmap is that on decent OSes (i.e. not NT/2000/XP), you get effectively get the buffer cache for the file mapped into your address space. Without mmap, you'd effectively have two copies of the file go through memory: one in the buffer cache and one in the application.

    This is not so serious if your file is a sequentially-read stream, because the application won't hold much at a time. However, if it's a randomly accessed file with a large working set (e.g. in a database server), the win is huge.

    --
    sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});