Reputation: 41
I can't understand the utility of dirty bit, that should be useful during pages replacement, to mark dirty pages. Swap space is a disk portion where OS puts pages that don't fit in primary memory. So, why a not-dirty page shouldn't be written on disk?
Let's take for example a page swapped out from memory to the disk. At this point let's imagine that it is first moved to primary memory again and then it is moved back to disk again. When it is moved to primary memory, I don't think the disk will retain a copy of it. Therefore, even if this page does not get dirty in primary memory, why it should not be rewritten on the disk when it is freed again from primary memory?
Upvotes: 0
Views: 2257
Reputation: 857
When the page is swapped back into memory (loaded into RAM from disk) the bits in the swap file are not invalidated or erased - they still contain the same values that were written out when the page was swapped from RAM to disk. So at the point when it is swapped from disk to RAM the pages in RAM and disk are identical. If no writes are performed then the RAM and disk (swap) versions of the page remain identical. If the kernel decides to swap this page out of RAM again, there is no need to write it to disk (swap) because the correct contents of the page is already on disk. So the page can simply be freed and use for some other purpose. But if a write has been performed then the version of the page on disk and in swap is different, and in this case the dirty bit is set indicating that the page must be written to disk before it can be reused.
Upvotes: 2
Reputation: 21607
Processors that use a dirty bit set that bit whenever a write is made to a page.
If the bit is clear, that means the page has not been changed. If the operating system needs to page out that page,it know that it does not have to write that page (with a clear dirty bit) back to the paging file.
Upvotes: 0