Summary
Highlights
A segmented memory management system uses the computer's physical memory (RAM) and a swap file on the hard drive. Running programs, called processes, occupy different amounts of memory as 'segments.' The operating system knows the starting location and size of each segment. When memory fills, idle processes are moved to disk to make room for new ones. Each process is atomic and cannot be split, leading to potential fragmentation where free space exists but isn't contiguous for larger processes.
In segmented memory, segments are swapped between disk and main memory as needed. Program segments correspond to code blocks (procedures, functions) and data segments to data structures (stacks, queues). Segments vary in size, and the OS tracks their start and size. A segment is entirely in RAM or entirely on disk. A segment in memory can only be replaced by a segment of the same size or smaller. This can lead to memory fragmentation, hindering large segments from being loaded frequently unless compaction occurs.
With paged memory, each program appears to have the entire memory to itself (logical memory), even though it's not true. Programs are broken into equal-sized 4KB pages, which can be anywhere in physical memory or on secondary storage. The operating system maintains a page table to map logical to physical locations. Pages can be loaded in a fragmented state, and unused pages are 'paged out' to disk to free up space. This use of secondary storage to extend RAM is called virtual memory.
In busy systems, when memory is nearly full, there can be excessive paging activity, called 'disk thrashing' or 'disk threshing,' which severely degrades computer performance. Paged memory splits memory into small, equal-sized pages that are not necessarily contiguous for a single application. A page table tracks their location, and pages are swapped in and out of a disk's swap file as needed.
Segmented memory provides entire blocks of code, allowing for faster access, but is prone to fragmentation, making it difficult for large processes to get into memory. Paged memory, while leading to fragmented processes that might run slower, utilizes free space more efficiently. Windows uses paged memory, while segmented memory is less common. Some processors combine both approaches, using segments composed of fixed-size blocks ('best of both worlds').