Memory(Whole Unit Notes)
Memory(Whole Unit Notes)
■ Background
■ Swapping
■ Contiguous Allocation
■ Paging
■ Segmentation
■ User (or system) usually does not know where the data that makes
up a program eventually will reside in memory.
● Assume it logically resides contiguously, starting at address 0
(although some code / situations require absolute addressing)
0
0
L
Program's n
logical
memory
n+L-1
System's
physical
memory
■ Execution time: Binding delayed until run time if the process can be
moved during its execution from one memory segment to another.
● Need special hardware (e.g., base and limit registers).
■ Dynamic loading
● Keep functions/procedures/methods as separate, loadable routines
● Only load a routine when it is needed (for user code)
■ Dynamic linking
● Not often supported
● Only link (resolve addressing of) system library routines when called
(for system code)
■ Overlays
● Quite common when memory constrained (e.g., in the past)
● Separate the “common” portions of program from portions executed at
different times
● After one part of program is executed, load another part into that
same space, and OVERLAY the first
● Much work for programmer – system does not help you – tools may
■ Stub replaces itself with the address of the routine, and executes
the routine
■ Purpose
● To protect user processes from each other, and from
changing operating system code and data.
■ Technique
● Base register (sometimes called relocation register)
contains value of smallest physical address process can use
● Limit register contains range of logical addresses –
Each logical address must be less than the limit register
Each physical address must be less than the base register +
limit register – 1
OS OS OS OS
process 8 process 10
■ Compaction
● Like “garbage collection” routines
● Move code blocks together, to get rid of small blocks of free
space and create large ones
● NOTE, however – this requires time ! ! !
● Also, it can only be done if mapping from logical to physical
addresses at run time (e.g., using base/limit registers, etc.)
● Then, there can also be I/O-related problems / concerns
Must have job in memory while it is involved in I/O.
Do I/O only into OS buffers (not into job’s buffers)
You
think
your
code But it
looks really
like looks
this like this
in main
memory
Can have one page table per job, or move data around in page table
Most common to have a separate page table for each process
Operating System Concepts 8.38 Silberschatz, Galvin and Gagne ©2009
Paging Example – Contents of Pages
EAT = (1 + ε) α + (2 + ε)(1 – α) = 2 + ε – α
α % of the time, it requires a lookup in TLB + 1 memory access (i.e., the data)
The rest of the time (1-α % of the time), it requires a TLB lookup + 2 memory
accesses (i.e., the page table and then the data)
p1 p2 d
10 10 12
Where p1 is an index into the outer page table, and p2 is the
displacement within the page of the outer page table.
Hash ‘p’, then traverse chain to find ‘p’, then read its associative
value, ‘r’, and use that as the page number.
■ Shared code
● One copy of read-only (reentrant) code shared among
processes (i.e., text editors, compilers, window systems).
● Shared code must appear in same location in the logical
address space of all processes
4
1
3 2
4
■ Relocation.
● Dynamic
● By segment table
■ Sharing.
● Shared segments
● Same segment number
■ Allocation.
● First fit / best fit
● External fragmentation
■ Uses 6 segments:
● Kernel code
● Kernel data
● User mode