Lesson 06 - Memory - en
Lesson 06 - Memory - en
Lesson 06 –
Memory management
PRESENTER: THS. HUỲNH HOÀNG HÀ
Content 2
1. Objectives
2. Introduction
3. Continuous Allocation
4. Discontinuous Allocation
5. Virtual memory
6. Summary
7. Quizzes & Answers
8. Lesson Test
3
0x5100
loading time Application01
0x5013
Application01 ???
0x10300 (base)
0x5000
Application02
Physical
CPU memory
3.2. Base & Bound 11
Base&Bound uses: + 1 Base Register stores the Base address.
+ 1 Bound (Limit) Register stores the size of Phy_Add_Space.
Application02
Physical
CPU memory
3.2. Base & Bound 12
Base&Bound uses the following formula:
if (Relative_address < Bound)
Physical address = Base address + Relative address;
else
Error;
(With: Relative_addr = Logical_addr – Starting_logical_Addr)
External Fragmentation is the phenomenon: "Memory has many free areas but
scattered (discontinuous)"
Solution 1: Use the memory compaction technique. This technique rearrages
the memory, to make free areas continuously.
Solution 2: Use Discontinuous Allocation.
Content 14
1. Objectives
2. Introduction
3. Continuous Allocation
1. Linker_Loader
2. Base & Bound
4. Discontinuous Allocation
1. Segmentation
2. Paging
3. Segmented paging
5. Virtual memory
6. Summary
7. Quizzes & Answers
8. Lesson Test
4. Discontinuous Allocation 15
The process is divided into several parts. These parts are saved in different
memory areas.
Includes:
Segmentation
Paging
Segmented paging
4.1. Segmentation 16
segment table
The process is divided into several segment. Each segment has different size.
The details about each segment are stored in a table, called a segment table.
Segment table contains:
Base: It is the base address of the segment.
Limit: It is the length of the segment.
4.1. Segmentation 17
* How does Logical address translate into physical
address ??? *
Answer:
1. CPU generates a logical address which
contains two parts:
Segment Number (s) – index.
Offset (d)
2. Use the segment table.
=> ------------------------------------
if (d < limit)
Physical address = base + d;
else
Error;
4.1. Segmentation 18
Example:
Look at the Image, what is the value of Segment
Table?
Look at the Image, What is the range of the
offset(d) in the segment 2?
4.1. Segmentation 19
Example:
What is the Physical address, if ?
1. The logical address in the main(), has the
offset(d) is 125.
2. The logical address in Segment 4, has the
offset(d) is 515.
3. The logical address in Segment 0, has the
offset(d) is 1300.
4.1. Segmentation 20
Example:
What is the Physical address, if ?
1. The instruction (logical address) in the main(),
has the offset(d) is 125.
2. The instruction (logical address) in Segment 4,
has the offset(d) is 515.
3. The instruction (logical address) in Segment 0,
has the offset(d) is 1300.
4.1. Segmentation 21
Processes can share physical memory area for the same segments.
Ex: subfunctions.
4.2. Paging 22
Process (logical address space) is split into several small parts. All of parts has
the same size, called page. (fixed size = 2n)
The physical memory is split into the small blocks, known as frames.
The frame size = the page size.
4.2. Paging 23
* How does Logical address translate into physical
address ??? *
Answer:
1. CPU generates a logical address which
contains two parts:
Page Number (p) [size: m bit]
Offset (d) [size: n bit = size of page]
2. Use the page table.
3. Physical address = f * 2^n + d.
(size of f = size of p = m)
Ex: f=0x03, n = 4 bit, d = 0x5
=> Phys = 0x03 * 2^4 + 0x5
=> Phys = 0x035
4.2. Paging 25
1. CPU generates a logical address which
Look at the Image: contains two parts:
1. What is the size of Offset (d) in bit ? (n=?) Page Number (p) [size: m bit]
Offset (d) [size: n bit = size of page]
2. Determine f in the Page table ? 2. Use the page table.
3. What is the Physical address, 3. Physical address = f * 2^n + d.
If [p, d] = [2, 200]
0x0100
If [p, d] = [4, 300] 0x0200
0x0300
0x0400
0x0500
0x0600
0x0700
0x0800
4.2. Paging 26
1. CPU generates a logical address which
Look at the Image: contains two parts:
1. What is the size of Offset (d) in bit ? (n=?) Page Number (p) [size: m bit]
Offset (d) [size: n bit = size of page]
2. Determine f in the Page table ? 2. Use the page table.
3. What is the Physical address, 3. Physical address = f * 2^n + d.
If [p, d] = [2, 200]
0x0100
If [p, d] = [4, 300] 0x0200
0x0300
0x0400
0x0500
0x0600
0x0700
0x0800
4.2. Paging 27
142 bytes
Page 4 114 bytes(Free)
The size of page = the size of frame = 2^8 = 256 byte ( Frame size is fixed)
The size of process(P) = 910 byte => (P) splits into 4 pages:
Page1(256 B) – Page2(256 B) – Page3(256 B) – Page4(142 B)
=> Physical need 4 Frames. Size of Frame4 = 256 B, but only store 142 B.
=> known as: Internal Fragmentation.
4.3. Segmented Paging 33
The process splits into many segments,
Then every segment splits into pages.
A logical address contains three parts:
Segment Number (s)
Page Number (p)
Offset (d)
Use 2 kinds of table:
Segment table
Page table
Advantages:
Reduce the size of page table
Easy for managing data
Read more.
5. Virtual memory 34
Situation: Size of RAM is limit. Many processes need to run.
Virtual memory is a technique:
Load a portion of process into RAM for executing.
Stores the other parts of process in Disk (HDD/SSD).
MMU will swap all parts of process in and out of RAM for running.
[Pros] The OS can run more processes concurrently.
[Cons] Using combination of main memory and auxiliary memory
makes the system run slower than only using the main memory.
Ex: Window10(Virtual memory)
6. Summary 35
The OS provides the mechanisms for memory management, mapping from
Logical address to Physical address, for using the main memory efficiently.
There are 2 allocation methods:
Continuous allocation: (Linker&Loader, Base&Bound)
[Pros] Simple configuration
[Cons] Need a large contiguous memory area to hold the entire process
Discontinuous allocation: (Segmentation, Paging, Segmented Paging)
[Cons] Hard configuration
[Pros] Process can split and store in discontinuous memory area
[Pros] Manage memory more flexible and better.
[Pros] Can use the virtual memory technique.
Virtual memory is a technique which makes the OS can run more processes
concurrently than usual.
36