r/AskComputerScience • • May 14 '25
confused about virtual memory
If I got this right, the point of virtual memory is to ensure processes use unique physical address space.
Is this abstraction really needed ?
For example, say there are 2 C programs and each one does malloc. This asks the OS for memory. Why can't the OS guarantee that unique physical address space is given to the C program ?
2
Upvotes
View all comments
Show parent comment
1
u/fllthdcrb May 16 '25 edited May 16 '25
"Physical memory" here refers to RAM. Disks (and memory devices like SSDs) can be considered a form of memory, but that's a different thing.
And where does the OS get such a page? Well, anywhere it likes. But most commonly, in a file on disk (the so-called "page file"; also known as a "swap file", because pages are swapped between it and RAM). To be more precise, it's the contents of a page, which it copies to or from the file. Or instead of a file, a partition of a disk, used often on e.g. Linux. The exact form can vary, but the point is, there are options involving secondary media.