Difference Between Paging and Segmentation in OS
The memory management in the operating system is an essential functionality, which allows the allocation of memory to the processes for execution and deallocates the memory when the process is no longer needed. In this article, we will discuss two memory management schemes paging and segmentation. The basic difference between paging and segmentation is that, “page” is a fixed-sized block whereas, a “segment” is a variable-sized block.
NOTE : 其实,这个差别就决定了segment是需要记录下它的每个block的size的,而page显然不需要
We will discuss some more differences between Paging and Segmentation with the help of comparison chart shown below.
Content: Paging Vs Segmentation
Comparison Chart
BASIS FOR COMPARISON | PAGING | SEGMENTATION |
---|---|---|
Basic | A page is of fixed block size. | A segment is of variable size. |
Fragmentation(碎片) | Paging may lead to internal fragmentation. | Segmentation may lead to external fragmentation. |
Address | The user specified address is divided by CPU into a page number and offset. | The user specifies each address by two quantities a segment number and the offset (Segment limit). |
Size | The hardware decides the page size. | The segment size is specified by the user. |
Table | Paging involves a page table that contains base address of each page. | Segmentation involves the segment table that contains segment number and offset (segment length). |
Definition of Paging
Paging is a memory management scheme. Paging allows a process to be stored in a memory in a non-contiguous manner. Storing process in a non-contiguous manner solves the problem of external fragmentation.
For implementing paging the physical and logical memory spaces are divided into the same fixed-sized blocks. These fixed-sized blocks of physical memory are called frames, and the fixed-sized blocks of logical memory are called pages.
SUMMARY :注意**pages**和**frames**的含义是不同的;
When a process needs to be executed the process pages from logical memory space are loaded into the frames of physical memory address space. Now the address generated by CPU for accessing the frame is divided into two parts i.e. page number and page offset.
The page table uses page number as an index; each process has its separate page table that maps logical address to the physical address. The page table contains base address of the page stored in the frame of physical memory space. The base address defined by page table is combined with the page offset to define the frame number in physical memory where the page is stored.
Definition of Segmentation
Like Paging, Segmentation is also a memory management scheme. It supports the user’s view of the memory. The process is divided into the variable size segments and loaded to the logical memory address space.
The logical address space is the collection of variable size segments. Each segment has its name and length. For the execution, the segments from logical memory space are loaded to the physical memory space.
The address specified by the user contain two quantities the segment name and the Offset. The segments are numbered and referred by the segment number instead of segment name. This segment number is used as an index in the segment table, and offset value decides the length or limit of the segment. The segment number and the offset together combinely generates the address of the segment in the physical memory space.
Key Differences Between Paging and Segmentation
- The basic difference between paging and segmentation is that a page is always of fixed block size whereas, a segment is of variable size.
- Paging may lead to internal fragmentation as the page is of fixed block size, but it may happen that the process does not acquire the entire block size which will generate the internal fragment in memory. The segmentation may lead to external fragmentation as the memory is filled with the variable sized blocks.
- In paging the user only provides a single integer as the address which is divided by the hardware into a page number and Offset. On the other hands, in segmentation the user specifies the address in two quantities i.e. segment number and offset.
- The size of the page is decided or specified by the hardware. On the other hands, the size of the segment is specified by the user.
- In paging, the page table maps the logical address to the physical address, and it contains base address of each page stored in the frames of physical memory space. However, in segmentation, the segment table maps the logical address to the physical address, and it contains segment number and offset (segment limit).
Conclusion:
Paging and segmentation both are the memory management schemes. Paging allows the memory to be divided into fixed sized block whereas the segmentation, divides the memory space into segments of the variable block size. Where the paging leads to internal fragmentation the segmentation leads to external fragmentation.