Jump to content
Sign in to follow this  
zak100

NRU: Page fault on write?

Recommended Posts

Hi,

I am trying to understand the concept of NRU from the following link. I have got some problem in understanding the text below:

https://www.informit.com/articles/article.aspx?p=25260&seqNum=3

Quote

 

If the hardware does not have these bits, they can be simulated as follows. When a process is started up, all of its page table entries are marked as not in memory. As soon as any page is referenced, a page fault will occur. The operating system then sets the bit (in its internal tables), changes the page table entry to point to the correct page, with mode READ ONLY, and restarts the instruction. If the page is subsequently written on, another page fault will occur, allowing the operating system to set the bit and change the page's mode to READ/WRITE.

 

 

I have bolded the text. I have two problems: Page fault occurs if the page is not in memory but the above text says that

(a)the page fault occurs at the time of modifying or writing the page? I can’t understand that.

(b) Also I cant understand the text “, allowing the operating system to set the M bit and change the page's mode to READ/WRITE.What is meant by READ/WRITE? If we are setting the M bit then it should be WRITE mode only? Why the text says READ/WRITE mode.

Somebody please guide me.

 

Zulfi.

 

 

Share this post


Link to post
Share on other sites
50 minutes ago, zak100 said:

(a)the page fault occurs at the time of modifying or writing the page? I can’t understand that.

It occurs when an attempt is made to read or write the page. If the page is not in memory, then it will have to be fetched before the read or write can complete.

51 minutes ago, zak100 said:

(b) Also I cant understand the text “, allowing the operating system to set the M bit and change the page's mode to READ/WRITE.What is meant by READ/WRITE? If we are setting the M bit then it should be WRITE mode only? Why the text says READ/WRITE mode.

The algorithm wants to keep track of which pages have been modified separately from those that have just been referenced / read. (I'm sure there is a good reason for that, presumably analysis shows that pages which are written to are more likely to be used again, or something).

So it has to keep track of when pages are modified. The easy way to do that (with the performance overhead of detecting every single write) is to initially mark the page as READ ONLY. Then when the software attempts to write to it, that will cause a page fault (attempting to write to read-only memory). At the point you can set the M flag to indicate that the page has been modified (because that is used later in the algorithm) and set the READ/WRITE flag so any further writes to that page will not cause a page fault (ie. won't slow the processor down).

Share this post


Link to post
Share on other sites

Hi,

Thanks for your response. Do you mean we have 3 flags, R, M and read/write?

 

Please guide me.

 

Zulfi.

Share this post


Link to post
Share on other sites
6 minutes ago, zak100 said:

Hi,

Thanks for your response. Do you mean we have 3 flags, R, M and read/write?

 

Please guide me.

 

Zulfi.

That is my understanding. 

The R and M flags just record the status of the page (referenced and modified).

The read/write flag controls whether it is legal to write or not (that is why you get a page fault attempting to write to a read only page).

(There may be others not mentioned in the article that are not relevant to this algorithm.)

Share this post


Link to post
Share on other sites

Hi,

Thanks. I got your idea.

R, flag stands for only read,

M flag means we want to only write

and read/write flag means we want to do both read and modify the page.

 

Zulfi.

 

Share this post


Link to post
Share on other sites
3 hours ago, zak100 said:

R, flag stands for only read,

M flag means we want to only write

and read/write flag means we want to do both read and modify the page.

Not quite. 

R records the fact that the page has been accessed (Referenced)

M records the fact that the page has been written to (Modified)

So reading a page the first time will set the R flag

Writing a page the first time will set the R and the M flag

Neither of those control what is allowed, they just record what happened to the page. 

The read/write controls whether the page can be written to or not. Initially it is read only until it is written to

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.