ADDRESS BINDING SCHEME
Presented By:
Rajesh Piryani
South Asian University
1
9/22/2011
Outline
 Introduction to Address Binding Scheme
 Types of Addresses
 Linking and Loading
 Overlays
 Swapping
2
9/22/2011
Address Binding
3
 Process moves between memory and disk during
execution
Executable File of
Program
Hard Disk
Executable file placed
within process
Main Memory
Brought for
execution
P1 P2 P3 P4 P5 P6
Input Queue
P1Brought for
execution
Main Memory9/22/2011
Address Binding (Continued..)
4
 Input queue – collection of processes on the disk that are
waiting to be brought into memory to run the program
 One process selected—brought to memory
 Process executes—Access instruction and data
 Process terminate—memory acquired get released.
9/22/2011
Address Binding (Continued..)
5
 Most systems allow a user process to reside in any part of the
physical memory.
 Thus, address space of the computer starts at 00000
 first address of the user process need not be 00000.
Symbolic
Address
Compiler
Binds
Relocatable
address
Linkage
Loader
binds
Binds
Absolute
address
Source Program
9/22/2011
Types of Addresses
6
 Symbolic Addresses
 Eg, variable names(such as variable i)
 Relocateable Addresses
 A compiler typically binds symbolic addresses to
relocatable addresses (in terms of offsets).
 eg. 100 bytes from the beginning of this module
 Absolute Addresses
 The linkage editor or loader binds relocatable addresses to
absolute addresses (physical addresses).
 eg. 74014 9/22/2011
Multistep Processing of a User Program
7
9/22/2011
Binding of Instructions and Data to
Memory
8
 Compile time: If memory location known a priori, absolute
code can be generated; must recompile code if starting
location changes
 MS-DOS.COM format programs are absolute code
 Load time: Must generate relocatable code if memory location
is not known at compile time
 Execution time: Binding delayed until run time if the process
can be moved during its execution from one memory segment
to another. Need hardware support for address maps (e.g.,
base and limit registers). 9/22/2011
A base and a limit register define a logical address space
9
9/22/2011
Logical vs. Physical Address Space
 Logical address – generated by the CPU; also referred
to as virtual address
 Physical address – address seen by the memory unit
 Logical and physical addresses are the same in
 compile-time and
 load-time address-binding schemes
 logical (virtual) and physical addresses differ in
execution-time address-binding scheme
10
9/22/2011
Memory-Management Unit (MMU)
 Hardware device that maps virtual to physical address
 Different methods to accomplish such a mapping.
 Contiguous Memory Allocation, Paging, Segmentation, Segmentation
with Paging
 In MMU scheme, the value in the relocation register is added to
every address generated by a user process at the time it is sent
to memory.
 The user program deals with logical addresses; it never sees the
real physical addresses
11
9/22/2011
Dynamic relocation using a relocation
register12
9/22/2011
How C Program Compile
13
Source Code
Preprocessing
Compilation
Assembly
Linking
Final Executable
9/22/2011
{ }
Preprocessing(Expand Macros)
#
14
#
……
…...
{ }
9/22/2011
Compilation (from Source Code to
Assembly Language)15
…...
{ }
MOV
XOR
JMP
9/22/2011
Assembly(From Assembly Language
to Machine Language Code)
 Assembler Leaves the address of external function
undefined
16
1010
1102
MOV
XOR
JMP
?
9/22/2011
Linking(create the final Executable
File)17
1010
1102
?
1010
1010
1110
1102
1010
1110
External Library
9/22/2011
Compilation Stages
18
.C .i .s .o .out
Source
Code
Preprocess
ed Code
Assembly
Language
Code
Machine
Language
Code
Machine
Code
(Object
Code)
Preproc
essor
Compila
tion
Assembl
y
Linking
9/22/2011
19
9/22/2011
Scenario of linking and loading
20
9/22/2011
Loading
 A loader is responsible to place a load module in
main memory at some starting address.
 Three approaches for loading
1. Absolute Loading
2. Relocatable Loading
3. Dynamic Loading
21
9/22/2011
Loading Example
22
9/22/2011
Disadvantage of Absolute Loading
 Programmer know assignment strategy for placing module into
main memory.
 If modification make due to other module, all addresses will be
altered.
 Load modules only can be placed in one region of memory.
23
9/22/2011
Dynamic Loading
 Routine is not loaded until it is called.
 All routines are kept on the disk in a relocatable
load format.
 Better memory-space utilization; unused routine is never
loaded
 Useful when large amounts of code are needed to
handle infrequently occurring cases
24
9/22/2011
Linking
 input a collection of object modules and produce a load
module, consisting of an integrated set of program and data
modules, to be passed to the loader.
25
9/22/2011
Linking Example
26
9/22/2011
Dynamic Linking
 Linking postponed until execution time
 Small piece of code, stub, used to locate the appropriate memory-resident
library routine
 Stub replaces itself with the address of the routine, and executes the routine
 Operating system needed to check if routine is in processes’ memory address
 Dynamic linking is particularly useful for libraries
 Dynamic Linking and dynamic loading required OS.
27
9/22/2011
Static and Dynamic Linking in Unix
 Static Linking
 Suppose we have math.c file for static linking.
 Now make a archive or static lib with the object file.
$ar rc libmath.a math.o
 To use this static library in a application we need to do
the following steps:
 compile the application code (place math.h in include folder)
 $cc -c app.c -Iinclude -o app.o
 Link with static library math.a
 $ld app.o libmath.a -o app
 Run the application
 $./app
28
9/22/2011
Dynamic Linking
 Dynamic Linking
 Implicit Dynamic Linking:
 Suppose we have math.c file for dynamic linking.
 compile it with position independent flag on(-fPIC). This is
needed for dynamic/static linking.
 $cc -fPIC -c math.c
 Now make a shared library with the object file.
 $cc -shared libmath.so math.o
29
9/22/2011
Dynamic Linking Continued..
 To use this shared library in a application we need to do the
following steps:
 compile the application code (place math.h in include folder)
 $cc -c app.c -Iinclude -o app.o
 Link with import library math.lib
 $ld app.o -lmath -o app
 Copy the libmath.so in lib path or current path and run the
application
 $./app
30
9/22/2011
Implicit Dynamic Linking or loading
 When application or client uses its import table to link the
external symbol/functions, it is called implicit linking.
 In implicit linking application use prototype header and import
library to link an external symbol.
 Example: Suppose we have a third party math library and
add() is a function/interface we are using in our application.
 Then the following steps are needed
 include the math.h where add() prototype is there as a
import function for compilation,
 Include math.lib for linking.
 place math.dll DLL at the path of our application.
31
9/22/2011
Explicit Dynamic Linking/Loading:
 When application does not link the external symbol by import
library rather it loads the DLL at runtime.
 It does the same mechanism as operating system does during
loading of the implicit linked DLL calls.
 This is done by using Win32 APIs like:
 LoadLibrary() - loads and links a input library form the DLL
path, or current path,
 GetProcAddress() - finds the symbol/function address by its
name for a loaded DLL
 FreeLibrary() - unloads the loaded DLL instance
32
9/22/2011
Dynamic Linking Continued….
 Explicit Dynamic Linking:
 Suppose we have math.c file for dynamic linking.
 compile it with position independent flag on(-fPIC). This is needed
for dynamic
 $cc -fPIC -c math.c
 Now make a shared library with the object file.
 $cc -shared libmath.so math.o
 To use this shared library in a application we need to load the
library then find the function pointer address, invoke the function,
and at last unload the library.
33
9/22/2011
Overlays
 Enable a process to be larger than the amount of memory allocated
to it.
 Idea to keep in memory only those instruction and data that are
needed at any give time.
 Consider example of two pass assembler
 Pass 1 70 KB :-it construct symbol table
 Pass 2 80 KB :-it generate machine language code
 Symbol Table 20 KB
 Common Routines 30 KB
 Required space 200 KB
 Memory space is 150 KB
34
9/22/2011
Overlays Continued…
 Overlays A
 Pass 1 70 KB
 Symbol table 20 KB
 Common routines 30KB
 Total size 120KB
 Overlay driver 10 KB
 Overlays B
 Pass 2 80 KB
 Symbol table 20 KB
 Common routines 30KB
 Total size 130KB
 Overlay driver 10 KB
35
Symbol
Table
Common
Routine
Overlay
Driver
PASS 1 PASS 2
20 K
30 K
10 K
70 K 80 K
Figure: Overlays for a two pass
Assembler
9/22/2011
Overlays Continued…
 Code of overlay A and Overlay B are kept on disk as absolute memory images
 Special relocation and liking algorithm needed.
 Overlays don’t require any special support from OS.
 Implemented completely by the user with simple file structure
 OS notices than there is more i/o than usual
 Small program do not need to be overlaid
 Overlays currently limited to microcomputer.
36
9/22/2011
Swapping
 A process can be swapped temporarily out of memory to a backing
store, and then brought back into memory for continued execution
 Backing store – fast disk large enough to accommodate copies of
all memory images for all users; must provide direct access to these
memory images
 Roll out, roll in – swapping variant used for priority-based
scheduling algorithms; lower-priority process is swapped out so
higher-priority process can be loaded and executed
 Major part of swap time is transfer time; total transfer time is
directly proportional to the amount of memory swapped
 Modified versions of swapping are found on many systems (i.e.,
UNIX, Linux, and Windows)
37
9/22/2011
Schematic View of Swapping
38
9/22/2011
SWAPPING
 Context-switch time is fairly high.
 Example:
 User process is of size1 MB
 Backing store is standard hard disk with transfer rate of 5MB/sec
 Actual transfer of 1MB=1/5 seconds=200 milliseconds.
 Swap out and Swap in will take=400 milliseconds
 In round robin: quantum>0.4 seconds
Total transfer time is directly proportional to amount of memory
swapped.
39
9/22/2011
Contiguous Allocation
 Main memory usually into two partitions:
 Resident operating system, usually held in low
memory with interrupt vector
 User processes then held in high memory
40
9/22/2011
Memory Protection
 Protecting OS from USER PROCESSES
 And Protecting USER PROCESSES from one another
 Relocation Register
 it contains the smallest physical address
 Limit Register
 It contains the range of logical address
 Each logical address must be less than limit register.
 MMU maps the logical address dynamically by adding the value in the
relocation register.
41
9/22/2011
A base and a limit register define a logical
address space
42
9/22/2011
HW address protection with base
and limit registers
 When the CPU scheduler selects a process for execution
 dispatcher loads the relocation register and limit register with the correct value
43
9/22/2011
Memory Allocation
 Fixed Size Partition:
 Divide memory into several fixed size partition.
 Each Partition may contain exactly one process.
 This method used by IBM OS/360 (called MFT). No
longer use.
 Next generalized method of fixed partition scheme
(called MVT)
 Used in batch environment
44
9/22/2011
Example of Fixed Size partition
Jobs Memory
Requirement
P1 200K
P2 95K
P3 540K
P4 10K
P5 110K
P6 250
45
OS
P2
P4
0K
300K
400K
500K
600K
700K
800K
900K
1000K
Main Memory
P1
P5
5K
90K
90K
100K
285K
We have 285K memory available , but we can not
fix P6 Process  Internal Fragmentation
9/22/2011
MVT Scheme (Multiple Partition
Allocation)
 Initially all memory available for user process.
 Considered one block of available memory, called hole.
 When process arrives, search for large enough hole for this
process, and it get allocated.
46
9/22/2011
MVT (Cont.)
 Multiple-partition allocation
 Hole – block of available memory; holes of various size
are scattered throughout memory
 When a process arrives, it is allocated memory from a
hole large enough to accommodate it
 Operating system maintains information about:
a) allocated partitions b) free partitions (hole)
47
9/22/2011
Jobs Memory
Requirement
P1 600K
P2 1000K
P3 300K
P4 700K
P5 500K
P6 200
48
OS
0K
400K
1000K
2000K
2300K
2560K
Main Memory
P1
P2
P3
Example of MVT(Multiple) Size
partition
9/22/2011
Jobs Memory
Requirement
P1 600K
P2 1000K
P3 300K
P4 700K
P5 500K
P6 200
49
OS
0K
400K
1000K
2000K
2300K
2560K
Main Memory
P1
FREE
P3
FREE
Example of MVT(Multiple) Size
partition
9/22/2011
Example of MVT(Multiple) Size
partition
Jobs Memory
Requirement
P1 600K
P2 1000K
P3 300K
P4 700K
P5 500K
P6 200
50
OS
0K
400K
1000K
2000K
2300K
2560K
Main Memory
P1
P4
P3
FREE
FREE
1700K
300K
260K
560K
We have 560K memory available , but we can not
fix P5 Process  External Fragmentation
9/22/2011
Dynamic Storage-Allocation
Problem
 First-fit: Allocate the first hole that is big enough
 Best-fit: Allocate the smallest hole that is big enough; must
search entire list, unless ordered by size. Produces the
smallest leftover hole.
 Worst-fit: Allocate the largest hole; must also search entire
list. Produces the largest leftover hole.
How to satisfy a request of size n from a list of free holes
First-fit and best-fit better than worst-fit in terms of speed and storage
utilization
51
9/22/2011
Fragmentation
 External Fragmentation – total memory space exists
to satisfy a request, but it is not contiguous
 Internal Fragmentation – allocated memory may be
slightly larger than requested memory; this size
difference is memory internal to a partition, but not
being used
 Reduce external fragmentation by compaction
 Shuffle memory contents to place all free memory
together in one large block
 Compaction is possible only if relocation is dynamic, and is
done at execution time
52
9/22/2011
References
 Books
 Operating System Concepts-Sixth Edition- By. Silberschatz Galvin
Gagne
 Operating System-William Stallings-6th edition
 Links
 http://operatingsystemconcepts4u.blogspot.com/2008/10/dynamic
-loading_13.html
 http://en.wikipedia.org/wiki/Dynamic_loading
 http://en.wikipedia.org/wiki/Dynamic-link_library
 http://www.mybestnotes.co.in/dll/how-we-use-dynamic-linking-in-
linux-give-example.php
 http://www.youtube.com/watch?v=2dan4hJlOv0
53
9/22/2011
Thank You For Your Cooperation
54
9/22/2011
QUESTIONS????
55
9/22/2011

Address Binding Scheme

  • 1.
    ADDRESS BINDING SCHEME PresentedBy: Rajesh Piryani South Asian University 1 9/22/2011
  • 2.
    Outline  Introduction toAddress Binding Scheme  Types of Addresses  Linking and Loading  Overlays  Swapping 2 9/22/2011
  • 3.
    Address Binding 3  Processmoves between memory and disk during execution Executable File of Program Hard Disk Executable file placed within process Main Memory Brought for execution P1 P2 P3 P4 P5 P6 Input Queue P1Brought for execution Main Memory9/22/2011
  • 4.
    Address Binding (Continued..) 4 Input queue – collection of processes on the disk that are waiting to be brought into memory to run the program  One process selected—brought to memory  Process executes—Access instruction and data  Process terminate—memory acquired get released. 9/22/2011
  • 5.
    Address Binding (Continued..) 5 Most systems allow a user process to reside in any part of the physical memory.  Thus, address space of the computer starts at 00000  first address of the user process need not be 00000. Symbolic Address Compiler Binds Relocatable address Linkage Loader binds Binds Absolute address Source Program 9/22/2011
  • 6.
    Types of Addresses 6 Symbolic Addresses  Eg, variable names(such as variable i)  Relocateable Addresses  A compiler typically binds symbolic addresses to relocatable addresses (in terms of offsets).  eg. 100 bytes from the beginning of this module  Absolute Addresses  The linkage editor or loader binds relocatable addresses to absolute addresses (physical addresses).  eg. 74014 9/22/2011
  • 7.
    Multistep Processing ofa User Program 7 9/22/2011
  • 8.
    Binding of Instructionsand Data to Memory 8  Compile time: If memory location known a priori, absolute code can be generated; must recompile code if starting location changes  MS-DOS.COM format programs are absolute code  Load time: Must generate relocatable code if memory location is not known at compile time  Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers). 9/22/2011
  • 9.
    A base anda limit register define a logical address space 9 9/22/2011
  • 10.
    Logical vs. PhysicalAddress Space  Logical address – generated by the CPU; also referred to as virtual address  Physical address – address seen by the memory unit  Logical and physical addresses are the same in  compile-time and  load-time address-binding schemes  logical (virtual) and physical addresses differ in execution-time address-binding scheme 10 9/22/2011
  • 11.
    Memory-Management Unit (MMU) Hardware device that maps virtual to physical address  Different methods to accomplish such a mapping.  Contiguous Memory Allocation, Paging, Segmentation, Segmentation with Paging  In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory.  The user program deals with logical addresses; it never sees the real physical addresses 11 9/22/2011
  • 12.
    Dynamic relocation usinga relocation register12 9/22/2011
  • 13.
    How C ProgramCompile 13 Source Code Preprocessing Compilation Assembly Linking Final Executable 9/22/2011
  • 14.
  • 15.
    Compilation (from SourceCode to Assembly Language)15 …... { } MOV XOR JMP 9/22/2011
  • 16.
    Assembly(From Assembly Language toMachine Language Code)  Assembler Leaves the address of external function undefined 16 1010 1102 MOV XOR JMP ? 9/22/2011
  • 17.
    Linking(create the finalExecutable File)17 1010 1102 ? 1010 1010 1110 1102 1010 1110 External Library 9/22/2011
  • 18.
    Compilation Stages 18 .C .i.s .o .out Source Code Preprocess ed Code Assembly Language Code Machine Language Code Machine Code (Object Code) Preproc essor Compila tion Assembl y Linking 9/22/2011
  • 19.
  • 20.
    Scenario of linkingand loading 20 9/22/2011
  • 21.
    Loading  A loaderis responsible to place a load module in main memory at some starting address.  Three approaches for loading 1. Absolute Loading 2. Relocatable Loading 3. Dynamic Loading 21 9/22/2011
  • 22.
  • 23.
    Disadvantage of AbsoluteLoading  Programmer know assignment strategy for placing module into main memory.  If modification make due to other module, all addresses will be altered.  Load modules only can be placed in one region of memory. 23 9/22/2011
  • 24.
    Dynamic Loading  Routineis not loaded until it is called.  All routines are kept on the disk in a relocatable load format.  Better memory-space utilization; unused routine is never loaded  Useful when large amounts of code are needed to handle infrequently occurring cases 24 9/22/2011
  • 25.
    Linking  input acollection of object modules and produce a load module, consisting of an integrated set of program and data modules, to be passed to the loader. 25 9/22/2011
  • 26.
  • 27.
    Dynamic Linking  Linkingpostponed until execution time  Small piece of code, stub, used to locate the appropriate memory-resident library routine  Stub replaces itself with the address of the routine, and executes the routine  Operating system needed to check if routine is in processes’ memory address  Dynamic linking is particularly useful for libraries  Dynamic Linking and dynamic loading required OS. 27 9/22/2011
  • 28.
    Static and DynamicLinking in Unix  Static Linking  Suppose we have math.c file for static linking.  Now make a archive or static lib with the object file. $ar rc libmath.a math.o  To use this static library in a application we need to do the following steps:  compile the application code (place math.h in include folder)  $cc -c app.c -Iinclude -o app.o  Link with static library math.a  $ld app.o libmath.a -o app  Run the application  $./app 28 9/22/2011
  • 29.
    Dynamic Linking  DynamicLinking  Implicit Dynamic Linking:  Suppose we have math.c file for dynamic linking.  compile it with position independent flag on(-fPIC). This is needed for dynamic/static linking.  $cc -fPIC -c math.c  Now make a shared library with the object file.  $cc -shared libmath.so math.o 29 9/22/2011
  • 30.
    Dynamic Linking Continued.. To use this shared library in a application we need to do the following steps:  compile the application code (place math.h in include folder)  $cc -c app.c -Iinclude -o app.o  Link with import library math.lib  $ld app.o -lmath -o app  Copy the libmath.so in lib path or current path and run the application  $./app 30 9/22/2011
  • 31.
    Implicit Dynamic Linkingor loading  When application or client uses its import table to link the external symbol/functions, it is called implicit linking.  In implicit linking application use prototype header and import library to link an external symbol.  Example: Suppose we have a third party math library and add() is a function/interface we are using in our application.  Then the following steps are needed  include the math.h where add() prototype is there as a import function for compilation,  Include math.lib for linking.  place math.dll DLL at the path of our application. 31 9/22/2011
  • 32.
    Explicit Dynamic Linking/Loading: When application does not link the external symbol by import library rather it loads the DLL at runtime.  It does the same mechanism as operating system does during loading of the implicit linked DLL calls.  This is done by using Win32 APIs like:  LoadLibrary() - loads and links a input library form the DLL path, or current path,  GetProcAddress() - finds the symbol/function address by its name for a loaded DLL  FreeLibrary() - unloads the loaded DLL instance 32 9/22/2011
  • 33.
    Dynamic Linking Continued…. Explicit Dynamic Linking:  Suppose we have math.c file for dynamic linking.  compile it with position independent flag on(-fPIC). This is needed for dynamic  $cc -fPIC -c math.c  Now make a shared library with the object file.  $cc -shared libmath.so math.o  To use this shared library in a application we need to load the library then find the function pointer address, invoke the function, and at last unload the library. 33 9/22/2011
  • 34.
    Overlays  Enable aprocess to be larger than the amount of memory allocated to it.  Idea to keep in memory only those instruction and data that are needed at any give time.  Consider example of two pass assembler  Pass 1 70 KB :-it construct symbol table  Pass 2 80 KB :-it generate machine language code  Symbol Table 20 KB  Common Routines 30 KB  Required space 200 KB  Memory space is 150 KB 34 9/22/2011
  • 35.
    Overlays Continued…  OverlaysA  Pass 1 70 KB  Symbol table 20 KB  Common routines 30KB  Total size 120KB  Overlay driver 10 KB  Overlays B  Pass 2 80 KB  Symbol table 20 KB  Common routines 30KB  Total size 130KB  Overlay driver 10 KB 35 Symbol Table Common Routine Overlay Driver PASS 1 PASS 2 20 K 30 K 10 K 70 K 80 K Figure: Overlays for a two pass Assembler 9/22/2011
  • 36.
    Overlays Continued…  Codeof overlay A and Overlay B are kept on disk as absolute memory images  Special relocation and liking algorithm needed.  Overlays don’t require any special support from OS.  Implemented completely by the user with simple file structure  OS notices than there is more i/o than usual  Small program do not need to be overlaid  Overlays currently limited to microcomputer. 36 9/22/2011
  • 37.
    Swapping  A processcan be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution  Backing store – fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images  Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed  Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped  Modified versions of swapping are found on many systems (i.e., UNIX, Linux, and Windows) 37 9/22/2011
  • 38.
    Schematic View ofSwapping 38 9/22/2011
  • 39.
    SWAPPING  Context-switch timeis fairly high.  Example:  User process is of size1 MB  Backing store is standard hard disk with transfer rate of 5MB/sec  Actual transfer of 1MB=1/5 seconds=200 milliseconds.  Swap out and Swap in will take=400 milliseconds  In round robin: quantum>0.4 seconds Total transfer time is directly proportional to amount of memory swapped. 39 9/22/2011
  • 40.
    Contiguous Allocation  Mainmemory usually into two partitions:  Resident operating system, usually held in low memory with interrupt vector  User processes then held in high memory 40 9/22/2011
  • 41.
    Memory Protection  ProtectingOS from USER PROCESSES  And Protecting USER PROCESSES from one another  Relocation Register  it contains the smallest physical address  Limit Register  It contains the range of logical address  Each logical address must be less than limit register.  MMU maps the logical address dynamically by adding the value in the relocation register. 41 9/22/2011
  • 42.
    A base anda limit register define a logical address space 42 9/22/2011
  • 43.
    HW address protectionwith base and limit registers  When the CPU scheduler selects a process for execution  dispatcher loads the relocation register and limit register with the correct value 43 9/22/2011
  • 44.
    Memory Allocation  FixedSize Partition:  Divide memory into several fixed size partition.  Each Partition may contain exactly one process.  This method used by IBM OS/360 (called MFT). No longer use.  Next generalized method of fixed partition scheme (called MVT)  Used in batch environment 44 9/22/2011
  • 45.
    Example of FixedSize partition Jobs Memory Requirement P1 200K P2 95K P3 540K P4 10K P5 110K P6 250 45 OS P2 P4 0K 300K 400K 500K 600K 700K 800K 900K 1000K Main Memory P1 P5 5K 90K 90K 100K 285K We have 285K memory available , but we can not fix P6 Process  Internal Fragmentation 9/22/2011
  • 46.
    MVT Scheme (MultiplePartition Allocation)  Initially all memory available for user process.  Considered one block of available memory, called hole.  When process arrives, search for large enough hole for this process, and it get allocated. 46 9/22/2011
  • 47.
    MVT (Cont.)  Multiple-partitionallocation  Hole – block of available memory; holes of various size are scattered throughout memory  When a process arrives, it is allocated memory from a hole large enough to accommodate it  Operating system maintains information about: a) allocated partitions b) free partitions (hole) 47 9/22/2011
  • 48.
    Jobs Memory Requirement P1 600K P21000K P3 300K P4 700K P5 500K P6 200 48 OS 0K 400K 1000K 2000K 2300K 2560K Main Memory P1 P2 P3 Example of MVT(Multiple) Size partition 9/22/2011
  • 49.
    Jobs Memory Requirement P1 600K P21000K P3 300K P4 700K P5 500K P6 200 49 OS 0K 400K 1000K 2000K 2300K 2560K Main Memory P1 FREE P3 FREE Example of MVT(Multiple) Size partition 9/22/2011
  • 50.
    Example of MVT(Multiple)Size partition Jobs Memory Requirement P1 600K P2 1000K P3 300K P4 700K P5 500K P6 200 50 OS 0K 400K 1000K 2000K 2300K 2560K Main Memory P1 P4 P3 FREE FREE 1700K 300K 260K 560K We have 560K memory available , but we can not fix P5 Process  External Fragmentation 9/22/2011
  • 51.
    Dynamic Storage-Allocation Problem  First-fit:Allocate the first hole that is big enough  Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole.  Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole. How to satisfy a request of size n from a list of free holes First-fit and best-fit better than worst-fit in terms of speed and storage utilization 51 9/22/2011
  • 52.
    Fragmentation  External Fragmentation– total memory space exists to satisfy a request, but it is not contiguous  Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used  Reduce external fragmentation by compaction  Shuffle memory contents to place all free memory together in one large block  Compaction is possible only if relocation is dynamic, and is done at execution time 52 9/22/2011
  • 53.
    References  Books  OperatingSystem Concepts-Sixth Edition- By. Silberschatz Galvin Gagne  Operating System-William Stallings-6th edition  Links  http://operatingsystemconcepts4u.blogspot.com/2008/10/dynamic -loading_13.html  http://en.wikipedia.org/wiki/Dynamic_loading  http://en.wikipedia.org/wiki/Dynamic-link_library  http://www.mybestnotes.co.in/dll/how-we-use-dynamic-linking-in- linux-give-example.php  http://www.youtube.com/watch?v=2dan4hJlOv0 53 9/22/2011
  • 54.
    Thank You ForYour Cooperation 54 9/22/2011
  • 55.