memory management policies unix l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Memory Management Policies: UNIX PowerPoint Presentation
Download Presentation
Memory Management Policies: UNIX

Loading in 2 Seconds...

play fullscreen
1 / 22

Memory Management Policies: UNIX - PowerPoint PPT Presentation


  • 890 Views
  • Uploaded on

Memory Management Policies: UNIX. Topics. Allocating swap space Freeing swap space Swapping Demand paging. Chapter 9. THE DESIGN OF THE UNIX OPERATING SYSTEM Maurice J. bach Prentice Hall. Memory.

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 Policies: UNIX' - jerrod


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 policies unix

Memory Management Policies: UNIX

Topics

Allocating swap space

Freeing swap space

Swapping

Demand paging

Chapter 9

THE DESIGN OF THE UNIX OPERATING SYSTEM

Maurice J. bach Prentice Hall

memory
Memory
  • Primary memory is a precious resource that frequently cannot contain all active processes in the system
  • The memory management system decides which processes should reside (at least partially) in main memory
  • It monitors the amount of available primary memory and may periodically write processes to a secondary device called the swap device to provide more space in primary memory
  • At a later time, the kernel reads the data from swap device back to main memory
data structures for process
Data Structures for Process

Kernel Region Table

Kernel Process Table

A Process

Per Process Region Table

Text

File Descriptor Table

Data

Stack

U Area

data structure for process contd
Data Structure for Process (contd.)

per process

region table

Kernel region table

u area

main memory

Kernel

process table

unix memory management policies
UNIX Memory Management Policies
  • Swapping
    • Easy to implement
    • Less system overhead
  • Demand Paging
    • Greater flexibility
swapping
Swapping
  • The swap device is a block device in a configurable section of a disk
  • Kernel allocates contiguous space on the swap device without fragmentation
  • It maintains free space of the swap device in an in-core table, called map
  • The kernel treats each unit of the swap map as group of disk blocks
  • As kernel allocates and frees resources, it updates the map accordingly
allocating swap space
Allocating Swap Space

Address

Unit

Allocate 100 unit

110000

1019900

Map

Allocate 50 unit

Allocate 100 unit

2519850

1519750

freeing swap space
Freeing Swap Space

101 50

2519750

Address

Unit

50 unit free at 101

2519750

Map

Case 1: Free resources fill a hole,

but not contiguous to any resources in the map

freeing swap space9
Freeing Swap Space

101 50

1 150

2519750

2519750

Address

Unit

50 unit free at 101

2519750

Map

100 unit free at 1

Case 2: Free resources fill a hole,

and immediately precedes an entry in the map

freeing swap space10
Freeing Swap Space

1 150

1 150

101 50

4519550

2519750

2519750

Address

Unit

50 unit free at 101

2519750

Map

100 unit free at 1

Allocate 200 unit

300 unit free at 151

Case 3: Free resources fill a hole, and completely fills the gap between entries in the map

110000

algorithm allocate swap space
Algorithm: Allocate Swap Space
  • malloc( address_of_map, number_of_unit)
    • for (every map entry)
      • if (current map entry can fit requested units)
        • if (requested units == number of units in entry)
          • Delete entry from map
        • else
          • Adjust start address of entry
        • return original address of entry
    • return -1
swapping process out
Swapping Process Out
  • Memory  Swap device
  • Kernel swap out when it needs memory
      • When fork() called for allocate child process
      • When called for increase the size of process
      • When process become larger by growth of its stack
      • Previously swapped out process want to swap in but not enough memory
swapping process out13
Swapping Process Out
  • The kernel must gather the page addresses of data at primary memory to be swapped out
  • Kernel copies the physical memory assigned to a process to the allocated space on the swap device
  • The mapping between physical memory and swap device is kept in page table entry
swapping process out14
Swapping Process Out

Virtual Addresses

Physical Addresses

Swap device

684

Text

0 278k

1k 432k

:

Data

65k 573k

66k 595k

690

:

Stack

128k 401k

:

Mapping process onto the swap device

swapping process in
Swapping Process In

Virtual Addresses

Physical Addresses

Swap device

684

Text

0 278k

1k 432k

:

Data

65k 573k

66k 595k

690

:

Stack

128k 401k

:

Swapping a process into memory

fork swap
Fork Swap
  • There may not be enough memory when fork() called
  • Child process swap out and “ready-to-run”
  • Swap in when kernel schedule it
expansion swap
Expansion Swap
  • It reserves enough space on the swap device to contain the memory space of the process, including the newly requested space
  • Then it adjust the address translation mapping of the process
  • Finally, it swaps the process out on newly allocated space in swapping device
  • When the process swaps the process into memory, it will allocate physical memory according to new address translation map
demand paging
Demand Paging
  • Not all page of process resides in memory
  • Locality
  • When a process accesses a page that is not part of its working set, it incurs a page fault.
  • The kernel suspends the execution of the process until it reads the page into memory and makes it accessible to the process
data structure for demand paging
Data Structure for Demand Paging
  • Page table entry
  • Disk block descriptors
  • Page frame data table
  • Swap use table
page table entry and disk block descriptor
Page Table Entry and Disk Block Descriptor

Swap device

Block num

Type

Page Table

Region

Page Table Entry

Disk Block Descriptor

Page Table Entry

Disk Block Descriptor

page table entry
Page Table Entry
  • Contains the physical address of page and the following bits:
    • Valid: whether the page content legal
    • Reference: whether the page is referenced recently
    • Modify:whether the page content is modified
    • copy on write: kernel must create a new copy when a process modifies its content (required for fork)
    • Age: Age of the page
    • Protection: Read/ write permission
disk block descriptor
Disk Block Descriptor

Swap device

Block num

Type

  • Swap Device number as there may be several swap devices
  • Block number that contains page