关于操作系统中虚拟内存管理的问题

huangapple go评论52阅读模式
英文:

A problem about virtual memory management in OS

问题

以下是要翻译的内容:

这个问题的背景如下。我困惑的是为什么我不需要知道TLB中有多少条目?

关于操作系统中虚拟内存管理的问题

对于第一个问题:

当我访问0x2330地址的数据时,由于TLB现在为空,我在主内存中找到了它,所以需要110纳秒。

当我访问0x0565地址的数据时,发生了页错误,所以需要500纳秒,然后我将其加载到TLB和主内存中(现在我应该替换主内存中的一页,因为驻留集包含2个帧,但应该替换哪一页呢?问题中只提到我们在TLB中使用LRU替换策略)。

当我访问0x2345地址的数据时,可能会发生什么事情?我不太确定;w;

英文:

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

关于操作系统中虚拟内存管理的问题

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;

答案1

得分: 0

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

对于回答要完全正确,你确实需要知道TLB中有多少个条目。有两种可能性:

a) TLB中有2个或更多个条目。在这种情况下,你没有理由关心替换算法是什么,问题中的“并且TLB使用LRU替换策略”是一个不必要的干扰。在实际硬件中(但不一定在学术理论中),这是极有可能的。

b) 只有1个TLB条目。在这种情况下,你没有理由关心替换算法的另一个原因 - 任何TLB未命中都必须导致先前的内容被驱逐(并且所有这些访问都将是“TLB未命中”,因为没有页面连续2次访问)。

要解决这个问题,我会做出最有可能的假设(即TLB中有2个或更多个条目),然后在我的答案中明确陈述这一假设(例如,“假设TLB中有2个或更多个条目(问题中没有提到),答案如下:”)。

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

这不完全正确。CPU必须访问TLB以确定它是“TLB未命中”,然后从内存中获取翻译到TLB中,然后执行以下操作之一:

*(如果没有高速缓存)从内存中获取数据(物理地址为0x27330)以进行最终访问;或

*(如果有高速缓存)检查数据是否已经缓存,然后执行以下操作之一:
*(如果“缓存命中”)从高速缓存中获取数据,或
*(如果“缓存未命中”)从内存中获取数据。

遗憾的是,问题没有提到任何关于高速缓存的信息。为了解决这个问题,我会做出最有可能的假设(即没有高速缓存 - 请参见注释),然后在我的答案中明确陈述这一假设(例如,“假设TLB中有2个或更多个条目(问题中没有提到),并且没有高速缓存(问题中也没有提到),答案如下:”)。

注意:在这个上下文中,“没有高速缓存”是最有可能的假设(学术界专注于教授虚拟内存,通常不考虑高速缓存);但在现实世界中,这是最不可能的假设。

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?

你又是对的 - 问题只说“操作系统采用固定分配和本地替换策略”(并没有说它是否使用LRU或其他什么替换策略)。

为了解决这个问题,我会做出一个合理的假设(即操作系统使用LRU页面替换策略),然后在我的答案中明确陈述这一假设(例如,“假设TLB中有2个或更多个条目(问题中没有提到),并且没有高速缓存(问题中也没有提到),操作系统使用LRU页面替换策略(问题中也没有提到),答案如下:”)。

英文:

> 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:").

huangapple
  • 本文由 发表于 2023年2月16日 03:24:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75464573.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定