Thread: virtual memory system

  1. #1
    Registered User invinceable's Avatar
    Join Date
    Jun 2013
    Posts
    2

    virtual memory system

    Hello i am studying for my operating system programming exam, we been provided with a sample exam but no answers have been given.
    i answered this question but not sure if i am right, it would be much appreciated if you could check if i am right and if i am wrong could you explain how to get the right answer.

    Consider a virtual memory system with the following parameters:
    • 32-bit virtual address
    • 4-kbyte virtual page size
    • 32-bit page table entry (PTE)
    • 2-gbyte physical memory


    (a) draw a diagram of the 32-bit address showing the length and placement of all bit fields i.e. the offset in the page(O), and the page number(P).

    32-bit virtual address
    page number | offset
    PPPPPPPPPPPPPPPPPPPP|OOOOOOOOOOOO

    (b) how many virtual pages are available in this system?

    2^20 = 1 048 576 virtual pages

    (c) how many physical frames are available in this system?

    2^12 = 4096*2028 = 8 306 688 physical frames

    (d) name TWO fields of the page table entry.

    - page frame number
    - valid bit(set if page is in memory)
    - other flags: modified(dirty), referenced, protection bits

    any help would be appreciated

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Take this with a grain of salt, it's been a lot of years since I've really had to deal with this kind of stuff

    a, b and d all look correct

    c makes me suspicious, mainly because of the 2028, which is not a power of two. In fact, it's somewhat "awkward" expressed in binary: 11111101100.

    You have 32 bits available for the PTE. The virtual page number is the index into the table, which is irrespective of the 32 bits for each PTE. That means you have 32 bits for status bits (e.g. valid, dirty, protection, etc).

    If you are dealing with only pages in RAM (i.e. nothing swapped to disk), then the answer is easy. You simply divide the physical memory size by page size:
    2GB / 4KB = 2^31 / 2^12 = 2^19 = 524 288 frames
    That means you need 19 bits of the PTE for physical page size, leaving 32 - 19 = 13 bits for status, etc. That's more than enough

    If you have to consider swapping to disk, then it's a bit trickier. Since disk is typically much, much larger than RAM, you could probably easily fill all 32 bits of the PTE with physical (RAM or disk) frame addresses. So then the question is: how many bits of the PTE are used for status info? Remove those from the total, and that is how many bits you have left to address physical pages (frames). So Let's say you have 5 status bits total: valid, dirty and 3 for protection (read, write, execute). That gives
    32 - 5 = 27 bits; 2^27 = 134 217 728 frames

    Hope that makes sense and clears up any issues. Feel free to post back if you have more questions, and maybe somebody else with better knowledge will come along to lend a hand.

  3. #3
    Registered User invinceable's Avatar
    Join Date
    Jun 2013
    Posts
    2
    Thank you so much, your help was really appreciated.

  4. #4
    Registered User
    Join Date
    Jun 2013
    Posts
    1
    Quote Originally Posted by invinceable View Post

    Consider a virtual memory system with the following parameters:
    • 32-bit virtual address
    • 4-kbyte virtual page size
    • 32-bit page table entry (PTE)
    • 2-gbyte physical memory


    (a) draw a diagram of the 32-bit address showing the length and placement of all bit fields i.e. the offset in the page(O), and the page number(P).

    32-bit virtual address
    page number | offset
    PPPPPPPPPPPPPPPPPPPP|OOOOOOOOOOOO
    Hi guys, new to this all and I'm just curious as how one would actually work out (a), was just browsing through and I understand the explanation for the other answers but not sure how you actually work out what the actual page number and offset values are. Is it based on the page size? So for e.g. the virtual page size for this question is set at 4kb, therefore 4kb = 4096 = 2^12. Meaning that 12 bits are the offset?
    Last edited by anonymous567; 06-14-2013 at 03:53 AM.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by anonymous567 View Post
    Hi guys, new to this all and I'm just curious as how one would actually work out (a), was just browsing through and I understand the explanation for the other answers but not sure how you actually work out what the actual page number and offset values are. Is it based on the page size? So for e.g. the virtual page size for this question is set at 4kb, therefore 4kb = 4096 = 2^12. Meaning that 12 bits are the offset?
    Yes, you're right. The page size is 4KB, requiring 12 of address. Since the virtual address space is 32 bits, 32 - 12 = 20 bits left for the virtual page number.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 01-12-2013, 01:46 PM
  2. Virtual File System Management
    By rsky613 in forum C Programming
    Replies: 3
    Last Post: 04-24-2011, 07:00 AM
  3. Replies: 2
    Last Post: 09-28-2006, 01:06 PM
  4. Replies: 4
    Last Post: 03-29-2004, 07:56 PM
  5. Virtual Memory system
    By sicstus in forum C Programming
    Replies: 1
    Last Post: 05-20-2002, 04:16 PM