Paged Segmentation and Segmented Paging
Major Limitation of Single Level Paging
A big challenge with single level paging is that if the logical address space is large, then the page table may take up a lot of space in main memory. For instance, consider that logical address is 32 bit and each page is 4 KB, the number of pages will be 2^20 pages. The page table without additional bits will be of the size 20 bits * 220 or 2.5 MB. Since each process has its own page table, a lot of memory will be consumed when single level paging is used. For a system with 64-bit logical address even a page table of single process will not fit in main memory. For a process with a large logical address space, a lot of its page table entries are invalid as a lot of the logical address space goes unused.
A solution to the problem is to use segmentation along with paging to reduce the size of page table. Traditionally, a program is divided into four segments, namely code segment, data segment, stack segment and heap segment.
The size of the page table can be reduced by creating a page table for each segment. To accomplish this hardware support is required. The address provided by CPU will now be partitioned into segment no., page no. and offset.
The memory management unit (MMU) will use the segment table which will contain the address of page table(base) and limit. The page table will point to the page frames of the segments in main memory.
Advantages of Segmented Paging
- The page table size is reduced as pages are present only for data of segments, hence reducing the memory requirements.
- Gives a programmers view along with the advantages of paging.
- Reduces external fragmentation in comparison with segmentation.
- Since the entire segment need not be swapped out, the swapping out into virtual memory becomes easier .
Disadvantages of Segmented Paging
- Internal fragmentation still exists in pages.
- Extra hardware is required
- Translation becomes more sequential increasing the memory access time.
- External fragmentation occurs because of varying sizes of page tables and varying sizes of segment tables in today’s systems.
- In segmented paging, not every process has the same number of segments and the segment tables can be large in size which will cause external fragmentation due to the varying segment table sizes. To solve this problem, we use paged segmentation which requires the segment table to be paged. The logical address generated by the CPU will now consist of page no #1, segment no, page no #2 and offset.
- The page table even with segmented paging can have a lot of invalid pages. Instead of using multi level paging along with segmented paging, the problem of larger page table can be solved by directly applying multi level paging instead of segmented paging.
Advantages of Paged Segmentation
- No external fragmentation
- Reduced memory requirements as no. of pages limited to segment size.
- Page table size is smaller just like segmented paging,
- Similar to segmented paging, the entire segment need not be swapped out.
Disadvantages of Paged Segmentation
- Internal fragmentation remains a problem.
- Hardware is complexer than segmented paging.
- Extra level of paging at first stage adds to the delay in memory access.