简体   繁体   English

分页器如何猜测在需求分页中将哪个页面带入内存?

[英]How pager guesses which page to bring it into the memory in demand paging?

When a process is to be swapped in, the pager guesses which pages will be used before the process is swapped out again. 当要交换一个进程时,寻呼机在再次交换该进程之前会猜测将使用哪些页面。 So pager will swap in only the desired pages. 因此,传呼机将仅交换所需的页面。 But how the pager will guess in advanced that these particular pages are required? 但是,传呼机如何预先猜测这些特定页面是必需的?

It doesn't guess that. 没想到。 If there is demand paging, that means: it will bring into the memory, if it is needed (== a process wants to read it). 如果存在需求分页,则意味着:如果需要,它将进入内存(==进程要读取它)。

Although it were possible to use some type of heuristics to make it before the demand, practically it doesn't happen, because this type of memory could have a much better usage as well: it can be used to cache the last read/wrote disk blocks. 尽管可以使用某种启发式方法在需求之前创建它,但实际上不会发生,因为这种类型的内存也可以有更好的用法:它可以用于缓存最后一个读/写磁盘块。

You use also a terminology: "process swapped in". 您还使用了一种术语:“交换了流程”。 Whole processes aren't swapped in/out in modern OSes, only their pages. 在现代操作系统中,整个进程不会被交换进/出,而只是它们的页面。 In older times it happened that processes were swapped in/out as a whole, because the paging couldn't handle that at the time. 在较早的时候,发生了整个进程都被调入/调出的情况,因为分页当时无法处理。

I have recently had the opportunity to implement a demand paging manager (DPM) for a small real-time OS. 我最近有机会为小型实时OS实现需求分页管理器(DPM)。 I can not speak for what the big and fancy OSes do, but in the RTOS upon which I worked, it did not do any prediction/guessing. 我无法说说大型OS的功能,但是在我工作过的RTOS中,它没有进行任何预测/猜测。 The only "guessing" it did was that of trying to figure out which page it should evict in order to make room for a new page. 它所做的唯一“猜测”是试图弄清楚应该退出哪个页面以便为新页面腾出空间。

I needed a general purpose DPM--one that would work in any scenario. 我需要一个通用的DPM-在任何情况下都可以使用。 I took a purely reactive approach; 我采取了纯粹的被动方式; that is pages would be paged in in response to some event that demanded their presence (such as a page fault). 也就是说,页面会响应某些要求其存在的事件而被分页(例如页面错误)。 My DPM did not bother with the proactive approach (guessing which pages are required in advance). 我的DPM并不主动采用这种方法(预先猜测需要哪些页面)。 I did this to avoid incurring the following penalties/costs: 我这样做是为了避免产生以下罚款/费用:

  1. Time to develop more complex code. 是时候开发更复杂的代码了。
  2. Time to execute the prediction algorithm. 执行预测算法的时间。
  3. Prediction miss penalties (loading data, saving data, and predicting the page) 预测未命中的罚款(加载数据,保存数据和预测页面)

Furthermore, a proactive approach would still require the reactive component (and its costs) just to handle prediction misses. 此外,前摄性方法仍将仅需要反应性成分(及其成本)来处理预测遗漏。 It was far more cost-effective to take the reactive approach. 采取被动方法更具成本效益。

Pager doesn't guess anything before the process is allocated the CPU. 在为进程分配CPU之前,Pager不会猜测任何内容。 As soon as the process comes in running state, some of its pages will be loaded in main memory, and after that demand paging will come in picture, pages will be swapped out/in according to the demand of process. 一旦进程进入运行状态,它的某些页面将被加载到主内存中,并且在该需求分页出现后,页面将根据过程的需求换出/切入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM