CS 241 Spring 2007 System Programming 1 Introduction to Memory Management Lecture 28 Lawrence Angrave/Klara Nahrstedt.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
Memory Management Chapter 7.
CS 311 – Lecture 21 Outline Memory management in UNIX
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
CS 104 Introduction to Computer Science and Graphics Problems
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Memory ManagementCS-502 Fall Memory Management CS-502 Operating Systems Fall 2006 (Slides include materials from Operating System Concepts, 7 th.
Memory Management Chapter 5.
MEMORY MANAGEMENT By KUNAL KADAKIA RISHIT SHAH. Memory Memory is a large array of words or bytes, each with its own address. It is a repository of quickly.
Operating System Concepts
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 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,
Chapter 4 Storage Management (Memory Management).
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Chapter 10 Memory Management Introduction Process must be loaded into memory before being executed. Input queue – collection of processes on the.
CE Operating Systems Lecture 14 Memory management.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Memory Management Operating Systems CS550. Memory Manager Memory manager - manages allocation and de-allocation of main memory Plays significant impact.
Memory Management. Introduction To improve both the utilization of the CPU and the speed of its response to users, the computer must keep several processes.
1 Memory Management. 2 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k Internal fragmentation (cannot be reallocated) Divide memory into n (possible.
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.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
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 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.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Memory.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Memory Management 1. Outline Background Logical versus Physical Address Space Swapping Contiguous Allocation Paging Segmentation 2.
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.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Memory.
SLC/VER1.0/OS CONCEPTS/OCT'99
Chapter 2 Memory and process management
Chapter 8: Main Memory.
Chapter 9 – Real Memory Organization and Management
Chapter 8 Main Memory.
Main Memory Management
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Operating System Concepts
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Multistep Processing of a User Program
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Memory Management-I 1.
Main Memory Background Swapping Contiguous Allocation Paging
CS399 New Beginnings Jonathan Walpole.
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Lecture 3: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Presentation transcript:

CS 241 Spring 2007 System Programming 1 Introduction to Memory Management Lecture 28 Lawrence Angrave/Klara Nahrstedt

2 CS241 Administrative  Read Stallings Chapter 7 & 7A about Memory Management  Regular Quiz 9 this week on Memory Management  Discussion Sessions this week (on Memory Management – needed for LMP2)  LMP2 (Long Machine Problem) starts today  LMP 2 is part of three major assignments (LMP1, LMP2, LMP3)  LMP2 will be split into two parts, PART I and overall LMP2 delivery.  You will need to deliver PART I by Monday, April 9 and the final overall LMP2 will be due by April 16. For each delivery you will receive points.  LMP2 quiz will be on April 16.  The graders will provide feedback on the Part I that should assist you in the overall LMP2 delivery.

3 Contents Addressing Requirements for a Process Names and Binding, Loading, Compiling, Run- Time Storage hierarchy Simple Programming Overlays Resident monitor Multi-Programming Fixed Partitioning Relocation Register Swapping

4 Names and Binding Naming = very deep theme that comes up everywhere Indirection Symbolic names Logical names Physical names Most used by application programmers Converted by system programmers of compilers, OS

5 Symbolic Names Symbolic names: known in a context or path File names Program names Printer/device names User names Variables Convenient to use/reference

6 Logical Names Logical names: label a specific entity … but independent of specific physical entity Inode number Job number Major, minor device numbers uid, pid, gid Absolute address in program

7 Physical Names Physical names: address of entity Physical Inode address on disk or memory (track, cylinder, …) Entry point or variable address Memory-mapped register addresses Process control block address Difficult to use by programmers Therefore, system software (compilers, loaders, OS) are usually the ones that convert symbolic names/logic names to physical names

8 Binding Time of Names Binding: map names to locations (values) Late binding … Early binding Different times Source program (.c file) Compile time Object module (.o file) Link time Load module Load time Run-time

9 Binding at Compile & Link time Create object code gcc -c part1.c gcc -c part2.c gcc -o wowee part1.o part2.o gcc uses linker program 'ld' to link object code together.

10 What does a process look like? (Unix) Process address space divided into “segments” text (code), data, heap (dynamic data), and stack heap stack code initialized data address 2^n-1 address >= 0

11 Who Binds What? Heap: constructed and layout by allocator (malloc) compiler, linker not involved other than saying where it can start namespace constructed dynamically and managed by programmer (names stored in pointers, and organized using data structures) Stack: alloc dynamic (proc call), layout by compiler names are relative off of stack pointer managed by compiler (alloc on proc entry, dealloc on exit) linker not involved because name space entirely local: compiler has enough information to build it. Global data & code: allocation static (compiler), layout (linker) compiler emits them and can form symbolic references between them (“jalr _printf”) linker lays them out, and translates references

12 Compiling Compiler: –doesn ’ t know where data/code should be placed in the process ’ s address space –assumes everything starts at zero –emits symbol table that holds the name and offset of each created object global definition –routine/variables exported by the file are recorded global definition Simpler perspective: –code is in a big char array –data is in another big char array –compiler creates (object name, index) tuple for each interesting thing –linker then merges all of these arrays 40 foo: call printf ret bar: … ret 0 foo: 0 bar: 40

13 Linkers (Linkage editors) Unix: ld usually hidden behind compiler Three functions: collect together all pieces of a program coalesce like segments fix addresses of code and data so the program can run Result: runnable program stored in new object file Why can’t compiler do this? Limited world view: one file, rather than all files Note *usually*:linkers only shuffle segments, but do not rearrange their internals. E.g., instructions not reordered; routines that are never called are not removed from a.out

14 Loading before Running On Unix systems, read by “loader” reads all code/data segs into buffer cache; maps code (read only) and initialized data (r/w) into addr space Optimization opportunities: Zero-initialized data does not need to be read in. Demand load: wait until code used before get from disk Copies of same program running? Share code Multiple programs use same routines: share code (harder) ld loader Cache Compile timeruntime

15 Run-time Maps virtual addresses to physical addresses VM, overlaying, recursion, relocation

16 Binding Time Trade-offs(1) Early binding Compiler + Produces efficient code + Allows checking to be done early + Allows estimates of running time and space - inflexible - require fixed hardware - difficult to support multiprogramming

17 Binding Time Trade-offs(2) Delayed binding Linker, loader + Produces efficient code + Allows separate compilation + Provides libraries, system interfaces + Portability and sharing of object code + Checking of consistency - inflexible - medium difficult to support multiprogramming

18 Binding Time Trade-offs (3) Late binding VM, dynamic linking and loading, overlaying, interpreting - Code less efficient - Checks must be done at run time + Flexible + Provides abstraction of hardware + Allows dynamic reconfiguration

19 Storage Hierarchy Cost $400 a chip $10 -4 per byte $10 -8 per byte $10 -9 per byte Size 2 13 bytes 2 27 bytes 2 30 bytes 2 40 bytes CPU Reg Cache Memory Secondary Storage bits words k words

20 Single Programming Overlay Manager Overlay Area Main Program Overlay 1 Overlay 2 Overlay 3 Secondary Storage Overlay 1Overlay 2Overlay 3Overlay 1 0K 5k 7k 12k

21 User Resident Monitor Free 8k 32k User Monitor User 0K

22 Multiprogramming How to keep multiple programs in memory?

23 Multiprogramming with Fixed Partitions Divide memory into n (possible unequal) partitions. Problem: Fragmentation Free Space 0k 4k 16k 64k 128k

24 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k Internal fragmentation (cannot be reallocated)

25 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k

26 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k

27 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k

28 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k

29 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k

30 Fixed Partition Allocation Implementation Issues Separate input queue for each partition Requires sorting the incoming jobs and putting them into separate queues Inefficient utilization of memory when the queue for a large partition is empty but the queue for a small partition is full. Small jobs have to wait to get into memory even though plenty of memory is free. One single input queue for all partitions. Allocate a partition where the job fits in. Best Fit Available Fit

31 Relocation Correct starting address when a program should start in the memory Different jobs will run at different addresses When a program is linked, the linker must know at what address the program will begin in memory. Logical addresses, Virtual addresses Logical address space, range (0 to max) Physical addresses, Physical address space range (R+0 to R+max) for base value R. User program never sees the real physical addresses Memory-management unit (MMU) map virtual to physical addresses. Relocation register Mapping requires hardware (MMU) with the base register

32 Relocation Register Memory Base Register CPU Instruction Address + BA MA MA+BA Physical Address Logical Address

33 Question 1 - Protection Problem: How to prevent a malicious process to write or jump into other user's or OS partitions Solution: Base bounds registers

34 Base Bounds Registers Memory Bounds RegisterBase Register CPU Address <+ Memory Address MA Logical Address LA Physical Address PA Fault Base Address Limit Address MA+BA Base Address BA

35 Question 2 What if there are more processes than what could fit into the memory?

36 Swapping Monitor Disk User Partition

37 Swapping Monitor Disk User 1 User Partition

38 Swapping Monitor User 1 Disk User 1 User Partition

39 Swapping Monitor User 2 User 1 Disk User 1 User Partition

40 Swapping Monitor Disk User 2 User Partition User 1

41 Swapping Monitor Disk User 2 User Partition User 1

42 Swapping Monitor Disk User 1 User 2 User Partition User 1

43 Summary Concept of Names/Addresses during Compile Link Load Running Simple Programming Overlays Relocation Register Multi-Programming Fixed Partitions Swapping