Question

When there is a TLB miss, and the page is not resident in physical memory, the page is written back into physical memory and the page table and TLB are updated.

But where is address for the secondary memory stored? How does it know where to find the data on disk?

Was it helpful?

Solution

The memory manager maintains a data structure, in which, given a virtual address, it can find the corresponding location on the disk / in the swap file.

Obviously, the search key isn't just the address, it's a pair of the address and the ID of the current address space or of the current process (you need to disambiguate between faulting at, say, address 0x8000 in process 1 and faulting at the same address 0x8000 in process 2 since they likely don't share memory at 0x8000).

Page Table Entries might be useful here. They store the physical address when the virtual to physical mapping is valid. When it's not valid (because of swapping out to the disk), the address can be set to anything of your liking. You could store in its place the location on the disk. Though, this isn't a great idea if you want to avoid writing the contents of unchanged pages to the disk every time you want to reuse the pages and their contents has been previously written to the disk and still matches what's in memory. A PTE can't hold two different addresses (physical and disk) at the same time. So, a dedicated data structure should be used for the purpose instead of PTEs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top