Search code examples
memoryoperating-systemvirtual-memorypage-replacement

A problem about virtual memory management in OS


Here is the context of this problem. I am confused that why I don't need to now how many entries in TLB?

enter image description here

For the first question:

when I access data in 0x2330, I find it in main memory since TLB is empty now, then I need 10 + 100 = 110(ns)

when I access data in 0x0565, I meet a page fault so I need 500(ns) , then I load it in TLB and main memory(now I should replace one page in main memory because the resident set contains 2 frames, but which page should I replace? The problem just say we use LRU replacement policy in TLB)

when I access data in 0x2345, what things may happen? I'm not sure ;w;


Solution

  • I am confused that why I don't need to now how many entries in TLB?

    For an answer to be 100% correct, you do need to know how many TLB entries there are. There are 2 possibilities:

    a) There are 2 or more TLB entries. In this case you have no reason to care what the replacement algorithm is and the question's "And the TLB is replaced with LRU replacement policy" is an unnecessary distraction. In practice for real hardware (but not necessary in theory for academia) this is extremely likely.

    b) There is only 1 TLB entry. In this case you have no reason to care what the replacement algorithm is for a different reason - any TLB miss must cause the previous contents to be evicted (and all of those accesses will be "TLB miss" because no page is accessed 2 or more times in a row).

    To work around this problem I'd make the most likely assumption (that there are 2 or more TLB entries) and then clearly state that assumption in my answer (e.g. "Assuming there are 2 or more TLB entries (not stated in question), the answers are:").

    when I access data in 0x2330, I find it in main memory since TLB is empty now, then I need 10 + 100 = 110(ns)

    That's not quite right. The CPU would have to access the TLB to determine that it's a "TLB miss", then fetch the translation from memory into the TLB, then either:

    • (if there are no cache/s) fetch the data from memory (at physical address 0x27330) to do the final access; or

    • (if there are cache/s) check if the data is already cached and either:

      • (if "cache hit") fetch the data from cache, or
      • (if "cache miss") fetch the data from memory

    Sadly; the question doesn't mention anything about cache/s. To work around that problem I'd make the most likely assumption (that there are no caches - see notes) and then clearly state that assumption in my answer (e.g. "Assuming there are 2 or more TLB entries (not stated in the question) and that there are also no cache/s (also not stated in the question), the answers are:").

    Note: "No cache/s" is the most likely assumption for the context (academia focusing on teaching virtual memory in isolation); but is also the least likely assumption in the real world.

    when I access data in 0x0565, I meet a page fault so I need 500(ns) , then I load it in TLB and main memory(now I should replace one page in main memory because the resident set contains 2 frames, but which page should I replace?

    You're right again - the question only says "The OS adopts fixed allocation and local replacement policy" (and doesn't say if it uses LRU or something else).

    To work around this problem I'd make a sane assumption (that the OS uses LRU replacment policy) and then clearly state that assumption in my answer (e.g. "Assuming there are 2 or more TLB entries (not stated in the question), and that there are also no cache/s (also not stated in the question), and that the OS is using an LRU page replacement policy (also not stated in the question); the answers are:").