Professional Documents
Culture Documents
Memory
Memory
Memory
Background
Program must be brought into memory and placed within a process for it to
be run.
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.
Memory-Management Unit
(MMU)
The user program deals with logical addresses; it never sees the real
physical addresses.
Swapping
Backing store fast disk large enough to accommodate copies of all memory
images for all users; must provide direct access to these memory images.
Major part of swap time is transfer time; total transfer time is directly
proportional to the amount of memory swapped.
Memory allocation
OS keeps a table indicating which parts of memory are available and which
are occupied. Initially, all memory is available for user processes, and is
considered as one large block of available memory, a hole.
When a process arrives and needs memory, we search for a hole large
enough for this process.
As processes enter the system, they are put into an i/p queue. The OS takes
into account the memory requirements of each processes and the amount of
available memory space in determining which processes are allocated
memory.
Dynamic Storage-Allocation
Problem
How to satisfy a request of size n from a list of free holes.
Fragmentation
What is Paging?
To run a program of size n pages, need to find n free frames and load
program.
Internal fragmentation
Address Translation
Architecture
Paging Model
Paging Example
What is Segmentation?
The users view is mapped onto physical memory. The mapping allows
differentiation between logical memory and physical memory.
Consider, how you think of a program when you are writing it. Think of it
as a main program with a set of subroutines, procedures, functions, or
modules. There may also be various data structures : tables, arrays, stacks,
variables, and so on. Each of these modules is referred to by name. you
talk about the symbol table, function sqrt, the main program, without
caring what address in memory these elements occupy.
You are not concerned with whether the symbol table is stored before or
after the sqrt fn. Each of these segments is of variable length.
The construct:
<segment-number, offset>
Elements within a segment are identified by their offset from the beginning
of the segment. Each segment is of variable length.
Hardware
Although the user can now refer to objects in the program by a twodimensional address, the actual physical memory is still, of course, a onedimensional sequence of bytes. Thus, we must define an implementation to
map two dimensional user-defined address into one dimensional physical
addresses. This mapping is affected by a segment table. Each entry of the
segment table has a segment base and a segment limit.
Base contains the starting physical address whereas the limit specifies the
length of the segment.
Segmentation Hardware
For example, segment 2 is 400 bytes long and begins at location 4300.
thus, a reference to byte 53, of segment 2 is mapped onto location
4300+53=4353. a reference to segment 3, byte 852, is mapped to 3200 (the
base of segment 3)+852=4052. a reference to byte 1222 of segment 0
would result in a trap to the OS, as this segment is only 1000 bytes long.
Example of Segmentation
Thrashing
If a process does not have enough pages, the page-fault rate is very high.
This leads to:
low CPU utilization.
operating system thinks that it needs to increase the degree of
multiprogramming.
another process added to the system.
Thrashing
Page Replacement
Use modify (dirty) bit to reduce overhead of page transfers only modified
pages are written to disk.
algorithm to
3. Read the desired page into the (newly) free frame. Update the page and
frame tables.
4. Restart the process.
Page Replacement
Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
3 frames (3 pages can be in memory at a time per process)
4 frames
9 page faults
10 page faults
Optimal Algorithm
Replace page that will not be used for longest period of time.
4 frames example
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
1
6 page faults
3
4
Counter implementation
Every page entry has a counter; every time page is referenced through
this entry, copy the clock into the counter.
When a page needs to be changed, look at the counters to determine
which are to change.
Reference bit
With each page associate a bit, initially = 0
When page is referenced bit set to 1.
Replace the one which is 0 (if one exists). We do not know the
order, however.
Second chance
Need reference bit.
Clock replacement.
If page to be replaced (in clock order) has reference bit = 1. then:
set reference bit 0.
leave page in memory.
replace next page (in clock order), subject to same rules.
Counting Algorithms
Keep a counter of the number of references that have been made to each
page.
MFU Algorithm: based on the argument that the page with the smallest
count was probably just brought in and has yet to be used.
Allocation of Frames
Fixed Allocation
Equal allocation e.g., if 100 frames and 5 processes, give
each 20 pages.
Proportional allocation Allocate according to the size of
process.
si size of process pi
S si
m total number of frames
s
ai allocation for pi i m
S
m 64
si 10
s2 127
10
64 5
137
127
a2
64 59
137
a1
Priority Allocation
Local replacement each process selects from only its own set of allocated
frames.