Memory Management Techniques: Segmentation vs. Paging

 
S
e
g
m
e
n
t
a
t
i
o
n
 
 
P
r
o
b
l
e
m
!
 
The virtual memory discussed so far is one-dimensional because the
virtual addresses go from 0 to some maximum address, one address
after another.
For many problems, having two or more separate virtual address
spaces may be much better than having only one.
 
Ali Akbar Mohammadi
 
2
 
E
x
a
m
p
l
e
:
 
C
o
m
p
i
l
e
r
 
Compiler has many tables that are built up as compilation proceeds,
possibly including:
1. 
The source text being saved for the printed listing (on batch systems).
2. 
The symbol table, containing the names and attributes of variables.
3. 
The table containing all the integer and floating-point constants used.
4. 
The parse tree, containing the syntactic analysis of the program.
5. 
The stack used for procedure calls within the compiler.
 
Ali Akbar Mohammadi
 
3
 
I
n
 
a
 
O
n
e
-
D
i
m
e
n
s
i
o
n
a
l
A
d
d
r
e
s
s
 
S
p
a
c
e
w
i
t
h
 
G
r
o
w
i
n
g
T
a
b
l
e
s
,
 
O
n
e
 
T
a
b
l
e
m
a
y
 
B
u
m
p
 
i
n
t
o
A
n
o
t
h
e
r
.
 
Ali Akbar Mohammadi
 
4
 
S
o
l
u
t
i
o
n
:
 
S
e
g
m
e
n
t
a
t
i
o
n
 
Each segment consists of a linear sequence of addresses, from 0 to
some maximum.
The length of each segment may be anything from 0 to the maximum
allowed. Different segments may, and usually do, have different
lengths. Moreover, segment lengths may change during execution.
The length of a stack segment may be increased whenever something
is pushed onto the stack and decreased whenever something is
popped off the stack.
 
Ali Akbar Mohammadi
 
5
 
A
 
S
e
g
m
e
n
t
e
d
 
M
e
m
o
r
y
 
A
l
l
o
w
s
 
E
a
c
h
 
T
a
b
l
e
 
t
o
 
G
r
o
w
o
r
 
S
h
r
i
n
k
 
I
n
d
e
p
e
n
d
e
n
t
l
y
 
o
f
 
t
h
e
 
O
t
h
e
r
 
T
a
b
l
e
s
.
 
Ali Akbar Mohammadi
 
6
 
C
o
m
p
a
r
i
s
o
n
 
o
f
 
P
a
g
i
n
g
 
a
n
d
 
S
e
g
m
e
n
t
a
t
i
o
n
 
Ali Akbar Mohammadi
 
7
 
I
m
p
l
e
m
e
n
t
a
t
i
o
n
 
o
f
 
P
u
r
e
 
S
e
g
m
e
n
t
a
t
i
o
n
 
The implementation of segmentation differs from paging in an
essential way: pages are fixed size and segments are not.
 
Ali Akbar Mohammadi
 
8
 
(
a
)
-
(
d
)
 
D
e
v
e
l
o
p
m
e
n
t
 
o
f
 
c
h
e
c
k
e
r
b
o
a
r
d
i
n
g
.
(
e
)
 
R
e
m
o
v
a
l
 
o
f
 
t
h
e
 
c
h
e
c
k
e
r
b
o
a
r
d
i
n
g
 
b
y
 
c
o
m
p
a
c
t
i
o
n
.
 
Ali Akbar Mohammadi
 
9
 
C
h
e
c
k
e
r
b
o
a
r
d
i
n
g
 
o
r
 
E
x
t
e
r
n
a
l
 
F
r
a
g
m
e
n
t
a
t
i
o
n
 
After the system has been running for a while, memory will be
divided up into a number of chunks, some containing segments and
some containing holes. This phenomenon, called 
checkerboarding 
or
external fragmentation
, wastes memory in the holes.
 
Ali Akbar Mohammadi
 
10
 
S
e
g
m
e
n
t
a
t
i
o
n
 
w
i
t
h
 
P
a
g
i
n
g
:
 
T
h
e
 
I
n
t
e
l
 
P
e
n
t
i
u
m
 
The Pentium supports up to 16K segments, each with up to 232 bytes
of virtual address space. The Pentium can be set up (by the operating
system) to use only segmentation, only paging, or both.
 
Ali Akbar Mohammadi
 
11
 
A
 
P
e
n
t
i
u
m
 
S
e
l
e
c
t
o
r
 
Ali Akbar Mohammadi
 
12
 
H
o
w
 
t
o
 
A
c
c
e
s
s
 
a
 
S
e
g
m
e
n
t
 
i
n
 
P
e
n
t
i
u
m
 
To access a segment, a Pentium program first loads a selector for that
segment into one of the machine's six segment registers.
During execution, the CS register holds the selector for the code
segment and the DS register holds the selector for the data segment.
The other segment registers are less important.
 
Ali Akbar Mohammadi
 
13
 
P
e
n
t
i
u
m
 
C
o
d
e
 
S
e
g
m
e
n
t
 
D
e
s
c
r
i
p
t
o
r
 
Ali Akbar Mohammadi
 
14
 
L
i
n
e
a
r
 
A
d
d
r
e
s
s
 
Assuming that the segment is in memory and the offset is in range,
the Pentium then adds the 32-bit 
base 
field in the descriptor to the
offset to form what is called a 
linear address
.
 
Ali Akbar Mohammadi
 
15
 
Ali Akbar Mohammadi
 
16
 
C
o
n
v
e
r
s
i
o
n
 
o
f
 
a
 
(
S
e
l
e
c
t
o
r
,
 
O
f
f
s
e
t
)
 
P
a
i
r
 
t
o
 
a
L
i
n
e
a
r
 
A
d
d
r
e
s
s
 
P
a
g
e
 
D
i
r
e
c
t
o
r
y
 
Each running program has a 
page directory 
consisting of 1024 32-bit
entries.
It is located at an address pointed to by a global register.
Each entry in this directory points to a page table also containing
1024 32-bit entries.
The page table entries point to page frames.
 
Ali Akbar Mohammadi
 
17
 
Ali Akbar Mohammadi
 
18
 
M
a
p
p
i
n
g
 
o
f
 
a
 
L
i
n
e
a
r
 
A
d
d
r
e
s
s
 
O
n
t
o
 
a
 
P
h
y
s
i
c
a
l
A
d
d
r
e
s
s
Slide Note
Embed
Share

Memory management is crucial in computer systems to optimize performance and resource utilization. Segmentation and paging are two important techniques used for managing memory efficiently. Segmentation allows for the independent growth and shrinking of different memory tables, while paging provides a way to efficiently use physical memory by breaking data into fixed-size blocks. By comparing these techniques, we can better understand their advantages and limitations in modern computing environments.

  • Memory management
  • Segmentation
  • Paging
  • Computer systems
  • Optimization

Uploaded on Aug 08, 2024 | 2 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Segmentation Segmentation

  2. Problem! Problem! The virtual memory discussed so far is one-dimensional because the virtual addresses go from 0 to some maximum address, one address after another. For many problems, having two or more separate virtual address spaces may be much better than having only one. Ali Akbar Mohammadi 2

  3. Example: Compiler Example: Compiler Compiler has many tables that are built up as compilation proceeds, possibly including: 1. The source text being saved for the printed listing (on batch systems). 2. The symbol table, containing the names and attributes of variables. 3. The table containing all the integer and floating-point constants used. 4. The parse tree, containing the syntactic analysis of the program. 5. The stack used for procedure calls within the compiler. Ali Akbar Mohammadi 3

  4. In a One In a One- - Dimensional Dimensional Address Space Address Space with Growing with Growing Tables, One Table Tables, One Table may Bump into may Bump into Another. Another. Ali Akbar Mohammadi 4

  5. Solution: Segmentation Solution: Segmentation Each segment consists of a linear sequence of addresses, from 0 to some maximum. The length of each segment may be anything from 0 to the maximum allowed. Different segments may, and usually do, have different lengths. Moreover, segment lengths may change during execution. The length of a stack segment may be increased whenever something is pushed onto the stack and decreased whenever something is popped off the stack. Ali Akbar Mohammadi 5

  6. A Segmented Memory Allows Each Table to Grow A Segmented Memory Allows Each Table to Grow or Shrink Independently of the Other Tables. or Shrink Independently of the Other Tables. Ali Akbar Mohammadi 6

  7. Comparison of Paging and Segmentation Comparison of Paging and Segmentation Consideration Paging Segmentation Need the programmer be aware that this technique is being used? No Yes How many linear address spaces are there? 1 Many Can the total address space exceed the size of physical memory? Yes Yes Can procedures and data be distinguished and separately protected? No Yes Can tables whose size fluctuates be accommodated easily? No Yes Is sharing of procedures between users facilitated? No yes Why was this technique invented? To get a large linear address space without having to buy more physical Memory To allow programs and data to be broken up into logically independent address spaces and to aid sharing and Protection Ali Akbar Mohammadi 7

  8. Implementation of Pure Segmentation Implementation of Pure Segmentation The implementation of segmentation differs from paging in an essential way: pages are fixed size and segments are not. Ali Akbar Mohammadi 8

  9. (a) (a)- -(d) Development of (d) Development of checkerboarding (e) Removal of the (e) Removal of the checkerboarding checkerboarding by compaction. checkerboarding. . by compaction. Ali Akbar Mohammadi 9

  10. Checkerboarding Checkerboarding or External Fragmentation or External Fragmentation After the system has been running for a while, memory will be divided up into a number of chunks, some containing segments and some containing holes. This phenomenon, called checkerboarding or external fragmentation, wastes memory in the holes. Ali Akbar Mohammadi 10

  11. Linear Address Linear Address Assuming that the segment is in memory and the offset is in range, the Pentium then adds the 32-bit base field in the descriptor to the offset to form what is called a linear address. Ali Akbar Mohammadi 15

  12. Conversion of a (Selector, Offset) Pair to a Conversion of a (Selector, Offset) Pair to a Linear Address Linear Address Ali Akbar Mohammadi 16

  13. Page Directory Page Directory Each running program has a page directory consisting of 1024 32-bit entries. It is located at an address pointed to by a global register. Each entry in this directory points to a page table also containing 1024 32-bit entries. The page table entries point to page frames. Ali Akbar Mohammadi 17

  14. Mapping of a Linear Address Onto a Physical Mapping of a Linear Address Onto a Physical Address Address Ali Akbar Mohammadi 18

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#