Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone explain this diagram on Paging (virtual memory) to me?

I've been trying to understand virtual memory but when I get into the real specifics of it I just get confused. I understand (or feel like I do) the fact that virtual memory is a way for a process to "think" that it has a certain amount of memory allocated to it. The virtual address space is partitioned into equal sized pages, the physical memory is partitioned into equal sized frames, and the pages map to the frames.

But like..when does this happen? In this diagram, the CPU is running Program P. That means that a part of P was already in the physical memory, correct? (Since the cpu only has access to the physical/main memory). So what exactly is being pointed at by the CPU? I see that it's a page in the virtual memory space, so like..what exactly does this page represent? Is it an instruction? Are we moving an instruction from virtual memory to physical memory, so that more of the program is in physical memory (that hadn't been needed up until that point)? Am I way off? Can someone explain this to me?

enter image description here

like image 716
FrostyStraw Avatar asked Oct 16 '25 18:10

FrostyStraw


1 Answers

The diagram shows the process of translating a virtual address to a physical address.

The fat arrow from Program P to CPU symbolizes the program being "fed" into the CPU.1

The CPU "points" to a virtual address used by an instruction to address a memory location in the program P. It is divided into two parts:

  • Page Table Index (p): the virtual address contains an index into the page table, which maps a page to a page frame (f). For a description of the mechanism, including multi-level paging, read this.
  • Offset (o): as you can see, the offset is directly added to the physical address, since paging's smallest addressable unit is a page, not a byte

Finally, the calculated address is used to address a memory location in physical memory.


1 "fed" means "read (pronounced like red) from secondary storage into RAM and executing the program instruction by instruction".

like image 138
cadaniluk Avatar answered Oct 19 '25 13:10

cadaniluk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!