Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 30 Syed Mansoor Sarwar

Similar presentations


Presentation on theme: "Lecture 30 Syed Mansoor Sarwar"— Presentation transcript:

1 Lecture 30 Syed Mansoor Sarwar
Operating Systems Lecture 30 Syed Mansoor Sarwar

2 © Copyright Virtual University of Pakistan
Agenda for Today Review of previous lecture What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking, and overlays Recap of lecture 10 December 2018 © Copyright Virtual University of Pakistan

3 © Copyright Virtual University of Pakistan
Review of Lecture 29 Deadlock detection Deadlock recovery Process termination Resource preemption 10 December 2018 © Copyright Virtual University of Pakistan

4 © Copyright Virtual University of Pakistan
Memory Hierarchy Very small, extremely fast, extremely expensive, and volatile CPU registers Small, very fast, expensive, and volatile cache Hundreds of megabytes of medium-speed, medium-price, volatile main memory Hundreds of gigabytes of slow, cheap, and non-volatile secondary storage 10 December 2018 © Copyright Virtual University of Pakistan

5 Purpose of Memory Management
To ensure fair, secure, orderly, and efficient use of memory 10 December 2018 © Copyright Virtual University of Pakistan

6 © Copyright Virtual University of Pakistan
Memory Management Keeping track of used and free memory space When, where, and how much memory to allocate and deallocate Swapping processes in and out of main memory 10 December 2018 © Copyright Virtual University of Pakistan

7 © Copyright Virtual University of Pakistan
Source to Execution Compile/Assemble Link Load Execute 10 December 2018 © Copyright Virtual University of Pakistan

8 © Copyright Virtual University of Pakistan
10 December 2018 © Copyright Virtual University of Pakistan

9 © Copyright Virtual University of Pakistan
Address Binding Binding instructions and data to memory addresses Compile time Load time Execution time 10 December 2018 © Copyright Virtual University of Pakistan

10 © Copyright Virtual University of Pakistan
Address Binding Compile time: If you know at compile time where the process will reside in memory, the absolute code can be generated. Process must reside in the same memory region for it to execute correctly. 10 December 2018 © Copyright Virtual University of Pakistan

11 © Copyright Virtual University of Pakistan
Address Binding Load time: If the location of a process in memory is not known at compile time, then the compiler must generate re-locatable code. In this case the final binding is delayed until load time. Process can be loaded in different memory regions. 10 December 2018 © Copyright Virtual University of Pakistan

12 © Copyright Virtual University of Pakistan
Address Binding Execution time: If the process can be moved during its execution from one memory region to another, then binding must be delayed until run time. Special hardware must be available for this to work. 10 December 2018 © Copyright Virtual University of Pakistan

13 Logical and Physical Addresses
Logical address: An address generated by the process/CPU; refers to an instruction or data in the process Physical address: An address for a main memory location where instruction or data resides 10 December 2018 © Copyright Virtual University of Pakistan

14 Logical and Physical Address Spaces
The set of all logical addresses generated by a process comprises its logical address space. The set of physical addresses corresponding to these logical addresses comprises the physical address space for the process. 10 December 2018 © Copyright Virtual University of Pakistan

15 Logical and Physical Address Spaces
The run-time mapping from logical to physical addresses is done by a piece of the CPU hardware, called the memory management unit (MMU). 10 December 2018 © Copyright Virtual University of Pakistan

16 © Copyright Virtual University of Pakistan
Example The base register is called the relocation register. The value in the relocation register is added to every address generated by a user process at the time it is sent to memory. 10 December 2018 © Copyright Virtual University of Pakistan

17 © Copyright Virtual University of Pakistan
Example 14000 Process 10 December 2018 © Copyright Virtual University of Pakistan

18 © Copyright Virtual University of Pakistan
Example In i8086, the logical address of the next instruction is specified by the value of instruction pointer (IP). The physical address for the instruction is computed by shifting the code segment register (CS) left by four bits and adding IP to it. 10 December 2018 © Copyright Virtual University of Pakistan

19 © Copyright Virtual University of Pakistan
Example CS * 24 Physical address Logical address + CPU MMU 10 December 2018 © Copyright Virtual University of Pakistan

20 © Copyright Virtual University of Pakistan
Example Logical address (16-bit) IP = 0B10h CS = D000h Physical address (20-bit) CS * 24 + IP = D0B10h Sizes of logical and physical address spaces? 10 December 2018 © Copyright Virtual University of Pakistan

21 © Copyright Virtual University of Pakistan
Dynamic Loading With dynamic loading, a routine is not loaded into the main memory until it is called. All routines are kept on the disk in a re-locatable format. The main program is loaded into memory and is executed 10 December 2018 © Copyright Virtual University of Pakistan

22 © Copyright Virtual University of Pakistan
Dynamic Loading Advantages Potentially less time needed to load a program Potentially less memory space needed Disadvantage Run-time activity 10 December 2018 © Copyright Virtual University of Pakistan

23 © Copyright Virtual University of Pakistan
Dynamic Linking In static linking, system language libraries are linked at compile time and, like any other object module, are combined by the loader into the binary image 10 December 2018 © Copyright Virtual University of Pakistan

24 © Copyright Virtual University of Pakistan
Dynamic Linking In dynamic linking, linking is postponed until run-time. A library call is replaced by a piece of code, called stub, which is used to locate memory-resident library routine 10 December 2018 © Copyright Virtual University of Pakistan

25 © Copyright Virtual University of Pakistan
Dynamic Linking During execution of a process, stub is replaced by the address of the relevant library code and the code is executed If library code is not in memory, it is loaded at this time 10 December 2018 © Copyright Virtual University of Pakistan

26 © Copyright Virtual University of Pakistan
Dynamic Linking Advantages Potentially less time needed to load a program Potentially less memory space needed Less disk space needed to store binaries 10 December 2018 © Copyright Virtual University of Pakistan

27 © Copyright Virtual University of Pakistan
Dynamic Linking Disadvantages Time-consuming run-time activity, resulting in slower program execution gcc compiler Dynamic linking by default -static option allows static linking 10 December 2018 © Copyright Virtual University of Pakistan

28 © Copyright Virtual University of Pakistan
Recap of Lecture What is memory management From source code to execution Address binding Logical and physical address spaces Dynamic loading Dynamic linking 10 December 2018 © Copyright Virtual University of Pakistan

29 © Copyright Virtual University of Pakistan
Operating Systems Lecture 30 Syed Mansoor Sarwar 10 December 2018 © Copyright Virtual University of Pakistan


Download ppt "Lecture 30 Syed Mansoor Sarwar"

Similar presentations


Ads by Google