So is it even possible for a user process to even try to access a physical memory location that does not belong to it and therefore getting an error by operating system?

because for example with a 32 bit cpu the user process has an illusion of having a 32 bit memory all for it self (correct me if I'm wrong) and each page of this virtual memory has a corresponding entry in the page table that says whether this page exists in the real memory or not

but considering user process does not have access to the page table to modify it, how can a process even try to access a memory location in physical memory that doesn't belong to it considering the page table won't let that happen?

does this scenario ever happen? (because i remember reading something about operating systems using exceptions when a process tries to access something that does not belong to it but I'm not sure)


1 Answer 1


Yes, this typically happens on modern operating systems such as Linux and Windows because they implement demand-paging. That is, whenever a process requests from the OS to allocate a chunk of memory, the OS by default only allocates virtual pages that are not actually mapped to physical pages. The OS satisfies the allocation request by simply modifying its internal data structures to remember that those virtual pages have been allocated and it's OK for the process to access them. This enables the OS to distinguish between virtual pages that have been allocated and those that have not. The OS does not update the corresponding page table entry and leave it invalid.

When an allocated virtual page is accessed for the first time, the CPU sees that the page table entry that describes that virtual page does not map to a physical page and so it will raise an exception known as a page fault. The OS handles the exception by allocating a physical page and updating the page table entry. Then it lets the CPU re-execute the instruction that attempted to access the page and caused the fault. When the instruction is executed again, it will be able to successfully access the page since it's now backed by physical main memory.

The alternative to demand-paging is anticipatory paging where the OS allocates a physical page and updates the page table immediately whenever it allocates a virtual page.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.