Paging and segmentation are processes by which data is stored to and then retrieved from a computer’s storage disk. Paging is a computer memory management function that presents storage locations to the computer’s central processing unit (CPU) as additional memory, called virtual memory. Segmentation is a virtual process that creates variable-sized address spaces in computer storage for related data, called segments.
Paging provides a storage address for each piece of data, while the segmentation process speeds storage retrieval. No system can efficiently rely on limited RAM alone. So the computer’s memory management unit (MMU) uses the storage drives, a hard disk drive (HDD) or solid-state drive (SSD), as virtual memory to supplement RAM. Managing computer memory is a basic but critical operating system function. This guide to paging and segmentation breaks down the differences between each technology, including their benefits and drawbacks.
Key differences between paging and segmentation
Although paging and segmentation are both critical components of computer memory, they accomplish memory allocation differently and are prone to different fragmentation issues.
|Size||The system has a fixed block size for pages and frames. Computer hardware determines page/frame sizes.||Segments can vary in size, and the system user specifies that size.|
|Fragmentation||Older systems were subject to internal fragmentation by not allocating entire pages to memory. Modern operating systems no longer have this problem.||Segmentation leads to external fragmentation.|
|Tables||Page tables direct the MMU to page location and status. This is a slower process than segmentation tables, but TLB memory cache accelerates it.||Segmentation tables contain segment ID and information, and are faster than direct paging table lookups.|
|Availability||Widely available on CPUs and as MMU chips.||Windows servers may support backwards compatibility, while Linux has very limited support.|
What is paging?
When paging occurs, storage locations are presented to the CPU as virtual memory. In the paging process, a page table stores the definition of each page. When an active process requests data, the MMU retrieves corresponding pages into frames located in physical memory for faster processing. These are various elements in the paging process:
- Page: A fixed-length contiguous block of virtual memory residing on disk.
- Frame: A fixed-length contiguous block located in RAM, with sizing identical to pages.
- Physical memory: The computer’s random access memory (RAM), typically contained in DIMM cards attached to the computer’s motherboard.
- Virtual memory: Virtual memory is a portion of an HDD or SSD that is reserved to emulate RAM. The MMU serves up virtual memory from disk to the CPU to reduce the workload on physical memory.
- Virtual address: The CPU generates a virtual address for each active process. The MMU maps the virtual address to a physical location in RAM and passes the address to the bus. A virtual address space is the range of virtual addresses under CPU control.
- Physical address: The physical address is a location in RAM. The physical address space is the set of all physical addresses corresponding to the CPU’s virtual addresses. A physical address space is the range of physical addresses under MMU control.
By assigning an address to a piece of data using a page table between the CPU and the computer’s physical memory, a computer’s MMU enables the system to retrieve that data whenever needed.
How does paging work?
The MMU uses page tables to translate virtual addresses to physical ones. Each table entry indicates where a page is located: in RAM or on disk as virtual memory. Tables may have a single or multi-level page table, such as different tables for applications and segments.
However, constant table lookups can slow down the MMU. To help with this, a memory cache called the Translation Lookaside Buffer (TLB) stores recent translations of virtual to physical addresses for rapid retrieval. Many systems have multiple TLBs, which may reside at different locations, including between the CPU and RAM or between multiple page table levels.
Different frame sizes are available for datasets with larger or smaller pages and matching-sized frames; 4 KB to 2 MB are common sizes, and GB-sized frames are available in high-performance servers.
Learn more about memory management in operating systems.
Advantages of paging
Some advantages of paging include:
- For programmers, paging is a transparent function that doesn’t require intervention.
- Paging doesn’t cause external fragmentation, and on properly updated operating systems, it doesn’t have internal fragmentation problems either.
- Frames in paging don’t have to be contiguous.
Disadvantages of paging
Paging causes internal fragmentation on older systems. An issue called hidden fragmentation used to be a problem in older Windows deployments. The problem was internal, or hidden, fragmentation. Unlike the serious external fragmentation of segmenting, internal fragmentation occurred if every frame was not the exact size of the page size. This is not an issue in modern Windows operating systems, but it does affect organizations that still use older systems.
Paging has longer memory lookup times than segmentation, though TLB memory caches can help, especially systems that have many TLBs.
Learn more about disk fragmentation and the problems it poses to storage systems.
What is segmentation?
Segmentation is a virtual process that creates address spaces of various sizes in a computer system, called segments. Each segment is a different virtual address space that directly corresponds to process objects. There are various elements in the segmentation process, including the CPU, segment table, which includes details on the segment, and physical memory or the computer’s RAM in the motherboard:
Segmentation speeds up a computer’s information retrieval by assigning related data into a segment table between the CPU and the physical memory.
How does segmentation work?
When a process executes, segmentation assigns related data into segments for faster processing. The segmentation function maintains a segment table that includes physical addresses of the segment, size, and other data.
Each segment stores the processes’ primary function, data structures, and utilities. The CPU keeps a segment map table for every process and memory blocks, along with segment identification and memory locations.
The CPU generates virtual addresses for running processes. Segmentation translates the CPU-generated virtual addresses into physical addresses that refer to a unique physical memory location. The translation is not strictly one-to-one: different virtual addresses can map to the same physical address.
Learn more about physical and virtual addresses.
Advantages of segmentation
Some benefits of segmentation include:
- Segmentation doesn’t cause any internal fragmentation
- Segment tables consume less space compared to paging tables
- Segmentation requires less processing overhead than paging.
- Segmentation makes relocating segments simpler than relocating contiguous address spaces on a disk
- Segment tables take up less memory
Disadvantages of segmentation
Although segmentation is a high-speed and highly secure memory management function, external fragmentation proved to be an insurmountable challenge. Segmentation causes external fragmentation to the point that modern x86-64 servers treat it as a legacy application and only support it for backward compatibility.
External fragmentation occurs when unusable memory is located outside of allocated memory blocks. The issue is that the system may have enough memory to satisfy process requests, but the available memory is not in a contiguous location. In time, the fragmentation worsens and significantly slows the segmentation process.
Linux only supports segmentation in 80×86 microprocessors, stating that paging simplifies memory management by using the same set of linear addresses. Porting Linux to different architectures is problematic because of limited segmentation support.
Bottom line: paging vs. segmentation
Paging and segmentation are both basic technologies for operating systems to make storage memory available to computers. Both are subject to fragmentation, but paging causes internal fragmentation for outdated computers, and segmentation causes significant external fragmentation. These storage technologies are only two examples of the ways current storage speed and capacity needs outstrip what many computer systems can handle.