© Janice Regan, CMPT 300, May 2007 0 CMPT 300 Introduction to Operating Systems Memory: Relocation.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Chapter 3 Loaders and Linkers
Mr. D. J. Patel, AITS, Rajkot 1 Operating Systems, by Dhananjay Dhamdhere1 Static and Dynamic Memory Allocation Memory allocation is an aspect of a more.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Memory Management Chapter 7.
CS 104 Introduction to Computer Science and Graphics Problems
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 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
An introduction to systems programming
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Memory Management Chapter 5.
Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Memory Management Chapter 5.
Lecture 9: SHELL PROGRAMMING (continued) Creating shell scripts!
1 Memory Management Memory Management Requirements –Relocation A programmer does not know in advance which other programs will be resident in main memory.
A. Frank - P. Weisberg Operating Systems Real Memory Management.
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.
Software Development and Software Loading in Embedded Systems.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Memory Management Chapter 7.
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,
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
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.
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.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
Chapter 4 Memory Management Virtual Memory.
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 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 Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Mono an multiprogramming.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 31 Memory Management.
LINKERS Execution of a program written in a language L involves the following steps: 1.Translation of the program: Performed by the translator for language.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Overview: Using Hardware.
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Memory management The main purpose of a computer system is to execute programs. These programs, together with the data they access, must be in main memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Memory Management Chapter 7.
SLC/VER1.0/OS CONCEPTS/OCT'99
Memory Management.
Chapter 2 Memory and process management
Memory management.
Real Memory Management
System Programming and administration
Linking & Loading.
Chapter 8 Main Memory.
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
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.
Module IV Memory Organization.
Main Memory Background Swapping Contiguous Allocation Paging
Memory Management Tasks
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.
An introduction to systems programming
COMP755 Advanced Operating Systems
Presentation transcript:

© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation

© Janice Regan, CMPT 300, May Shared files  A file may be shared by more than one directory (or user)  Two approaches to sharing  Hard link Once linked file is always available Entry for file added to directory file to link  Symbolic link A file containing the pathname to the file to be linked Treated like any other file in the directory If file linked to is deleted, link can no longer access the file

© Janice Regan, CMPT 300, May File types: Unix  Now have discussed  Regular files (used for user information) Binary Ascii Contain data, user code, compiled code, executables  Directory files  Symbolic links  Also have  special files: contain no data, provide a way to map devices to file names

© Janice Regan, CMPT 300, May Using regular files  When developing an application a user will use a computer language  Compile, link, execute  The compiler will save a file to the disk that has a special type, such a file is called an object module.  An object module includes machine executable instructions  Executable file is loaded (by the loader) to put it in memory when it is made into a process C codecompilerAssembler codeassembler Machine language Object file linker Machine language Executable file

© Janice Regan, CMPT 300, May Machine instructions  Remember that machine instructions, like those in the executable include the addresses of variables stored in the memory image and other instructions stored in the command portion of the memory image  When we load the executable into memory to run it those addresses must remain valid.  Simplest solution is to always load the executable at the same location (absolute loading)  Not practical with multiprocessing  Need to use offsets to accomplish relocatable loading

© Janice Regan, CMPT 300, May Absolute loading  Addresses used in machine code all assume that the executable will be loaded at location x in the memory  All machine instructions that use absolute addresses are assigned those addresses  at compile/assembly time by the compiler or assembler OR  During program development by the programmer Problem: must know in advance where the executable will be placed Reasonable only when programming a special process CPU for a particular purpose (for example an embedded CPU for controlling and operating an electronic device)

© Janice Regan, CMPT 300, May Absolute loading: Limitations  Useful only  Without multiprocessing (one program at a time)  Or with a small number of fixed partitions, must specifiy at compile time which partition is to be used  Even then  Memory space is wasted when process does not fill partition  Processes, once compiled can run in only one partition (constrained by addressing) OS Location x Location 0 Program Starts at location x x: beginning of first fixed partition Program Starts at location y y: beginning of second fixed partition Location y

© Janice Regan, CMPT 300, May Fixed partitions, varying sizes Operating system P1 P2 P3 p4

© Janice Regan, CMPT 300, May Multiprocessing: fixed partitions  Partitions of equal size  Any program whose image size is <= to the partition size can be loaded into any available partition  Internal fragmentation will occur since not all processes will fill their partitions  Some processes may be too larger for the partition size: requires overlays, programmer breaks program into units that can fit in one partition and alternates them in his partition Operating system P1 P2 P3 P4 p5

© Janice Regan, CMPT 300, May Fixed partitions varying size: 1 FIFO Operating system P1 P2 P3 p4

© Janice Regan, CMPT 300, May Absolute loading: other difficulties  When using libraries or other previously compiled routines must  Separately compile and link every combination of routines so that the object contains all the routines and their relative addresses in the compiled and linked code  Or must know the sizes of each routine to be combined, be sure no labels are used in multiple routines and have a complicated support method to assure that addressing is done correctly in the assembled code

© Janice Regan, CMPT 300, May Relocatable loading: contiguous process image  All processes are compiled/assembled with the assumption that they will be loaded at location 0 in memory  When a process runs then  determine where in memory its image will fit  Finds the address where the first bit of the object file will be placed (address x)  Adds x to every address referred to in the compiled/assembled code.  The relocation can be done at different times

© Janice Regan, CMPT 300, May Relocation  At compile time  Must know offset at compile time  Must recompile if offset changes  Not generally practical

© Janice Regan, CMPT 300, May Static Relocation  At load time: Static relocation  At compile time append a relocation table to the end of the executable  The relocation table contains a list of all addresses that need to be relocated (all absolute addresses)  At load time determine were the executable will be loaded into memory and add the appropriate offset to each variable or other absolute address (e.g. branch destination) in the relocation table  Relocation calculation done at load time  Cannot move the process to another location during execution.  External references (to other modules) are resolved at load time

© Janice Regan, CMPT 300, May Static Relocation: problem  The relocation table is used before the program begins execution  All absolute addresses are relocated  The process begins to run  As the process runs relative addresses (and pointers) may be calculated and stored in variables  The process is swapped out of memory  When the process is moved back into memory  The loader can recalculate all the absolute addresses from the relocation table and move the code to a new location  However all stored addresses refer to the location in memory where the code was originally loaded so when a stored address is used it will point to the wrong place (can even be outside of the process image at the new location)

© Janice Regan, CMPT 300, May Static relocation: limitations  As shown in the previous example static relocation will not allow the image of the process to be moved from its originally allocated position.  Requiring a process to always be loaded at the same place significantly decreases the efficiency of time sharing algorithms  Before the process can be reloaded all processes using any part of the memory space previously allocated to the process must be removed from physical memory.

© Janice Regan, CMPT 300, May Dynamic Relocation  At compile time relative addresses are retained in the loaded executable  Special hardware for fast address translation (MMU) memory management unit  Process ‘thinks’ it is executing at memory location 0, (the logical address) MMU translates to actual location (the physical address)  When an instruction is executed any necessary absolute addresses are calculated

© Janice Regan, CMPT 300, May Dynamic Relocation: Hardware program data stack Process contol Base register bound register Adder Relative address offset Absolute physical address Comparator Error: out of bound: interrupt MMU

© Janice Regan, CMPT 300, May Linking: External References  An application may use libraries, or may be distributed across multiple files.  The linker/loader  Takes as input a collection of object modules  In each object module there may be address references to other modules  Absolute loading  programmer or compiler specified physical addresses  Relocatable linking/loading  The linker/loader combines the modules into a single load module with consistent addresses relative to a common point (usually 0).  This module can be loaded at any location in memory  Dynamic or run-time linking  Allows swapping and relocation of the load module within memory

© Janice Regan, CMPT 300, May External References  An application may use libraries, or may be distributed across multiple files.  The linker  Takes as input a collection of object modules  In each object module there may be address references to other modules  Relocatable linking (using a linkage editor at compile time and a loader capable of static relocation)  Each module assumes it starts at address 0 (beginning of the load module)  Linker makes executable where each object module has addresses relative to the start of the same load module (see next slide)

© Janice Regan, CMPT 300, May Relocatable linking: example Data module 1 Code module 1 Data module 2 Code module 2 Library code Library Data Separate compiled and assembled object modules Load module Data module 1 Code module 1 0 Logical address 0 Three separately compiled object codes. Each starts at logical address zero. All addresses internal to each object modules are relative to address 0 at the beginning of that module. Data module 2 Code module 2 Library code Library Data Logical address 0 Logical address x Logical address y One linked load module, All addresses in module 1 addressing module 2 or library must be changed to point to the new logical addresses in the load module. All addresses internal to module 2 must be changed to be relative to x, in the library to be relative to y. External references from module 2 or the library must also be updated to be consistent within the load module

© Janice Regan, CMPT 300, May Relocatable Linking/Loading  When a load module is statically linked it will contain internally consistent logical addresses and can be loaded as one unit.  Each combination of modules and libraries needed must be separately linked to produce separate load modules  Sharing of libraries/modules is not possible. Each load module includes its own copy of the library or module

© Janice Regan, CMPT 300, May Dynamic load time linking  Defer linking with external modules until load time  While the load module is loading any reference in it to an external module (target module) causes  The target module’s load module to be loaded into to image  The target module can be dynamically loaded starting after the initial load module. References in the load module to addresses in the target module can be updated  Prevents need for relinking when a component is upgraded (commercial software may only supply the executable, cannot be relinked only reloaded)  Provides basis for code sharing (OS loads one copy of modules being used by multiple processes)  Provides a mechanism to easily extend the functionality of a system by adding dynamic link modules

© Janice Regan, CMPT 300, May Run-time Dynamic linking  Linking does not occur until the reference is encountered during execution  Allows modules that are used only in some paths through the application to be loaded only when needed