Memory Management Chapter 7.

Slides:



Advertisements
Similar presentations
Chapters 7 & 8 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,
Advertisements

Memory Management Chapter 7.
Fixed/Variable Partitioning
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable supply of ready processes to.
Allocating Memory.
Chapter 7 Memory Management
Chapter 7 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2009, Prentice.
OS Fall’02 Memory Management Operating Systems Fall 2002.
Chapter 7 Memory Management
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Memory Management Chapter 7 B.Ramamurthy. Memory Management Subdividing memory to accommodate multiple processes Memory needs to allocated efficiently.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Memory Management Chapter 5.
Memory Management Five Requirements for Memory Management to satisfy: –Relocation Users generally don’t know where they will be placed in main memory May.
Chapter 7 Memory Management
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
1 Memory Management Chapter 7. 2 Roadmap n Memory management u Objectives u Requirements n Simple memory management u Memory partitioning F Fixed partitioning.
Chapter 7 Memory Management Seventh Edition William Stallings Operating Systems: Internals and Design Principles.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Operating System 7 MEMORY MANAGEMENT. MEMORY MANAGEMENT REQUIREMENTS.
Memory Management Chapter 7.
Chapter 7 Memory Management Seventh Edition William Stallings Operating Systems: Internals and Design Principles.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
MEMORY MANAGEMENT Presented By:- Lect. Puneet Gupta G.P.C.G. Patiala.
Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Dr.
Chapter 7 Memory Management
Chapter 7 Memory Management Seventh Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management Chapter 7.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Subject: Operating System.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management Chapter 8. 2 Memory Management n It is the task carried out by the OS and hardware to accommodate multiple processes in main memory.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
Informationsteknologi Wednesday, October 3, 2007Computer Systems/Operating Systems - Class 121 Today’s class Memory management Virtual memory.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Memory management Ref: Stallings G.Anuradha. What is memory management? The task of subdivision of user portion of memory to accommodate multiple processes.
Memory Management Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only storage.
CSNB224 – AAG 2007 Memory Management Chapter 7. CSNB224 – AAG 2007 Memory Management In uniprogramming system, memory is divided into two parts: for the.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management Chapter 5 Advanced Operating System.
1 Memory Management n In most schemes, the kernel occupies some fixed portion of main memory and the rest is shared by multiple processes.
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
MEMORY MANAGEMENT. memory management  In a multiprogramming system, in order to share the processor, a number of processes must be kept in memory. 
COMP 3500 Introduction to Operating Systems Memory Management: Part 2 Dr. Xiao Qin Auburn University Slides.
Memory Management Chapter 7.
Chapter 7 Memory Management
Memory Management Chapter 7.
Memory Management.
ITEC 202 Operating Systems
Chapter 2 Memory and process management
Requirements, Partitioning, paging, and segmentation
Day 19 Memory Management.
Day 19 Memory Management.
Chapter 8 Main Memory.
Day 18 Memory Management.
Economics, Administration & Information system
Main Memory Background Swapping Contiguous Allocation Paging
Memory Management Chapter 7.
Memory Blocks in a Buddy System - Buddy Systems (2)
Operating System Chapter 7. Memory Management
Operating Systems: Internals and Design Principles, 6/E
Chapter 7 Memory Management
Presentation transcript:

Memory Management Chapter 7

Memory Management Subdividing memory to accommodate multiple processes Memory needs to allocated efficiently to pack as many processes into memory as possible

Memory Management Requirements (1) Relocation Protection Sharing Logical organization Physical organization

Memory Management Requirements (2) Relocation programmer does not know where the program will be placed in memory when it is executed while the program is executing, it may be swapped to disk and returned to main memory at a different location the processor hardware and operating system software must be able to translate the memory references found in the code of the program into actual physical memory address,reflecting the current location of the program in main memory

Memory Management Requirements (3) Protection processes should not be able to reference memory locations in another process without permission because the location of a program in main memory is unknown, it is impossible to check absolute addresses in programs since the program could be relocated all memory references generated by a process must be checked during execution to ensure that they refer only to the memory space allocated to that process.

Memory Management Requirements (4) Sharing any protection mechanism must have the flexibility to allow several processes to access the same portion of memory If a number of process are executing the same program, it is advantageous to allow each process (person) access to the same copy of the program rather than have their own separate copy

Memory Management Requirements (5) Logical Organization memory is organized as a linear address space. While this organization closely mirrors the actual machine hardware, it does not correspond t the way in which programs are typically constructed. most programs are written in modules different degrees of protection given to modules (read-only, execute-only) Segmentation is a tool to satisfies these requirement.

Memory Management Requirements (6) Physical Organization memory available for a program plus its data may be insufficient overlaying allows various modules to be assigned the same region of memory secondary memory cheaper, larger capacity, and permanent

Memory Partitioning Fixed Partitioning Dynamic Partitioning Simple Paging Simple Segmentation Virtual-Memory Paging Virtual-Memory Segmentation

Fixed Partitioning Partition available memory into regions with fixed boundaries Equal-size partitions any process whose size is less than or equal to the partition size can be loaded into an available partition if all partitions are full, the operating system can swap a process out of a partition a program may not fit in a partition. The programmer must design the program with overlays

Fixed Partitioning Main memory use is inefficient. Any program, no matter how small, occupies an entire partition. This is called internal fragmentation. Operating System 8 M 8 M 8 M 8 M 8 M

Fixed Partitioning Unequal-size partitions lessens the problem with equal-size partitions Operating System 8 M 2 M 4 M 6 M 8 M 8 M 12 M

Placement Algorithm with Partitions Equal-size partitions because all partitions are of equal size, it does not matter which partition is used Unequal-size partitions can assign each process to the smallest partition within which it will fit queue for each partition processes are assigned in such a way as to minimize wasted memory within a partition

One Process Queue per Partition Operating System New Processes

One Process Queue per Partition When its time to load a process into main memory the smallest available partition that will hold the process is selected Operating System New Processes

Dynamic Partitioning Partitions are of variable length and number Process is allocated exactly as much memory as required Eventually get holes in the memory. This is called external fragmentation Must use compaction to shift processes so they are contiguous and all free memory is in one block

Example Dynamic Partitioning Operating System Operating System Process 1 320 K 576 K Operating System Process 1 320 K Process 2 128 K 224 K 896 K 352 K

Example Dynamic Partitioning Operating System Operating System Operating System Process 1 320 K Process 3 288 K 64 K Process 4 128 K 96 K 320 K 320 K Process 1 Process 1 224 K 224 K Process 2 Process 3 288 K Process 3 288 K 64 K 64 K

Example Dynamic Partitioning Operating System Operating System 320 K Process 2 224 k 96 K 128 K 128 K Process 4 Process 4 96 K 96 K Process 3 288 K Process 3 288 K 64 K 64 K

Dynamic Partitioning Placement Algorithm Operating system must decide which free block to allocate to a process Best-fit algorithm chooses the block that is closest in size to the request worst performer overall since smallest block is found for process, the smallest amount of fragmentation is left memory compaction must be done more often

Dynamic Partitioning Placement Algorithm First-fit algorithm starts scanning memory from the beginning and chooses the first available block that is large enough. fastest may have many process loaded in the front end of memory that must be searched over when trying to find a free block

Dynamic Partitioning Placement Algorithm Next-fit starts scanning memory from the location of the last placement and chooses the next available block that is large enough more often allocate a block of memory at the end of memory where the largest block is found the largest block of memory is broken up into smaller blocks compaction is required to obtain a large block at the end of memory

Dynamic Partitioning Placement Algorithm 8K 8K 12K First Fit 12K 22K 6K Best Fit Last allocated block (14K) 18K 2K 8K 8K 6K 6K Allocated block 14K Free block 14K Next Fit 36K 20K Before After

Why Buddy System? - Buddy Systems (1) A fixed partitioning scheme limits the number of active processes and may use space inefficiently if there is a poor match between available partition size and process size A dynamic partitioning scheme is more complex to maintain and includes the overhead of compaction.

Memory Blocks in a Buddy System - Buddy Systems (2) In a buddy system, memory blocks are available of size 2k, L <= K <= U, where: 2L = smallest block that is allocated. 2U = largest size block that is allocated. Generally, 2U is the size of the entire memory available for allocation.

Allocation Method - Buddy Systems (3) To begin, the entire space available for allocation is treated as a single block of size 2U. If a request of size that 2 U-1 < s <= 2U is made, then the entire block is allocated. Otherwise, the block is split into two equal buddies of size 2 U-1. If 2 U-2 < s<= 2U-1, then the request is allocated to one of the two buddies. Otherwise, one of the buddies is split in half again. This process continues until the smallest block greater than or equal to s is generated and allocated to the request.

Remove Unallocated Blocks - Buddy Systems (4) At any time, the buddy system maintains a list of holes (unallocated blocks) of each size 2 i. A hole may be removed from the (i + 1) list by splitting it in half to create two buddies of size 2i in the i list. Whenever a pair of buddies on the i list both become unallocated, they are removed from that list and coalesced into a single block on the (i + 1) list.

Example of Buddy System - Buddy Systems (5) 1 Megabyte Block 1M Request 100K (A) A=128K 128K 256K 512K Request 240K (B) A=128K 128K B=256K 512K Request 256K (D) A=128K 128K B=256K D=256K 256K Release B A=128K 128K 256K D=256K 256K Release A 512K D=256K 256K Request 75K (E) E=128K 128K 256K D=256K 256K Release E 512K D=256K 256K Release D 1M

Tree Representation of Buddy System - Buddy Systems (6) 512K 256K 128K A=128K 128K B=256K D=256K 256K

Fibonacci Buddy System (1) The Fibonacci sequence is defined as follow: F0 = 0, F1 = 1, F n+2 = F n+1 + Fn (n>=0) 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, ….

Fibonacci Buddy System (2) Show the results of the following sequence in a figure using Fibonacci Buddy system: Request 60 (A); Request 135 (B); Request 70 (C); Return A; Request 20 (D); Return B; Return C; Return D.

Fibonacci Buddy System (3) 377 Byte Block 377(144+233) Request 60 (A) 55 A= 89 233 Request 135 (B) 55 A=89 89 B=144 Request 70 (C) 55 A=89 C=89 B=144 Return A 144 C=89 B=144 Request 60 (D) 55 D=89 C=89 B=144 Return B 55 D=89 C=89 144 Return D 144 C=89 144 Return C 377

Fibonacci Buddy System (4) 377 144 + 233 (55+89)+ (89+144) 128K 64K 55 D=89 C=89 144

Relocation When program loaded into memory the actual (absolute) memory locations are determined A process may occupy different partitions which means different absolute memory locations during execution (from swapping) Compaction will also cause a program to occupy a different partition which means different absolute memory locations

Addresses Logical Relative Physical reference to a memory location independent of the current assignment of data to memory translation must be made to the physical address Relative address expressed as a location relative to some known point, usually the beginning of the program Physical the absolute address or actual location

Hardware Support for Relocation Relative address Process Control Block Base Register Adder Program Absolute address Bounds Register Comparator Data Interrupt to operating system Stack Process image in main memory

Registers Used during Execution Base register starting address for the process Bounds register ending location of the process These values are set when the process is loaded and when the process is swapped in

Registers Used during Execution The value of the base register is added to a relative address to produce an absolute address The resulting address is compared with the value in the bounds register If the address is not within bounds, an interrupt is generated to the operating system

Paging Partition memory into small equal-size chunks and divide each process into the same size chunks The chunks of a process are called pages and chunks of memory are called frames Operating system maintains a page table for each process contains the frame location for each page in the process memory address consist of a page number and offset within the page

Paging (a) (b) (c) Frame Number 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 A.0 A.1 A.2 A.3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 A.0 A.1 A.2 A.3 B.0 B.1 B.2 (a) (b) (c)

Paging 1 2 3 4 5 6 7 8 9 10 11 12 13 14 A.0 A.1 A.2 A.3 B.0 B.1 B.2 C.0 C.1 C.2 C.3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 A.0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 A.0 A.1 A.1 A.2 A.2 A.3 A.3 D.0 D.1 D.2 C.0 C.0 C.1 C.1 C.2 C.2 C.3 C.3 D.3 D.4 (d) (e) (f)

Page Tables for Example --- 7 1 2 3 4 4 13 1 1 1 --- 1 8 5 14 2 2 2 --- 2 9 6 Free Frame List 3 3 3 10 11 Process B 12 Process C Process A Process D Data Structures for the Example at Time Epoch (f)

Logical Address of Paging Relative Address = 1502 Logical Address = User Process (2700 Bytes) Page# =1, Offset = 478 0000010111011110 0000010111011110 Page 0 1024 Page 1 478 Page 3 Internal Fragmentation (a) Partitioning (b) Paging (Page Size = 1K)

Segmentation All segments of all programs do not have to be of the same length There is a maximum segment length Addressing consist of two parts - a segment number and an offset Since segments are not equal, segmentation is similar to dynamic partitioning

Logical Address of Segmentation Relative Address = 1502 Logical Address = User Process (2700 Bytes) Segment# =1, Offset = 752 0000010111011110 0001001011110000 Segment 0 750 Bytes 752 Segment 1 1950 Bytes (a) Partitioning (b) Segmentation

Question 1 - Exercise/Home Work (1) A 1 Megabyte block of memory is allocated using buddy system. A. Show the results of the following sequence in a figure: Request 70K (A); Request 35K (B); Request 80K (C); Return A; Request 60K (D); Return B; Return C; Return D. B. Show the binary tree representation following Return B.

Question 2 - Exercise/Home Work (1) The Fibonacci sequence is defined as follow: F0 = 0, F1 = 1, F n+2 = F n+1 + Fn (n>=0) 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, …. A. Could this sequence be used to establish a buddy system? B. What would be the advantage of this system over the binary buddy system?

Question 2 - Exercise/Home Work (2) C. Show the results of the following sequence in a figure using Fibonacci buddy system: Request 70 (A); Request 35 (B); Request 80 (C); Return A; Request 60 (D); Return B; Return C; Return D. D. Show the binary tree representation following Return B.