Menu

Memory Management

Paging

Paging is a way the operating system organises main memory. It divides RAM into equal-sized sections called pages. Because every page is the same size, the operating system can give any free page to a process, rather than searching for one continuous block large enough for a whole program.

When a process is loaded, its instructions and data are split across pages in main memory. The operating system records which pages belong to which process. It can then allocate pages as processes need them and free pages when they are no longer required. This allows several processes to share RAM at the same time.

RAM drawn as eight equal-sized frames holding non-adjacent pages of Process A and Process B, with two free frames. Arrows show pages swapped out to secondary storage and swapped back in.

Swapping pages

When virtual memory is in use, not every page of every process can stay in RAM. A paging algorithm decides which pages are swapped out of main memory into secondary storage, and which pages are swapped back into main memory when they are needed. It might move out pages that have not been used recently to make room for pages that a running process needs now.

For example, a games console running a large open-world game only has room in RAM for the pages covering the area the player is currently in. As the player travels into new territory, the paging algorithm swaps out the pages holding scenery the player has left behind to the console's storage, and swaps in the pages for the new area. If the player later walks back, those pages are swapped in again. The game was never closed or deleted; only some of its pages were moved temporarily.

Practise this