120 likes | 139 Views
The Abstraction: Address Spaces. Deoksang Kim(dskim@dcslab.snu.ac.kr) School of Computer Science and Engineering Seoul National University. Outline. Early Systems Multiprogramming Time Sharing Address Space Virtual Memory Virtualizing memory goals Summary. Early Systems. 0KB.
E N D
The Abstraction: Address Spaces Deoksang Kim(dskim@dcslab.snu.ac.kr) School of Computer Science and Engineering Seoul National University
Outline Early Systems Multiprogramming Time Sharing Address Space Virtual Memory Virtualizing memory goals Summary
Early Systems 0KB Operating System (code, data, etc.) 64KB Current Program (code, data, etc.) max Physical Memory • Building computer systems was easy • Users did not expect much • Early machines did not provide much of an abstraction to users • Physical memory • Operating System • A set of routines • One running program
Multiprogramming 0KB Operating System 64KB Process A Process B I/O operation max Physical Memory Disk Machines were expensive so people began to share machines more effectively Increase the effectiveutilizationof the CPU
Time Sharing • Limitations of batch computing • It is difficult to debug batch systems • If some job takes too much time (i.e. if error occurs in job then other jobs will wait for unknown time) • The notion of interactivitybecame important • Many users might be concurrently using a machine, each waiting for a timely response from their currently-executing tasks • Implementation strategy • Run one process for a short while, giving it full access to all memory
Time Sharing Example 1 0KB Operating System 64KB Process B Process A Time’s up Too Slow max Physical Memory Disk
Time Sharing Example 2 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 Physical Memory • Leave processes in memory while switching between processes • It allows the OS to implement time sharing efficiently • New demands were placed on the operating system • protection
Address Space • Users require the OS to create an easy-to-use abstraction of physical memory • We call this abstraction the address space, and it is the running program’s view of memory in the system • The address space of a process contains all of the memory state of the running program • Code • It has to live in memory somewhere, and thus it is in the address space • Stack • To keep track of where program is in the function call chain as well as allocate local variables and pass parameters and return values to and from routines • Heap • It is used for dynamically-allocated and user-managed memory (e.g. malloc() in C, new in C++, JAVA) • Data, BSS, and etc.
Address Space 0KB Program Code 1KB Heap 2KB (free) 15KB • When multiple threads co-exist in an address space, no nice way to divide the address space like this works anymore Stack 16KB Address Space • Code • It is static, so we can place it at the top of the address space and know that it won’t need any more space as the program runs • Heap & Stack • We place them like this because each wishes to be able to grow, and by putting them at opposite ends of the address space, we can allow such growth: they just have to grow in opposite directions
Virtual memory 0KB 0KB Operating System (code, data, etc.) Program Code 64KB (free) Heap 128KB Process C (code, data, etc.) Key to virtualization of memory The OS will have to make sure physical address (free) 192KB Process B (code, data, etc.) 256KB (free) 320KB Process A (code, data, etc.) 384KB (free) Stack 448KB (free) 512KB Address Space of Process A Physical Memory • The address space is abstractionthat the OS is providing to the running program • When the OS does this, we say the OS is virtualizing memory • The running program thinks it is loaded into memory at a particular address and has a potentially very large address space
Virtualizing memory goals • Transparency • The OS should implement virtual memory in a way that is invisible to the running program • The program should not be aware of the fact that memory is virtualized • The program behaves as if it has its own private physical memory • The OS and hardware do all the work to multiplex memory • Efficiency • The OS should strive to make the virtualization as efficient as possible, in terms of both time and space • In implementing time-efficient virtualization, the OS will have to rely on hardware support, including hardware features such as TLBs • Protection • The OS should make sure to protect processes from one another as well as the OS itself from processes • Protection enables us to deliver the property of isolation among processes
Summary • We have seen the introduction of a virtual memory • VM system is responsible for providing the illusion of a large, sparse, private address space to programs • The OS will take each of these virtual memory references and turn them into physical address • The OS will do this for many processes at once, making sure to protect programs from one another, as well as protect the OS