Skip to main content

Paging

In Turkish
sayfalama
Updated 3 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/paging

In short

Paging is a memory management scheme that splits memory into fixed-size pages and uses page tables to map each process's virtual pages to physical RAM.

What is paging in operating systems?

Paging is the technique most operating systems use to implement virtual memory. Each process's virtual address space is divided into fixed-size blocks called pages, commonly 4 KB, and physical RAM is divided into frames of the same size. Any page can be placed in any free frame, so a process's memory does not need to be one continuous region of RAM.

Every virtual address is split into a page number and an offset within the page. The CPU's memory management unit looks up the page number in the process's page table, a multi-level tree on 64-bit systems, to find the matching frame, and a small cache called the translation lookaside buffer (TLB) remembers recent lookups so most translations are nearly free. Each page table entry also holds flags, such as whether the page is present, writable, or executable. If the page is not present, the CPU raises a page fault, and the kernel loads the page from disk, updates the table, and retries the instruction.

Paging is like a book printed on loose, numbered pages that are stored in whichever slots of a big filing cabinet happen to be free, with an index card saying which slot holds each page. Because pages are loaded only when first touched, known as demand paging, programs start quickly and unused parts never take up RAM. Paging also enables shared libraries, memory-mapped files, and copy-on-write, where a forked process shares its parent's pages until one of them writes.

Paging is often confused with virtual memory and with swapping. Virtual memory is the overall idea of giving each process a private address space, and paging is the main mechanism that implements it. Swapping, or paging out, is what happens when the kernel moves pages to swap space on disk because RAM is full. Paging in an operating system is also unrelated to pagination in web APIs, which splits long result lists into pages.

Key takeaways

  • Memory is divided into fixed-size pages, commonly 4 KB, and RAM into frames.
  • Page tables map each virtual page to a physical frame.
  • The TLB caches recent translations so lookups stay fast.
  • Accessing a page that isn't in RAM causes a page fault, which the kernel handles.
  • Paging is the main mechanism behind virtual memory.

Example

A toy page table lookup in Pythonpython
PAGE_SIZE = 4096  # 4 KB pages

def translate(virtual_addr, page_table):
    page_number = virtual_addr // PAGE_SIZE
    offset = virtual_addr % PAGE_SIZE
    if page_number not in page_table:
        raise RuntimeError("page fault: the kernel must load this page")
    frame = page_table[page_number]
    return frame * PAGE_SIZE + offset

# Virtual page 2 is stored in physical frame 7
print(hex(translate(0x2ABC, {2: 7})))  # 0x7abc

Readers ask

What is a page fault?

A page fault is the CPU's signal that a program touched a page that isn't currently mapped to RAM. A minor fault is resolved without disk access, for example by mapping a page already in memory, while a major fault requires reading the page from disk and is much slower.

What is the TLB?

The translation lookaside buffer is a small cache inside the CPU that stores recent virtual-to-physical address translations. It saves the CPU from walking the page table on almost every memory access.

What is the difference between paging and swapping?

Paging is the general scheme of managing memory in fixed-size pages. Swapping means moving pages out of RAM to swap space on disk when memory runs low, and reading them back when they are needed.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings