I'm trying to understand how OS does the swapping between the disk and RAM when a page fault occurs. For instance, assume the page table of a process is full and a swap needs to happen.
Does the frame to which the page entry in the page table point to get written to disk itself, then the frame gets overwritten by the new data that is requested? Or does the page itself contain the frame data in this case?
Additionally, if two virtual addresses can map to the same physical address (assuming it's not because of shared memory), is whatever data that was written in the frame the page they belong to points to get written to disk itself?
My confusion comes from the fact that the book I'm reading (and many resources online) mention that the 'page' gets written to disk, but the page from what I understand only contains metadata regarding the frame and the address and not the memory data themselves. So, how does it work, exactly?