Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paging or segmentation for virtual memory, which is better?

Most OSes use paging for virtual memory. Why is this? Why not use segmentation? Is it just because of a hardware issue? Is one better than the other in certain cases? Basically, if you had to choose one over the other, which one would you want to use and why?

Let's assume it's an x86 for argument's sake.

like image 850
Matt Avatar asked Jun 02 '11 14:06

Matt


People also ask

Is segmentation used in virtual memory?

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.

Why is paging important for virtual memory?

Paging acts as an important part of virtual memory, as it allows programs in secondary storage to exceed the available size of the physical storage.

Why is paging faster than segmentation?

In paging, the pages are of the same size. In segmentation, the segments are of different sizes. The page size in paging depends on the hardware, while the segment size in segmentation is determined by the programmer. Memory access in paging is faster than segmentation.


2 Answers

OS like windows and Linux use a combination of both segmentation and paging. The virtual memory of a process is first divided into segments and then each segment consists of a lot of pages. The OS first goes to the specific segment and in that segment it then locates the particular page to access an address

like image 131
lovesh Avatar answered Sep 28 '22 01:09

lovesh


Taken from :operating systems concepts by galvin

one of the issues..

Segmentation permits the physical address space of a process to be non- contiguous. Paging is another memory-management scheme that offers this advantage. However, paging avoids external fragmentation and the need for compaction, whereas segmentation does not.

Segmentaion problem: The problem arises because, when code fragments or data residing in main memory need to be swapped out, space must be found on the backing store. The backing store has the same fragmentation problems but access is much slower, so compaction is impossible.

Paging solves it by:

The basic method for implementing paging involves breaking physical memory into fixed-sized blocks called frames and breaking logical memory into blocks of the same size called pages.The backing store is divided into fixed-sized blocks that are the same size as the memory frames or clusters of multiple frames.

Since pages-frames-The backing store all are divided into same size so it doesn't lead to external fragmentation. But may have internal fragmentation. So pagesize must be chosen correctly

Operating Systems concepts

like image 23
sourav punoriyar Avatar answered Sep 28 '22 02:09

sourav punoriyar