Difference between Paging and Segmentation
What is Paging?
Paging is one of the most important terms used in the operating system. Paging divides the physical memory into frames and program’s address space into identical size pages. The size of the page should be always stable. As we know that the dimension of the page should be provided by the hardware itself, it generally guides to internal fragmentation as the page is the fixed block size. In paging, page table is used to map pages with the frames from memory. Page table contains page location as well as frame location. Paging is invisible to the developers. Paging contains static linking and dynamic loading. A page is an actual unit.
Important Terminologies used in Paging
- Address represented in bits also known as logical address is generated by the CPU.
- Virtual address space the combination of all logical addresses are generated by a program.
- Physical address will appear on memory unit.
- The mapping from the computer generated address to physical address is performed by the memory management unit (MMU) which is hardware device and this process is known as paging technique.
- Physical address scope is divided into number of stable size blocks known as frames.
- Logical address scope is divided into fixed size blocks which are known as pages.
- Page size = frame size.
Memory Management Unit (MMU)
Memory management unit is used for converting logical addresses to physical addresses. Physical address is type of address of frame in which every page is stored, although the logical address is type of address which is generated by the CPU for each page. CPU approaches a page using its logical address. Operating system generally collects physical address in order to approach that page physically. It is also an important term used in operation system.
Physical address contains:
- Frame number(F)
Frame no. defines the number of bits which are required to represent the frame of physical address space also known as frame number. - Frame offset(d)
It is used to specify the number of bits required to represent a certain word in a frame, or the Physical Address Space frame size, the word number of a frame, or the frame offset.
Hardware implementation of the page table is performed by assigned registers. But the use of register is only beneficial in one condition when page table is too small. If the page table consists of a huge numbers of entries, then we use the TLB (Translation Look aside Buffer), a special, small, quick look up hardware cache.
- TLB is a close, high speed memory.
- Everyentry in TLB contains two parts, tag and value.
- When TLB is used then an item is compared with all tags. If the item is found, then equivalent value is returned.
What is Segmentation?
Segmentation is a memory management technique or process which is used to divide the program from the user's view of memory. It means the program is divided into modules or segments. The blocks that a program is divided into which are not of identical sizes are known as segments. Segmentation provides user view of process. This feature is not included in paging. In segmentation, user view is mapped to physical memory. Segmentation is also another type of non-contiguous memory allocation method like paging. Variable size partitioning is a theme of segmentation. It results in external fragmentation.
It is easy to appeal for protection in segmentation. In segmentation, segments are of different sizes. It also provides more efficient result then paging. It can handle data structures. In segmentation, list of holes is maintained by the operation system. Segments are also known as logical unit of information. There is also no restriction on size of segments. Segmentation is visible to the user and it eases sharing of methods between processes. In segmentation, processors require segment number.
Types of Segmentation
There are mainly two types of segmentations present in the operating system:
- Virtual Memory Segmentation: Virtual Memory Segmentation divides the processes into n number of segments. All the segments are not divided at a time. Virtual Memory Segmentation may or may not take place at the run time of a program.
- Simple Segmentation: In simple segmentation, every process is divided into number of segments, all of which loaded in memory at run time, not continuously.
Simple relationship cannot be maintained between logical and physical addresses in segmentation. A table collects the information related to all segments which is known segment table. Segment table maps 2D logical address into one dimensional physical address. Every entry of table contains base address and its limit.
- Base address: It consists of starting physical address where segments occupy in memory.
- Limit: The limit specifies the length of particular segment.
Address generated by CPU
- Segment number (S): It specifies the numbers of bits needed to present the segment.
- Segment offset (D): It specifies the numbers of bits needed to present the size of the segment.
Advantages of Segmentation
- There is no internal fragmentation in segmentation.
- In segmentation, segment table consumes less space as compare to page table in paging.
- Whole module is loaded only once and segmentation improves CPU utilization.
- It is a type of method which is used to segregate data from security operations.
- In segmentation, segment is specified by the user whereas in paging the hardware determines the page size.
Disadvantages of Segmentation
- The major disadvantage of segmentation is that the approach time to retrieve the instruction increases because in segmentation there are two memory accesses, one for segment table and another for main memory.
- Overhead is connected with keeping a segment table for each activity.
- As we know that processes are loaded as well as removed from the memory, the free memory space is divided into small pieces which results in external fragmentation.