Professional Documents
Culture Documents
Demand paging
and
Segmentation
1
Click to edit Master title style
Demand paging and Segmentation
2 2
Click to edit Master title style
Scope
This article explains segmentation
and demand paging in detail.
DEFINITON
Users want to see memory as a collection of
variable-sized segments with no necessary
ordering of segments. They do not want to view
memory as a linear array of bytes.
3 3
• A logical grouping of instructions such as subroutine, array, or
Click to edit Master title style
data is called a segment. Every program is a collection of
these segments.
• The main program includes various data structures such as
objects, arrays, stacks, variables, etc. Each of these
segments is of variable length where length is the purpose of
the segment in the program. Elements within a segment are
identified by their offset from the beginning of the segment.
• Segmentation is a memory management scheme that
supports the user’s view of memory. A logical address space
is a collection of segments. Each segment has a name and
length.
• The segment name and the offset within the segment are
specified by the addresses. A logical address consists of:
4 4
Click to edit Master title style
A C compiler creates separate segments for
the following :
1.The code
2.Global variables
3.The heap from which memory
is allocated.
4.The stacks are used for each
thread.
5.The standard C library
The mapping of logical addresses into physical
memory is done with the help of a segment table.
Each entry in the segment table has a segment
base and segment limit. The segment base
contains the starting physical addresses where
the segments reside in the memory and the
segment limit specifies the length of the
segment.
5 5
Click to edit Master title style
A logical address consists of two
parts: a segment number and
an offset into that segment (d).
The segment number is used as
an index to the segment table.
The offset d of the logical
address must be between 0 and
the segment limit. If it is not, we
trap the OS. When an offset is
legal, it is added to the segment
to produce the address in the
physical memory of the desired
byte. The segment table is an
array of base limit register pairs. Segment 2 is 400 bytes long and begins at 4300. Thus, a reference to byte
53 of segment 2 is mapped to location 4300 + 53 = 4353. A reference to
segment 3, byte 852 is mapped to 3200 + 852 = 4052. A reference to byte
1222 of segment 0 would result in the trap as this segment is only 1000
bytes long.
6 6
Click to edit Master title style
Advantages
-It eliminates fragmentation.
-Segmentation supports virtual memory.
-It allows dynamically growing segments.
-It facilitates shared segments
-It provides dynamic linking and loading of segments..
7 7
Click to edit Master title style
Demand Paging
Sometimes we may not initially need the entire program in memory. To solve this problem we use a technique called
demand paging. In demand paging, we initially load pages only as they are needed. It is commonly used in virtual
memory systems.
In-demand paged virtual memory pages are only loaded when they are demanded during program execution. Pages
that are never demanded are thus never loaded into physical memory.
To swap the process into the memory a lazy swapper is used, it never swaps a page into the memory unless that page
will be needed.
8 8
Click to edit Master title style
Demand Paging
A pager is used for demand paging because a pager is concerned with the individual pages of a process, unlike a
swapper which manipulates the entire process. When a process is to be swapped in, the pager guesses which pages
will be used before the process is swapped out again. The pager only brings the guessed pages into the memory.
Thus, it avoids reading into memory pages that are not going to be used. And doing this decreases the swap time and
the amount of physical memory needed.
The valid and invalid bit scheme is described. The pages are legal and in memory when the bit is set valid. And if the
bit is set to invalid then the page can be either valid or invalid. But it will remain on the disk. The page table entry for
a page that is brought into memory is marked as valid but the page entry that is not currently in memory is simply
marked as invalid.
9 9
Click to edit Master title style
1010
Click to edit Master title style
The procedure is as
follows:
1111
Click to edit Master title style
1212
1.Click
What is a segment in memory
to edit Master title style management?
2. What is the purpose of segmentation in a program?
3. What is a logical address in memory segmentation?
4. What are the separate segments created by a C compiler?
5. How is the mapping of logical addresses into physical
memory done in segmentation?
6. What are the two parts of a logical address in
segmentation?
7. What happens when an offset in a logical address is not
within the segment limit?
8. What is demand paging?
9. How does demand paging handle pages that are not
demanded?
10. What is the procedure for handling a page fault trap in 1313