Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between virtual page and page frame?

From what I understand pages come from overlays which are clusters of memory spaces generated by Virtual Memory. But I don't understand what frames are or how they relate.

Can anyone explain what page and frame is and how it works?

like image 644
Callat Avatar asked Feb 15 '17 19:02

Callat


2 Answers

A page (or memory page, or virtual page, or logical page) is a fixed-length contiguous block of virtual memory.

A frame (or memory frame, or physical page, or page frame) is a fixed-length block of RAM (ie. physical memory, it exists - as in "physical". Virtual memory is invented for our mathematics to work properly and efficiently in order to securely manage memory).

Notice that the frame may not be contiguous, but the page will be. We want the process, the OS to deal with consecutive addresses as it makes everything easier. Let a dedicated hardware chip (the MMU) correspond the virtual address to the proper physical address & vice versa.

Virtual addresses are used by the process, while physical addresses are used by the hardware, ie. the CPU (placing address in its address bus to request a memory access) and the RAM subsystem (MMU, page tables etc). When a program is compiled, the compiler converts a program code into machine understandable code and in between this process, addresses spaces are set in the form of virtual addresses. When processed by the processor, they're again mapped into the physical locations available in memory whether it'd be RAM or HDD, with the help of the MMU.

PS. I don't condone the use of the term page frame. You likely realize that it is the source of confusions. Stick to 'page' and 'frame', two very simple words with clear meaning.

like image 82
KeyC0de Avatar answered Sep 20 '22 19:09

KeyC0de


Physical memory is organized into PAGE FRAMES. The size of a page frame is a power of 2 in bytes and varies among systems.

Logical memory is organized into PAGES. The size of page matches a page frame.

A logical address is divided into a page selector and an offset into the page.

Logical pages are mapped to page frames using page tables. The structure of a page table varies among systems. The pages selector of a logical address serves as an index into a page table.

In most systems, the page tables can specify valid logical addresses that have no associated page frame. This is a virtual memory system. If an application attempt to access such a page, it triggers a page fault exception. The operating system page fault handler must allocate a physical page frame, load the page frame using data from secondary storage, update the page table to map the logical page to the newly allocated physical page frame, and finally restart the instruction that caused the fault.

The operating system manages the page tables. The CPU (transparently to the application) translates logical page frames into physical page frames using the page table.

like image 34
user3344003 Avatar answered Sep 17 '22 19:09

user3344003