Memory Management Policies: UNIX

Slides:



Advertisements
Similar presentations
Chapter 4 Memory Management Basic memory management Swapping
Advertisements

Chapter 3 Memory Management
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
Virtual Memory Management G. Anuradha Ref:- Galvin.
Case Study: Virtual Memory in UNIX Reference – Maurice J.Bach, The Design of the UNIX Operating System Terminology - Physical Memory (Main Memory) Secondary.
Virtual Memory Operating System Concepts chapter 9 CS 355
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory OSC: Chapter 9. Demand Paging Copy-on-Write Page Replacement.
Memory Management Design & Implementation Segmentation Chapter 4.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Structure of Processes
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Introduction to Kernel
Virtual Memory Chapter 8.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001.
Computer Organization and Architecture
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Virtual Memory Management B.Ramamurthy. Paging (2) The relation between virtual addresses and physical memory addres- ses given by page table.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
1 Memory Management in Representative Operating Systems.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Operating Systems Chapter 8
MEMORY MANAGEMENT Presented By:- Lect. Puneet Gupta G.P.C.G. Patiala.
Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Virtual Memory 1 Chapter 13. Virtual Memory Introduction Demand Paging Hardware Requirements 4.3 BSD Virtual Memory 4.3 BSD Memory Management Operations.
Unit - III Memory management and Virtual memory. Contents : Swapping Demand paging Hybrid System with swapping and demand paging Memory management requirements.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
CS 241 Section Week #9 (11/05/09). Topics MP6 Overview Memory Management Virtual Memory Page Tables.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 9: Virtual-Memory Management.
Lecture Topics: 11/24 Sharing Pages Demand Paging (and alternative) Page Replacement –optimal algorithm –implementable algorithms.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical memory.
LINUX 15 : Memory Management
1 Structure of Processes Chapter 6 Process State and Transition Data Structure for Process Layout of System Memory THE DESIGN OF THE UNIX OPERATING SYSTEM.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 4.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Virtual Memory.
Memory Management Chapter 7.
Introduction to Kernel
Computer Organization
Chapter 2: The Linux System Part 4
OPERATING SYSTEM CONCEPTS AND PRACTISE
Virtual Memory CSSE 332 Operating Systems
Virtual Memory Chapter 7.4.
Chapter 9: Virtual Memory – Part I
Chapter 9: Virtual Memory
Structure of Processes
CSC 322 Operating Systems Concepts Lecture - 16: by
Virtual Memory Chapter 8.
Review.
Structure of Processes
Chapter 9: Virtual-Memory Management
Operating Systems Lecture November 2018.
Main Memory Background Swapping Contiguous Allocation Paging
Chapter 9: Virtual Memory
Contents Memory types & memory hierarchy Virtual memory (VM)
Memory Management and I/O Subsystem
Structure of Processes
CSE 542: Operating Systems
Presentation transcript:

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

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 Text Stack Data File Descriptor Table Per Process Region Table Kernel Process Table Kernel Region Table A Process U Area

Data Structure for Process (contd.) per process region table Kernel region table u area main memory Kernel process table

UNIX Memory Management Policies Swapping Easy to implement Less system overhead Demand Paging Greater flexibility

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 1 10000 101 9900 151 9750 251 9850 Map Address 1 10000 101 9900 151 9750 251 9850 Allocate 100 unit Allocate 50 unit Map Address Unit

Freeing Swap Space Address Unit 101 50 251 9750 251 9750 Map 101 50 251 9750 50 unit free at 101 251 9750 Map Case 1: Free resources fill a hole, but not contiguous to any resources in the map

Freeing Swap Space Address Unit 101 50 251 9750 251 9750 Map 1 150 101 50 251 9750 50 unit free at 101 251 9750 Map 100 unit free at 1 1 150 251 9750 Case 2: Free resources fill a hole, and immediately precedes an entry in the map

Freeing Swap Space Address Unit 101 50 251 9750 251 9750 Map 1 150 101 50 251 9750 50 unit free at 101 251 9750 Map 100 unit free at 1 1 150 451 9550 1 150 251 9750 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 1 10000

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 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 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 Out Mapping process onto the swap device Text Data : 128k 401k 66k 595k 65k 573k 1k 432k 0 278k Virtual Addresses Swap device 684 690 Text Data Stack Physical Addresses Mapping process onto the swap device

Swapping Process In Swapping a process into memory Text Data Stack 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 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 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 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 Page table entry Disk block descriptors Page frame data table Swap use table

Page Table Entry and Disk Block Descriptor Region Page Table Page Table Entry Disk Block Descriptor Page Table Entry Page address age Cp/wrt mod ref val prot Disk Block Descriptor Type Block num Swap device

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 Swap Device number as there may be several swap devices Block number that contains page Type Block num Swap device