views:

73

answers:

1

Hello, I am doing some exercices to understand how the virtual memory and paging works, my question is as follows :

Suppose we use a paged memory with pages of 1024 bytes, the virtual address space is of 8 pages but the physical memory can only contain 4 frames of pages. Replacement policy is LRU.

  1. What is the physical address in main memory that corresponds to virtual address 4096? and how do you get to that result?
  2. Same thing as question 1 but with virtual address 1024
  3. A page fault occurs when accessing a word in page 0, which page frame will be used to receive the virtual page 0?

Page Image

My trial :

What I got so far for 1. and 2. questions is determine the address in the table (attached as image) for the corresponding pages. So for example I will match virtual address 4096 to page 4, and 1024 to page 1, is this correct?

A: 
  1. I would find the page that the address refers to first. The first page starts at 0 and the last byte is at 1023, the second page starts at 1024 etc. So 4096 is the start of the fourth page in the virtual memory table. According to the "Present on main memory bit", this table is paged, so we look at the "page frame" column to see what page in main memory it resides in. The table says page 01, which is 1 in binary. In real memory each page is still 1024 bytes, so page index 1 would be found at the physical address 1024.

  2. Similar to 1

  3. 4 pages mean page numbers in binary of 00, 01, 10, 11. If a page is currently not being used, that will be the first page to be filled after a page fault.

tjohns20
Thank you for the answer, but isn't Page 0 that starts from 0 and ends at 1023 and not Page 1? And how does it affect the physical address when a page is present in main memory or not?
Virtual address 1024 (Page 1) is not present in main memory (bit set to 0) for example "page frame" is set to "xx" so how do we know the physical address?
Yep, you're right about the Page indexes. What I should have said was "the first page", "second page" etc.As for address 1024, if it's not in the memory it must be on the hard disk. Try the 'address on hard disk' column :)
tjohns20
Thanks, now I am gonna continue studying!