You are on page 1of 7

Describe Segmentation process and

comparison of segmentation with paging:

Segmentation process:
The concept of segmentation in os is similar to paging which is used for
memory management. Segmentation divides the user program and the data
associated with the program into the number of segments. Well, there is a
difference between paging and segmentation in paging each page has an
equivalent fixed size whereas segments are of variable size.

 Further, we will discuss segmentation in brief along with its workflow.

 What is Segmentation in OS?


Segmentation is used for memory management where user’s view is
plotted onto the physical memory. In segmentation, the user program is
divided into the number of segments where each segment is of variable
size.

Segmentation may appear to you as a dynamic partitioning the where


divided segments are of variable size. These segments need not be
placed in contiguous memory. Thus segmentation does not create
internal fragmentation but it may create external fragmentation.

From the user’s view, a program has segments such as the main
method, with a set of objects, methods, arrays, procedures, global
variables, templates etc. So these modules or data elements are the
segments to which user refers it by its name without concerning at what
address these modules or elements are stored in memory. Neither the
user is worried about in which sequence the modules or data elements
are stored in memory.

Each segment of the user program is of variable length and the length
of the segment is decided by the purpose of the segment in the user
program. Now, in logical addressing, the elements in a particular
segment are identified by their offset value starting from the beginning
of the segment. The logical address of a segment is always known by
the two entities segment name and the offset. The segments created
from a user program are numbered and for simplicity, each segment is
referred to as by the segment number instead of the segment name.
So, now the logical address has two tuples.

<segment-number, offset>

 Why Segmentation is required?


Till now, we were using Paging as our main memory management technique. Paging is
more close to Operating system rather than the User. It divides all the process into the
form of pages regardless of the fact that a process can have some relative parts of
functions which needs to be loaded in the same page.

Operating system doesn't care about the User's view of the process. It may divide the
same function into different pages and those pages may or may not be loaded at the
same time into the memory. It decreases the efficiency of the system.

It is better to have segmentation which divides the process into the segments. Each
segment contain same type of functions such as main function can be included in one
segment and the library functions can be included in the other segment,

Implementation of Segmentation
Let us now see the implementation of segmentation. As we know in
segmentation the user program is divided into the number of segments. And a
segment is identified by two components i.e. a segment name and segment
offset.

In this section, we will see how this two-dimensional address is mapped onto
the one-dimensional physical memory. Like we have page table in paging
similarly we have a segment table in segmentation.

Segmentation Table
The segment table has two entries for each segment i.e. segment base
address and segment limit. The segment base address denotes the starting
address where the segment is stored in the memory while the segment
limit denotes the length of the segment.
Let us understand the workflow of the segment table with the help of the figure
given below.

As in the figure above you can see that the CPU calls outs for a segment and
logically provides a two-dimensional address for that segment where the first
entity s is the segment number (segment name) and its offset d.

Now the segment number would help to find two more details regarding the
segment number in segment table i.e. segments base address and its limit.
On the other hand, the offset provides by CPU is verified whether it is
between 0 and the limit of called segment if yes then the offset is added to the
base address of called segment to retrieve the physical address of the
segment. If the offset doesn’t verify the condition the operating system is
trapped with addressing error i.e. the logical address tries to attempt beyond
the segment limit.
Example of Segmentation in OS
Consider that a user program has been divided into five segments and they
are numbered from segment 0 to segment 4, as you can see them in the
logical address space. You also have a segment table which has entries for
these segment with their base address in physical memory and their limit.

Now suppose the CPU calls for segment number 2 which is 400 bytes long
and it resides at 4300 memory location. The CPU wants to refer the 53rd byte
of segment 2. So, here the input we get from CPU is segment number 2 and
53 as an offset.

Now the offset is in between 0 and limit of the segment 2 i.e. 400. So, the
condition got verified and the offset is being added to the base address of the
segment 2 to reach the 53rd byte of the segment 2 in physical memory.  In
case you try to access the 453rd byte of segment 2 then it would result in a trap
to the operating system as offset value 453 is greater than the limit of
segment 2.

Advantages of Segmentation
1. No internal fragmentation
2. Average Segment Size is larger than the actual page size.
3. Less overhead
4. It is easier to relocate segments than entire address space.
5. The segment table is of lesser size as compare to the page table in paging.

Disadvantages
1. It can have external fragmentation.
2. it is difficult to allocate contiguous memory to variable sized partition.
3. Costly memory management algorithms.

Key Takeaways
 Segmentation used for memory management.
 The concept of segmentation is close to the user’s view of physical
memory.
 Segmentation divides the user program into variable-length segments
where the length of the segments depends upon its purpose in the program.
 Segmentation includes a segment table which is an array of the base
address and limits where base address denotes the location of a particular
segment in the physical memory and limit denote the segment length.
 Segmentation leads to external fragmentation.

Paging:
What is Paging?
Paging is a storage mechanism that allows OS to retrieve processes from the
secondary storage into the main memory in the form of pages. In the Paging
method, the main memory is divided into small fixed-size blocks of physical
address, which is called frames.
The size of a frame should be kept the same as that of a page to have
maximum utilization of the main memory and to avoid external fragmentation.
Paging is used for faster access to data, and it is a logical concept.

Advantages of Paging
Here, are pros/benefits of using Paging method

 On the programmer level, paging is a transparent function and does not


require intervention.
 Frames do not have to be contiguous.
 Easy to use memory management algorithm
 Swapping is easy between equal-sized pages and page frames.

Disadvantages of Paging
Here, are cons/drawbacks of Paging:

 Paging causes internal fragmentation on older systems.


 Longer memory lookup times compared to segmentation
 It may cause internal fragmentation
 Complex memory management algorithm
 Page tables consume additional memory.
 Multi-level paging may lead to memory reference overhead.

Paging VS Segmentation
Paging Segmentation
A page is of the fixed block size. A segment is of variable size.
It may lead to internal fragmentation. It may lead to external fragmentation.
In Paging, the hardware decides the The segment size is specified by the
page size. user.
A process address space is broken A process address space Is broken
into fixed-sized blocks, which is in differing sized blocks called
called pages. sections.
The paging technique is faster for Segmentation is slower than paging
memory access. method.
Page table stores the page data Segmentation table stores the
segmentation data.
Paging does not facilitate any Segmentation allows for the sharing
sharing of procedures. of procedures.
Paging fails to distinguish and secure Segmentation can be able to
procedures and data separately. separate secure procedures and
data.
Paging address space is one In segmentation, there is the
dimensional availability of many independent
address spaces
In paging, the user just provides a In the segmentation method, the
single integer as the address, that is user specifies the address in two
divided by the hardware into a page quantities 1)segment number
number and offset. 2)offset.

You might also like