virtual memory: how does it provide protection

Joined
Jun 14, 2017
Messages
2
it's said that virtual memory solves the problems of raw physical memory, namely lack of memory, fragmentation, and protection. but does it provide a guarantee that two processes don't map to the same physical memory? how does, when "allocating" a space for a new process, virtual memory manager know that "this physical memory is allocated so i can't touch it, but that one isn't so i'll give it to the new process"? is there some kind of mapping stored?
 
Yeah, the operating system uses the Memory Management Unit on the processor to translate virtual addresses.

https://en.wikipedia.org/wiki/Memory_management_unit

It keeps track of what is allocated to each task with a Page Table. This is an actual physical table maintained in ram by the operating system.

https://en.wikipedia.org/wiki/Page_table

Each time you create a new task, a space is set-aside in the Table that's not currently used by any other task.

And then the OS adds more memory Pages as needed. This is called a Page Fault.

https://en.wikipedia.org/wiki/Page_fault

They can also be deallocated by the OS when not needed any longer. This is how you avoid fragmentation: pages can be used in any order, and can be managed individually. As-opposed to flat-mapped systems, where you need one continuous block of memory when it's requested.
 
Last edited:
Back
Top