Académique Documents
Professionnel Documents
Culture Documents
Course Details
Memory Management and File Management
Dr. Ashok Singh Sairam
Grading Policy:
Quiz/Assignment: 12%; Midsem: 34 %; Endsem: 54%
Memory Hierarchy
Memory hierarchy
What is the memory hierarchy?
Different levels of memory Some are small & fast Others are large & slow
Main memory: medium-speed, medium price memory (DRAM) Disk: many gigabytes of slow, cheap, non-volatile storage
static linking
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
10
Dynamic Loading
Routine is not loaded until it is called Better memory-space utilization; unused routine is never loaded Useful when large amounts of code are needed to handle infrequently occurring cases No special support from the operating system is required implemented through program design
11
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
12
Variables and procedures cant use absolute locations in memory Several ways to guarantee this Protect a process from other processes reading or modifying its own memory Protect a process from modifying its own memory in undesirable ways (such as writing to program code)
14
Address generation
Physical address: location in actual memory Logical address: location from the processs point of view Physical address = base + logical address Logical address larger than limit => error
OS
0
16
0
17
Mechanisms
Separate input queues for each partition Single input queue: better ability to optimize CPU usage
900K Partition 4 Partition 3 Partition 2 Partition 1 OS
CS 341: Operating Systems
19
Modeling multiprogramming
More I/O wait means less processor utilization
CPU Utilization 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 0 1 2 3 4 5 6 7 8 9 10 Degree of Multiprogramming 80% I/O Wait 50% I/O Wait 20% I/O Wait
At 20% I/O wait, 34 processes fully utilize CPU At 80% I/O wait, even 10 processes arent enough
This means that the OS should have more processes if theyre I/O bound More processes => memory management & protection more important!
CS 341: Operating Systems
20
Swapping
21
Swapping
C B A OS C B OS C B D OS C D OS C A D OS
A OS
B A OS
24
Limitations of swapping
Problems with swapping
Process must fit into physical memory (impossible to run larger processes) Memory becomes fragmented
External fragmentation: lots of small free areas Compaction needed to reassemble larger free areas
Chapter 4
25
26
27
28
30
31
At any given time we will have a list of available block sizes and an input queue of processes. How to satisfy a request of size n from a list of free holes?
32
Example
Where to allocate memory space for process P2?
Free1
Free2 Free3
Main Memory
33
First Fit
Allocate the first hole that is big enough Searching may start from the beginning or from the position where the last first-fit search ended. Usually the fastest May have many processes loaded at the front end which must be searched and skipped when trying to find a free block.
34
35
Request Size: 16 MB Where would first fit, best fit and worst fit pick?
37
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
CS 341: Operating Systems 38