Prashant Sharma
Prashant Sharma

Reputation: 27

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?

Upvotes: 0

Views: 205

Answers (3)

instance
instance

Reputation: 1374

Pager doesn't guess anything before the process is allocated the CPU. 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.

Upvotes: 1

Sparky
Sparky

Reputation: 14057

I have recently had the opportunity to implement a demand paging manager (DPM) for a small real-time OS. 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. 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. 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). 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.

Upvotes: 1

peterh
peterh

Reputation: 12575

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.

Upvotes: 1

Related Questions