Memory Management Chapter 5 Advanced Operating System.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Memory Management Chapter 7.
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.
CS 104 Introduction to Computer Science and Graphics Problems
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 2010.
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.
Virtual Memory I Chapter 8.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Chapter 7 Memory Management
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
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.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Operating System 7 MEMORY MANAGEMENT. MEMORY MANAGEMENT REQUIREMENTS.
Memory Management Chapter 7.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
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.
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
Memory Management – Page 1 of 49CSCI 4717 – Computer Architecture Memory Management Uni-program – memory split into two parts –One for Operating System.
Memory Management Chapter 7.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Subject: Operating System.
CE Operating Systems Lecture 14 Memory management.
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.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
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.
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.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
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.
ITEC 202 Operating Systems
Chapter 2 Memory and process management
Main Memory Management
Economics, Administration & Information system
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Main Memory Background Swapping Contiguous Allocation Paging
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
COMP755 Advanced Operating Systems
Operating Systems: Internals and Design Principles, 6/E
Chapter 7 Memory Management
Presentation transcript:

Memory Management Chapter 5 Advanced Operating System

Memory Management Subdivide memory to accommodate multiple processes Allocate memory efficiently – pack as many processes into memory as possible if a>10 then a := a + 1; a b := a + 1; b a RAM / memory

Memory Management Requirements Relocation Protection Sharing Local organization Physical organization

Memory Management Requirements Relocation when a program is compiled, the address of the code and data are fixed the memory range a process occupies may change in run time, e.g. due to swapping. The program may no longer work afterward a = 0; a mov [100],0 100 The process image moves after swapping mov [100],0 200 RAM

Memory Management Requirements Protection other processes cannot reference memory of a process without permission cannot be checked in compile time. must be checked during execution

Memory Management Requirements Sharing allow several processes to access the same portion of memory, e.g., several processes running the same program several processes sharing a common library shared memory for data transfer between processes

Memory Management Requirements Logical Organization programs are written in modules different degrees of protection given to modules (read-only, execute-only) share modules (e.g. DLL)

Memory Management Requirements Physical Organization memory available may be insufficient secondary memory cheaper, larger capacity, and permanent how to use secondary memory to ‘simulate’ primary memory? Overlay virtual memory (discussed in Chap 8) memory-mapped file

Fixed Partitioning Partition available memory into regions with fixed boundary (e.g. at system boot up) Each process is allocated ONE partition 8M Equal-size 8M 4M 8M 12M Unequal-size RAM

Internal Fragmentation OS 8M Process A (8M) Process B (5M) When a 5M process is allocated an 8M partition, 3M of memory is wasted (cannot be used by other processes). This is called internal fragmentation. 8M Process C (10M) We cannot run a process that needs 10M, even if we have enough free memory.

Dynamic Partitioning Partitions are of variable length and number Process is allocated exactly as much memory as required No internal fragmentation, but there is still external fragmentation Must use compaction to shift processes so that all free memory is in one block

External Fragmentation OS 6M A 3M  B 6M  C 12M  OS 6M A 3M 5M free 6M free  C 12M OS 6M A 3M C 12M D 3M  E 3M  F 5M  Holes appear as processes are created and terminated. This is called external fragmentation. In this example, we have totally 5M free memory. But there is no contiguous region large enough for the new process. We need to perform compaction. OS 6M A 3M 5M free  C 12M D 3M E 3M Compaction RAM

Placement Algorithm 6M 8M 2M 7M 5M  Where should I load this process? Last allocated block Best-fit. Leave a small hole First-fit. Use the first block that is large enough Next-fit. Use the first large enough block after the last placement

Placement Algorithm Best-fit algorithm chooses the block that is closest in size to the request worst performer overall small blocks are left all around. Compaction must be done more often

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

Placement Algorithm Next-fit algorithm starts scanning memory from the location of the last placement and chooses the next available block that is large enough

Key concepts in Paging Physical memory (RAM), Frame, Physical address Addressing space of each process, Page, Logical address Page table Address translation

Paging in Pentium We will use Pentium as an example in the following explanation Pentium uses 32 bit address and address bus The size of a page and frame is 4k (4096) bytes

Physical memory / RAM RAM Each byte in the RAM is identified by a 32 bit physical address We can plug in at most 2^32=4G bytes of RAM. The CPU cannot address RAM above 4G. The address range is 0x – 0xFFFFFFFF 1 byte each 0x x x

Frame Frame number in hexadecimal RAM E.g. frame contains the bytes of address 0x – 0x00000FFF. Frame contains the addresses 0x – 0x00009FFF. The physical memory (RAM) is divided into chunks of equal size (4096 in Pentium). They are called frames bytes in each frame

Addressing space of process A Addressing space of process B Each process has its own ‘memory’ called addressing space. It is an illusion created by the hardware and the OS. Some bytes may be in RAM, some may be in hard disk (virtual memory), and some may not exist yet. Each byte of the addressing space is located by a 32-bit logical address. So each process can access at most 2^32 = 4G bytes. The addressing spaces of process A and B are separate! E.g. this byte is not the same as that byte, although A and B access the bytes using the same address.

Page The addressing space of each process is divided into chunks of equal size. (Same size as the frame size). They are called pages. A A A B B C C C C Addressing space of process A For example, the byte is the first byte in the page Page number in hexadecimal Addressing space of process C Addressing space of process B

Pages and Frames A A A C B C B C A A A C C C CB B The pages in the addressing space of each process are mapped to the frames in the physical memory. Note that contiguous pages may be mapped to separate frames. The pages in the addressing space of each process are mapped to the frames in the physical memory. Note that contiguous pages may be mapped to separate frames. RAM Addressing space of process A Some pages might not be in RAM at the moment. More about this in chap 8. ? Addressing space of process C Addressing space of process B

Page Table A A A C B C B C C A A A Page table of process A The OS maintains a data structure called page table to store the mapping between the pages and frames ? Page table of process B Page table of process C RAM Addressing space of process A

Address Translation, 1 C C C C Addressing space of process C void greet ( ) { printf(“Hello!”); } Every process has its own addressing space. A process sees that all data and program it needs (i.e. its process image) are somewhere in its addressing space.

Address Translation, A A A C B C B C C C C C RAM Addressing space of process C Page table of process C C But actually, these are stored in the physical memory (or hard disk). This mapping is maintained by the OS using page table.

Address Translation, 3 Addressing space of process C Logical address MOV [ ], AX Instruction register CPU Suppose process C wants to write a global variable at address (a logical address in the addressing space of process C)

Address Translation, RAM physical address MOV [ ], AX Instruction register CPU addr: data: xxx The bus and the RAM only “know” physical address. They do not know process and addressing space

Address Translation, RAM Addressing space of process C Logical address ?? physical address MOV [ ], AX Instruction register CPU When the CPU read/write data at any logical address, e.g. MOV [ ], AX it has to find the data in the RAM, which only knows physical address. When the CPU read/write data at any logical address, e.g. MOV [ ], AX it has to find the data in the RAM, which only knows physical address.

Address Translation, Page table of process C page number offset frame number offset Physical addressLogical address CPU uses the page table of process C to translate the logical address to physical address frame page

Address Translation, bit page number 12 bit offset bit frame number 12 bit offset Logical address is the address as seen by a process. The process does not know where in the RAM the byte actually resides in. Physical address is the address actually used by the CPU to read the physical memory (RAM). It is the actual address of the byte in RAM Page table of process C

Address Translation, RAM Addressing space of process C Logical address physical address MOV [ ], AX Instruction register CPU addr: data: xxx The CPU then submits the physical address to the bus to read/write the data

Address Translation, 9 void greet ( ) { printf(“Hello!”); } frame 00009page void greet ( ) { printf(“Hello!”); } Before executing any instruction in the process, the CPU fetches that instruction. E.g. when the process C calls the function greet ( ), the CPU fetches the instruction at the logical address MOV “instruction register”, “instruction at ” The CPU again needs to translate the logical address to physical address before fetching the instruction through the bus. Before executing any instruction in the process, the CPU fetches that instruction. E.g. when the process C calls the function greet ( ), the CPU fetches the instruction at the logical address MOV “instruction register”, “instruction at ” The CPU again needs to translate the logical address to physical address before fetching the instruction through the bus.

Address Translation All addresses seen by a process is logical address. To read some data or code from RAM, the CPU has to submit the physical address (the real one) onto the bus. The CPU uses the page table of the running process to translate every address used at runtime.

Address Translation … is done every time the CPU needs to access data/code in RAM when the CPU fetches an instruction when the CPU executes an instruction that access data in RAM (not present in cache)

Segments Program Data Stack The addressing space of a process is divided into parts of unequal length called segments. Each segment usually holds ‘data’ of a certain type, e.g. program code, global data, and stack. Each segment is identified by a number. Addressing space of a process 40k 50k 20k Segment 0 Segment 1 Segment 2 Segments in Pentium is implemented with segment registers (CS, DS, SS, etc) and implicit or explicit association with address register. In concepts, this is similar to what we study here.

Segment Table Program Data Stack Program Data Stack Addressing space of a process RAM Segment table k 50k 20k MP baselength The segments are mapped to the RAM through a segment table. It marks the base address and length of the segment. Starting address of the segment

Address Translation segment # offset 0123ABCD + Segment table pointer Virtual addressPhysical address The base address and the length of the segment are first looked up in the segment table. Physical address = base address + offset. The CPU also checks that the offset is within the length of the segment. Segment table k 50k 20k baselength

Segmentation Simplifies handling of growing data structures Allows programs to be altered and recompiled independently Used for sharing data among processes Lends itself to protection

Combined Paging and Segmentation Paging is transparent to the programmer Paging eliminates external fragmentation Segmentation is visible to the programmer Segmentation allows for growing data structures, modularity, and support for sharing and protection Each segment is broken into fixed-size pages

Segment #Page #offset Virtual address Address Translation The process has a page table for each segment The CPU uses the segment # to get a page table The CPU generates the physical address using the page #, offset and the page table