Memory management
Download
1 / 17

Memory Management - PowerPoint PPT Presentation


  • 97 Views
  • Uploaded on

Memory Management. How is the OS chose the location in the main memory to place an incoming process?. Process E 8 KB (computation heavy). Process D 8 KB (I/O heavy). Process H 2 KB. Process C 1 KB. Process G 2 KB. Process F 2 KB. Memory (18 KB). Process A 1 KB. Process B 1 KB.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Memory Management' - dayton


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Memory management
Memory Management

How is the OS chose the location in the main memory to place an incoming process?

Process E 8 KB

(computation heavy)

Process D 8 KB

(I/O heavy)

Process H 2 KB

Process C 1 KB

Process G 2 KB

Process F 2 KB

Memory (18 KB)

Process A 1 KB

Process B 1 KB


Adjacent placement
Adjacent Placement

  • First-fit: Choose the first block that is large enough to hold the new process.

  • Best-fit: Chose the block that leaves the smallest amount of space unused when the new process is placed.

  • Worst-fit: Chose the block that leaves the largest amount of space unused when the new process is placed.

6 KB

6 KB

6 KB

6 KB

12 KB

14 KB

14 KB

14 KB

14 KB

19 KB

19 KB

19 KB

19 KB

11 KB

11 KB

11 KB

11 KB

13 KB

13 KB

13 KB

13 KB


Example

P1

P2

P3

P4

P5

P6

P7

Arrival time

0

12

18

25

29

3

7

CPU time

5

3

9

10

16

2

8

Memory req.

3

5

8

12

2

6

9

Example

Memory Size: 35 units

Operating system: 10 units


Memory management

Garbage Collection

Over time as processes are placed and removed from the main memory, there would be a number of used and used areas in the main memory distributed in a random fashion

Unused areas by themselves may not be sufficiently big enough to place an incoming process

All used areas can be collected in one part of the main memory leaving one big chunk of unused area to place incoming processes

This process is referred to as garbage collection operation

6 KB

48 KB

48 KB

76 KB

14 KB

19 KB

76 KB

64 KB

19 KB

10 KB

64 KB

51 KB

11 KB

10 KB

13 KB


Memory management

Garbage Collection

Garbage collection operation requires CPU to read the instructions and data of each process and write them to another place in the main memory

During this time CPU can not execute user programs

Hence garbage collection is not effective process

It is not a preferred operation either but has to be executed from time to time


Memory management

Paging

Divide the main memory into fixed size blocks (e.g.,8 KB)

Divide each process into same sized blocks as well

Main memory

Sayfa 1

In this model, it is not required that all the pages of a process be in main memory

If the instruction to execute is not in the current page in the main memory a page fault is generated and the page is brought in to the main memory

8 KB

Sayfa 2

16 KB

Sayfa 3

24 KB

Sayfa 4

32 KB

Sayfa 5

40 KB

Sayfa 6

48 KB

Sayfa 7

Process

52 KB


Memory management

Paging

Small or Large Block Size

When a process is divided into fized size blocks (pages), the number of data in the last page can be smaller than the page size (i.e. A 51 KB process is divided into 8 KB blocks) and this unused area can NOT be used by another process (wasted)

As the block size increases the amount of wasted space in the main memory increases

As the page size decreases the number of page faults is expected to increase. Furthermore small page size would mean large number of entries to manage corresponding data structures (page tables, etc.)


Memory management

D-4

D-1

E-1

E-4

D-7

D-5

D-2

E-2

E-5

E-7

E-8

D-3

E-3

D-8

D-6

E-6

Process C 1024

Proses E

Process A 1024

Proses D

F-1

Process B 1024

F-2

Proses F

G-1

Proses G

G-2

H-1

Proses H

H-2


Memory management

First Last LLT

LLT for

A

LLT for

B

LLT for

C

LLT for

D

A

B

C

D

E

F

G

H

LLT for

E

LLT for

F

LLT for

G

LLT for

H

Process/Page

Table


Paging algorithms
Paging Algorithms

  • The objective is to minimize the page faults

  • Work fast and use minimal resources to execute

  • Optimum Algorithm

    • Replace the page that will not be used for the longest timeBUT we do not know this

    • Used to determine how well a proposed algoritm work

1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

1

1

4

Four pages can be

Hold in the main

Memory simultanously

2

2

2

3

3

3

4

5

5


First come first served
First Come First Served

1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

3 pages in the main memory

1

2

3

4

1

1

1

2

5

5

2

3

4

1

2

2

2

5

3

3

3

4

1

2

5

5

5

3

4

4

The number of page faults increases as the number of pages in the memory increases

Four pages in the main memory

2

3

4

1

2

1

5

1

1

2

3

4

5

2

3

2

2

1

3

3

3

4

5

1

3

4

2

4

4

4

5

1

2

3

4

5


Least recently used lru
Least Recently Used (LRU)

  • Her sayfa için bir sayaç kullanılır. Bir sayfaya referans geldiğinde sistem saati bu alana yazılır

  • Ana bellekten sayacı en küçük olan sayfayı çıkar

1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

4 pages in the main memory

4

4

1

2

5

1

4

2

3

1

2

5

2

3

2

1

3

4

3

2

5

1

3

4

1

2

4

2

4

1

5

1

2

3

4

5


Memory management

1, 2, 5, 4, 1, 3, 5, 4, 2, 1, 3, 5

1

1

5

1

5

5

3

3

3

3

2

5

4

5

4

4

5

5

5

5

5

4

3

4

3

3

2

1

1

1

1

1

2

5

4

3

5

4

2

1

2

3

5

4

1

5

4

2

1

3

5

5

4

1

3

4

2

1

3

5


Vald invalid bit
Vald/Invalid Bit

  • Use a valid/invalid bit for every page in the page table(1: in memory; 0: not in memory)

  • Inıtiazie all valid/invalid bits to 0

  • If the address of the instruction is in a page and the valid/invalid bit of that page is 0, generate an interrupt

  • When a page is written to the main memory, set the corresponding valid/invalid bit to 1

Valid/Invalid bit

Page no

1

Page no

0

Page no

0

Page no

1

0

Page no

Page Table


Page table page fault
Page Table/Page Fault

1

0

1

2

3

4

5

6

7

4

0

1

2

3

4

5

6

7

A

B

C

DEFG

H

  • A reference to an instruction in a new page causes an interrupt

  • OS looks at the table and makes a decision. If it is an illegal reference, ends thew process. Otherwise brings in the new page to the memory

  • Find an unused page in the main memory

  • Read the page from disk and write it to main memory Set the valid bit in the page table to 1

0

4

A

6

1

0

6

C

A

B

0

9

1

C

D

E

.

.

.

0

0

F

G

9

F

Virtual Memory

Page Table

H

Main memory


Page fault process
Page Fault Process

1

0

1

2

3

4

5

6

7

4

0

3. Page is

İn disk

A

B

1. Referans

6

1

2. Trap

Operating

system

Load page

H

0

C

D

E

0

6. Restartinstruction

9

1

F

G

0

0

Page Table

H

4

A

5. Update

Page table

6

C

4. Bring the page

To the main memory

.

.

.

9

F

Main memory


When there is no empty page in the main memory
When there is no empty page in the main memory?

  • Page replacement- find some page in memory but not really in use and swap it out

  • Note: Page replacement completes seperation between logical and physical memory.. Large virtual memory can be provided on a smaller physical memory

  • Find the location of the desired page on disk

  • Find a free frame

    • If there is a free frame, use it

    • If there is no free frame, use a page replacement algorithm to select a victim frame

  • Read the desired page into the (newly) free frame, update the page and frame tables

  • Restart the process