

















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!


















EECS 482
1
Review of processes
unit of concurrency
unit of data
Address space abstraction
Includes program code, stack, data segment
small size, shared between processes
process has its own memory, as large as the virtualaddress space
Illusions provided by address spaces
in different address spaces (i.e. different processes), yetremain logically distinct
amount of physical memory on the machine
another address space (actually controlled sharing)
1 process runs at a time (viz. one process occupies memory at
a time)
Always load process into the same spot in memory (and
reserve some space for the OS) fffff (high memory)
..
operating
system
. 80000 7ffff
..
user process
. 00000 (low memory)
Achieves address independence by always loading process into
same physical memory location
Problems with uni-programming?
EECS 482
2
Multi-programming: more than 1 process is in memory at a
time• need to support address translation• need to support protection
Must translate addresses issued by a process so they don’t con-
flict with addresses issued by other processes• static address translation: translate addresses before exe-
cution (translation remains constant during execution)
execution (translation may change during execution)
Is it possible to run two processes at the same time (both are in
memory) and provide address independence with onlystatic address translation?
Does this achieve the other address space abstractions? Achieving all the address space abstractions requires doing
some work on every memory reference
EECS 482
4
Load each process into contiguous regions of physical mem-
ory, prevent each process from accessing data outside itsregion if
(virtual address > bound) {kill
process (core dump)
}
else
{
physical address = virtual address + base }
Process has illusion of running on its own dedicated machine,
with memory [0, bound)
This is similar to linker-loader, but also protect processes from
each other.
As with all translation data, only kernel can change base and
bounds
During context switch, must change all translation data (base
and bounds registers)
What to do when address space grows?Low hardware cost (2 registers, adder, comparator), low over-
head (add and compare on each memory reference)
virtualmemory 0
bound
physicalmemory 0
physical memory size
base + bound
base
EECS 482
5
Peter M. Chen
Hard for a single address space to be larger than physical
memory
But sum of all address spaces can be larger than physical mem-
ory• swap an entire address space out to disk, swap address
space for new process in
Can’t share part of an address space between processes
External fragmentation
memory regions process 1 start:
KB
(phys.
mem.
0-
KB)
process 2 start:200 KB (phys. mem. 100-299 KB)process 3 start:300 KB (phys. mem. 300-599 KB)process 4 start:400 KB (phys. mem. 600-999 KB)process 3 exits
(frees
phys.
mem.
300-
KB)
process 5 start:100 KB (phys. mem. 300-399 KB)process 1 exits
(frees
phys.
mem.
0-
KB)
process 6 start:
KB
300 KB are
free
(400-
KB;
0-
KB),
but
not contiguous
between allocated regions. Can waste lots of memory.
Allocation strategies to minimize external fragmentation
isfy the request (least amount of wasted space)
can satisfy the request
(by copying them to another area)
virtualmemory
physicalmemory 0
data code code
data (P1)code
virtual address(process 1)
virtualmemorydata code^ code virtual address(process 2)
data (P2)
EECS 482
7
Segment: a region of contiguous memoryBase & bounds used a single segment. Let’s generalize this to
allow multiple segments, described by a table of base &bound pairs.
In segmentation, a virtual address takes the form:
(virtual segment #, offset)• could specify virtual segment # via the high bits of the
segment # address, or via a special register, or implicit to theinstruction opcode
base
bound
description
0
4000
700
code segment
1
0
500
data segment
2
unused
3
2000
1000
stack segment
virtualmemory 0 4ff
physicalmemory
2fff 2000
virtualmemory segment 1
fff^0
segment 3
stack
stack
data
4ff
data
virtualmemory 0 6ff
segment 0
code
code
46ff 4000
EECS 482
8
Note that not all virtual addresses are
valid
above 4ff
address space. Invalid means this virtual address is ille-gal for the process to access (and will cause a core dumpif accessed).
matically extend the address space (e.g. in Unix, access-ing invalid stack address right above stack bound willtrap to the kernel and automatically increase the stacksize).
Protection: different segments can have different protection
address space
What must be changed on a context switch?
Pros and cons
Can a single address space be larger than physical memory?How to make memory allocation easy and allow an address
space easily be larger than physical memory?
EECS 482
10
How does processor know that virtual page is not in physical
memory?
Like segments, pages can have different protections
Resident means a virtual page is in memory. It is NOT an error
for a program to access a non-resident page
Valid means a virtual page is not currently legal for the pro-
gram to access
Who makes a virtual page resident/non-resident?Who makes a virtual page valid/invalid?Why would a process want one of its virtual pages to be
invalid?
EECS 482
11
What happens if page size is small?What happens if page size is really big?Could we use a large page size but let other processes use the
leftover space in the page?
Page size is typically a compromise, e.g. 4 KB or 8 KB
Fixed vs. variable size partitions
Too small a size leads to a large translation table, whiletoo large a size leads to internal fragmentation
hard to pack these variable size partitions into physicalmemory (leading to external fragmentation)
What happens to paging if the virtual address space is sparse
(most of the address space is invalid, with scattered validregions)?
Paging pros and cons
EECS 482
13
This is a two-level tree How does this allow the translation data to take less space?
How to use share memory when using multi-level page tables?What must be changed on a context switch?Another alternative: use segments in place of the level-1 page
table. This uses pages on level 2 (i.e. break each segmentinto pages)
level
1
0
1
3
level
2
page
table
page
tables
virtualaddressbits 21-
12
physicalpage #
0
10
1
15
2
20
3
2
virtualaddressbits 21-
12
physicalpage #
0
30
1
4
2
8
3
3
NULL
2 NULL
EECS 482
14
Pros and cons
Translation when using paging involves 1 or more additional
memory references. How to speed up the translation pro-cess?
TLB caches translation from virtual page # to physical page #
(TLB conceptually caches the entire page table entry, e.g.dirty bit, reference bit, protection)
If TLB contains the entry you’re looking for, can skip all the
translation steps above
On TLB miss, figure out the translation by getting the user’s
page table entry, store in the TLB, then restart the instruc-tion.
Does this change what happens on a context switch?
EECS 482
16
Most MMUs maintain “referenced” bit for each resident page,
which is set automatically when the page is referenced.Reference bit can be cleared by OS.
Why is hardware support needed to maintain the reference bit?How can you identify an “old” page?Try to do this work incrementally (rather than all at once)
To find a page to evict:
time (since last sweep), so this is your victim.
last sweep. What to do?
Can this infinite loop? What if it finds all pages referenced
since the last sweep?
New pages are put behind the clock hand, with reference=
EECS 482
17
What to do with page when it’s evicted? Why not write pages to disk on every store?
While evicted page is being written to disk, the page being
brought into memory must wait• may be able to reduce total work by giving preference to
dirty pages (e.g. could evict clean pages before dirtypages)
back dirty pages
EECS 482
19
Who sets up the data used by translator?Kernel is allowed to modify any memory (including translation
tables)
How can kernel refer to translation table? Translation table is
not really in any process’s address space. It is often inphysical (i.e. untranslated) memory.• kernel can issue untranslated addresses (i.e. bypass the
translator)
address space
How does machine know that the kernel is running?
and to allow kernel to execute privileged instructions(e.g. halt, I/O)
user)
How have we handled the problem of protection so far?
who can modify data used by translator?
processor know if kernel is running?
is allowed to modify mode bit?
EECS 482
20
What causes a switch from a user process into the kernel?
Sequence of events that take place when C++ program calls
cin• C++ code calls cin• cin is a standard library function that calls read()• read() is a standard library function that executes the
assembly-language instruction “syscall”, with parame-ters (SYS_read, file number, size) in registers or on thestack
-^
when processor executes “syscall” instruction, it trapsto the kernel at a pre-specified location
nel’s read() function
Details of what happens when trapping to kernel
changing some data used by the translator)
Does this look familiar?How does processor know exception handler’s address?