You can usually think that physical pages are temporarily highlighted. If the memory used by your program is replaced with a disk, then at any time the connection between your virtual addresses and physical memory can be deleted, and physical memory is used for something else.
If the program later accesses this memory, the OS will assign a new physical page to this virtual page, copy the data from the page file to the physical memory, and terminate access to the memory.
So, to answer your question, a physical page can be marked as accessible when your program no longer uses the allocations allocated in it or earlier. Or after malloc is not always worried about freeing memory back to the OS. You really cannot predict this.
This all happens in the kernel, it is invisible from the point of view of C, just as caching memory from memory is invisible from C. Well, it is invisible until your program slows down massively due to exchange. Obviously, if you disable the swap file, everything will change a little: instead of slowing down your program due to an exchange, some program somewhere will not be able to allocate memory, or something will be killed by the OOM killer.
source share