Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 19 of 19
I found this guide to the kernel very useful. The memory management stuff is in chapter 3....
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,281

    I found this guide to the kernel very useful. The memory management stuff is in chapter 3.
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

  2. #12
    Just Joined!
    Join Date
    Mar 2006
    Posts
    29
    Just a FYI, the swap isn't infinite, it is blocked by the address space limits. Do not forget that the swap is "mapped" as memory and shares the same addresses space with the real memory. Thus for a 32bits systems you can't go more than 4GB of overall (swap + real) memory even if you have a 6GB swap partition/file.
    On the topic, to get a deeper undertanding try to get a hold of the i386 protected system which was the base of the paged memory systems.

  3. #13
    Just Joined!
    Join Date
    May 2010
    Posts
    12
    Thanks a lot !

    Since executables (at least the text segments) are not written into the swap and are always loaded into the memory from their location in the hard disk, the swap is basically a place to store the data segments of the executables and the data stored in the dynamic memory allocated to the process.

    Also, when a process' time slice expires and its replaced by another process, the page table as well as the TLB (which I think is a subset of the page table) that FastFreddie mentioned is stored in a kernel data structure as part of the process' context. As and when some of its pages are swapped out of the memory, the kernel updates the tables so that when the process comes again into execution, its page table and the translation table are up-to-date.

    One thing I still don't understand is how, after the pages have been transferred into the swap, when the process is again ready for execution, how does the process recognize what out of those present on the swap are its own. A process-specific data structure to hold the locations in the swap of all the pages that are swapped may be there perhaps ?

    About what Keikun2004 said, I understand that since the address bus is only 32 bit and the virtual address generated is also 32 bit, therefore only 2^32 addresses of the main memory can be addressed (considering all processes' mapping), irrespective of the main memory size. Thus, the maximum no. of addresses in the main memory whose mapping is present in any of the process' tables at a particular time is 4GiB, but since each user process can be given 2GiB virtual addresses and the swapping behind the scenes is oblivious to the user, it can be perhaps said that the user is given the illusion that he has infinite virtual memory to work with.

  4. $spacer_open
    $spacer_close
  5. #14
    Just Joined!
    Join Date
    Feb 2005
    Posts
    2
    I think keikun2004 is almost correct. Virtual memory is bound by 2 things. First by the amount of backing store (Swap space) and the hardware address register. If the hardware address register is larger than 32 bits say 33 then you could have 2 segments of 32 bit addresses. Also Swap isn't really limited by how big the Virtual address scheme is. The limitation is the size of the swap space. I mean that EACH process has X amount of virtual Memory. So IF the VM addressing scheme is 2 G then VM will = 2 Gig per process. Swap (Backing Store) needs to be large enough to handle the amount of processes running or you become bound or worst case hung untill some space frees up.

    There is no reason to write the text segments to swap they are immutable (in that they can't be overwritten while a process is using the file. The initialized data section can change as a process progresses as well as the uninitialized data section and these are backed up by backing store. On some machines with lots of memory SWAP may NEVER BE USED. Because there is enough memory to hold all of the users/processes pages.

  6. #15
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    You are correct in that the TLB is a subset of the page tables. More accurately, however, it is a cache for the page tables. So it is faster to access than the normal page tables, and recently-used virtual memory translations are stored in the TLB in order to make future lookups faster.

    You asked how the process knows what part of the swap it owns. The answer is simple: it doesn't. You need to remember that to the process, memory is very simple. To a process, there are 4 GB of contiguous memory addresses. That is all. No funny business.

    Writing to and reading from swap is all done by the kernel. When the scheduler decides to make a new process active, it will wipe the page tables. The new process will then begin to execute. As it attempts to access memory, these accesses will fault, returning control to the kernel, which will load the memory from swap / disk. This is completely transparent to the process.

    I do not recall how Linux internally remembers the mapping of swap page to process and virtual page, but it may be something as simple as a lookup table where the key is PID and virtual page #, and this gets mapped to a particular swap page.

  7. #16
    Just Joined!
    Join Date
    May 2010
    Posts
    12
    Thanks. I think the only part that really confuses me now is the limit of the virtual memory. I have seen on the net "virtual memory is infinite", "virtual memory is sum of RAM and swap","VM is upper bounded by 4GiB", etc. I guess its just a way of viewing virtual memory.
    What I understand is that once all the 2^32 addresses of main memory fill up and the swap space too, no more processes can be added. So for 32 bit systems, 4GiB+swap space should be the maximum amount of virtual memory that all the processes can share at a given instance. Am I right ?

  8. #17
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    That's almost correct. Remember that the text segments of your executables don't get swapped (because they come from disk), so you get that "swap" in addition to your actual swap. You also need to remember about virtual memory tricks that the OS plays though: a process isn't given memory until it asks for it (so even though it thinks it has 4 GB immediately, it actually has only been allocated what it is specifically asking), and for instance, if you request a bunch of memory filled with 0s, the OS won't actually give you the memory until you write something to it, so there's no physical memory backing it yet.

    Also, if you make a fork() call, memory is generally shared between the two processes until one of them actually wants to modify the memory. So you could have two processes that think they hav their own copies of a piece of memory, but in reality it's just one copy.

    So yes, there is a maximum amount of space, but the space you need is much more complicated than just 4 * (# of processes), and the maximum space is a bit more complicated than 4 + (size of swap).

  9. #18
    Just Joined!
    Join Date
    May 2007
    Posts
    72
    Is this a good time to ask for a good rule of thumb for sizing swap space? Given that RAM is now pretty cheap and many people have huge amounts, the old 2*(RAM size) seems unnecessary. On the other hand, HD's are cheap too, and if you've got terabytes of space, 10G (!) or even 100G (!!!) would hardly be missed.
    Perhaps a lot of the fancy tricks with virtual memory and swapping are becoming obsolete? Do they cost much in performance?

  10. #19
    Just Joined!
    Join Date
    May 2010
    Posts
    12
    Thanks a lot to everyone for responding to the thread. I really learned a lot here.

Page 2 of 2 FirstFirst 1 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •