OSTEP 13 Address Spacex
Download
Report
Transcript OSTEP 13 Address Spacex
Chapter 13
Address Space
Chien-Chung Shen
CIS/UD
[email protected]
Lack of Memory Abstraction
• Earlier systems did not provide
much of an abstraction of
(physical) memory
0KB
Operating System
(code, data, etc.)
– OS == library that sat in memory 64KB
starting from physical address 0
– One running program (process) that
sat in memory starting from physical
address 64K
max
Current Program
(code, data, etc.)
Multiprogramming
• Multiple concurrent processes
– increase utilization of CPU
– time sharing & interactive
• Expensive to save/restore contents
in memory when context switching
so leave processes in memory and
switch between them
• One critical issue
– protection
0KB
Operating System
(code, data, etc.)
64KB
(free)
128KB
Process C
(code, data, etc.)
192KB
Process B
(code, data, etc.)
256KB
(free)
320KB
Process A
(code, data, etc.)
384KB
(free)
448KB
(free)
512KB
Address Space
• Abstraction of physical memory
– Running program’s view of physical
memory: contain all the memory state of
running program
– The process is NOT in memory at
physical addresses 0 through 16KB
– Virtual address vs. physical address
• Address spaces of threads ?
• How to virtualize memory ?
– How can the OS build this abstraction of
a private, potentially large address space
for multiple running processes (all
sharing memory) on top of a single,
physical memory?
0KB
the code segment:
where instructions live
Program Code
1KB
the heap segment:
contains malloc’d data
dynamic data structures
(it grows downward)
Heap
2KB
(free)
(it grows upward)
the stack segment:
contains local variables
arguments to routines,
return values, etc.
15KB
Stack
16KB
0KB
Operating System
(code, data, etc.)
64KB
(free)
128KB
Process C
(code, data, etc.)
192KB
Process B
(code, data, etc.)
256KB
(free)
320KB
Process A
(code, data, etc.)
384KB
(free)
448KB
(free)
512KB
Principle of Isolation
• Isolation is a key in building reliable systems
• If two entities are properly isolated from each other,
this implies that one can fail without affecting the
other
• OS strives to isolate processes from each other and
in this way prevent one from harming the other
• By using memory isolation, OS further ensures that
running programs cannot affect the operation of the
underlying OS
• By walling off pieces of the OS from other pieces of
the OS, microkernel may provide greater reliability
than monolithic kernel design
Goals of Virtualized Memory
• Transparency
– virtualized memory is implemented in a way that is invisible
to (hard to be noticed by) the running program
– program behaves as if it has its own private physical memory
– OS and hardware do all the work to multiplex memory among
many different processes, and hence implement the illusion
• Efficiency
– time (not much slower) and space (not much more space)
• Protection
– protect process from one another and the OS itself from
processes
– enables isolation among processes; each process should be
running in its own isolated cocoon, safe from the ravages of
other faulty or event malicious processes
Virtualized Memory
•
•
•
•
•
Any address you can see as a programmer of a user-level program is
a virtual address
Only the OS, through its tricky techniques of virtualizing memory,
that knows where in the physical memory of the machine these
instructions and data values lie
If you print out an address in a program, it’s a virtual one, an illusion
of how things are laid out in memory; only the OS (and the
hardware) knows the real truth
Virtualized memory is responsible for providing the illusion of a
large, sparse, private address space to programs, which hold all of
their instructions and data therein
OS, with hardware help, will take each of these virtual memory
references, and turn them into physical addresses which can be
presented to the physical memory to fetch the desired information
• OS will do this for many processes at once, making sure to
protect programs from one another, as well as protect the OS