






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







1
^
Background
Swapping
Contiguous Memory Allocation
Paging
Segmentation
Segmented Paging
^
Memory is a large array of bytes^ l^
memory and registers are only storage CPU can access directly l both instructions and data are fetched from memory l memory unit just sees a stream on memory addresses
Accessing memory is slow (why?)^ l^
register access in one CPU clock (or less) l cache
sits between main memory and CPU registers
Protection of memory required to ensure correctoperation^ l^
isolate processes from one another and from the OS
3
^
Protect OS from user processesand processes from each other^ l^
give each process separate space l determine legal range of addressesfor each process
A pair of
base
and
limit
registers define the processaddress space.
CPU compares each addressgenerated by the process withthe base and limit registers.
^
Address binding of instructions and data to memoryaddresses can happen at three different stages^ l^
compile time
: If memory location known a priori,
absolute code
can be generated^ ^
must recompile code if starting location changes l^ load time
: Must generate
relocatable code
if memory location is
not known at compile time^ ^
code can be placed anywhere in memory l^ execution time
: Binding delayed until run time if the process can
be moved during its execution from one memory segment toanother^ ^
need hardware support for address maps (e.g., base and limitregisters)
5
^
^
The concept of a logical address space that is bound to aseparate
physical address space
is central to proper
memory management^ l^
logical address
virtual address l physical address
Logical and physical addresses are the same in compile-time and load-time address-binding schemes.
Logical and physical addresses differ in execution-timeaddress-binding scheme.
7
^
Hardware device that mapsvirtual to physical address.
Simple MMU scheme^ l^
start each process's logicaladdress from 0 l base memory address for eachprocess stored in
relocation
register l max. process address stored in limit register l relocation register added toevery logical address l logical: 0 –
max
correspond to
physical: R+0 – R+limit
^
Static
loading l^ entire program in memory before program starts l^ program size limited by size of memory
Dynamic loading^ l^
routine is not loaded until it is called l better memory-space utilization; unused routine is never loaded l useful when large amounts of code are needed to handleinfrequently occurring cases l no special support from the operating system is requiredimplemented through program design
13
^
Relocation and limit registers used to protection^ l^
of user processes from each other, and l operating system from the user processes
Hardware checks^ l^
base register contains value of smallest physical address l each logical address must be less than the limit register l MMU maps logical address
dynamically
^
Multiple-partition method^ l^
hole
b) free partitions (hole)
OS process 5process 8process 2
OS process 5 process 2
OS process 5 process 2
OS process 5process 9 process 2
process 9
process 10
15
^
Given
a
list
of
variable-sized
holes,
how
to
allocate
memory for a new arriving process of some size,
n
Memory allocation schemes^ l^
First-fit
: Allocate the
first
hole that is big enough
l^ Best-fit
: Allocate the
smallest
hole that is big enough; must
search entire list, unless ordered by size^ ^
produces the smallest leftover hole l^ Worst-fit
: Allocate the
largest
hole; must also search entire list
^ produces the largest leftover hole
Performance^ l^
first-fit and best-fit better than worst-fit in terms of performanceand storage requirement l first-fit generally the fastest
^
External Fragmentation
satisfy a request, but it is not contiguous
50-percent rule^ l^
given N allocated blocks, 0.5N blocks will be lost to fragmentation
Solutions to external fragmentation^ l^
compaction^ ^
move allocated blocks to place all
holes
together
^ compaction is possible
only
if relocation is dynamic
l^ permit non-contiguous allocation of logical address space
Internal Fragmentation^ l^
occurs with fixed sized blocks used to reduce cost of managingextremely small holes l size of last block may be slightly larger than requested memory l what is the greatest memory loss due to internal fragmentation?
17
^
Solution to external fragmentation and compaction^ l^
logical address space of a process can be noncontiguous l commonly used in most OS l frequently depend on hardware support
Scheme^ l^
divide physical memory into fixed-sized blocks called
frames
^ size is generally power of 2, between 512 bytes and 8,192 bytes l^ divide logical memory into blocks of same size called
pages
l^ OS keeps track of all free frames l^ a program of size
n^ pages, needs
n^ free frames before loading
l^ needs a
page table
to translate logical to physical addresses
Problem of internal fragmentation still exists
^
Hardware defines the page size (and frame size).
Page size,
d , determines the number of bits required to
specify the page offset,
n.
l^
How? l^ d = 2
n
The remaining bits in the logical address specify thepage number,
p.
For logical address space, 2
m, and page size 2
n,
page number
page offset
p^
d
m - n
n
19
^
^
25
^
^
Memory protection implemented by associating protectionbit with each frame
Valid-invalid
bit attached to each entry in the page table:
l^ “valid” indicates that the associated page is in the process’ logicaladdress space, and is thus a legal page l^ “invalid” indicates that the page is not in the process’ logicaladdress space
27
^
Scheme^ l^
14 bit address space l Program usesaddresses 0 – 10468 l Page size of 2kb l Accessing addresseson pages 6 and 7 isinvalid^ ^
segmentation fault
Problems^ l^
addresses 10469 –12287 are still valid l page table stillcontains all rows l use page table lengthregister
^
Shared code^ l^
Paging allows the possibility ofeasily sharing code l one copy of read-only (reentrant)code shared among processes(i.e., text editors, compilers,window systems) l each process has private data l significant reduction in memoryusage possible
Example^ l^
3 code pages shared l each process has private data
29
^
Hierarchical Paging
Hashed Page Tables
Inverted Page Tables
^
Sometimes necessary to divide page table into pieces^ l^
to support a large logical address space (
32 to 2
l^ example: for page size of 4kb, page table has 2
20 entries
l^ contiguous allocation of big page tables not feasible
Two-level page table (paged page-table)^ l^
further divide the page number field l p1 –
index into outer page table l^ p2 –
displacement within outer page table
page number
page offset
p i^
p^2
d
^
^
31
^
^
37
^
^
Memory-management scheme that supports user view ofmemory^ l^
a program is a collection of segments
(^13)
(^24)
1 4 2 3
user space
physical memory space
39
^
Logical address consists of a two tuple:
<segment-number, offset>
Segment table
addresses; each table entry has^ l^
base
Segment-table base register (STBR)
points to the
segment table’s location in memory
Segment-table length register (STLR)
indicates number
of segments used by a program;
segment number
s^
is legal if
s^ <^ STLR
^
41
^
^
Supports both segmentation and segmentation withpaging
CPU generates logical address^ l^
given to segmentation unit^ ^
which produces linear addresses l^ linear address given to paging unit
^ which generates physical address in main memory ^ paging units form equivalent of MMU
43
^
32-bit architecture
Max. number of segments – 16K^ l^
8k segments in local descriptor table (LDT) l 8k segments in global descriptor table (GDT)
Max. size of segment – 4GB
Each segment descriptor is 8 bytes^ l^
contains segment base and limit
Each logical address is 48 bits^ l^
16 bit segment selector, 32 bit offset
16 bit segment selector contains^ l^
13 bit segment number, 1 bit table identifier, 2 bits of protection
Maps 48 bit logical address to 32 bit linear address
^