Virtualization of Resources

Anything required for the execution of a program is called a resource. The processor, memory, displays, mice, keyboards, disk storage, printers, and networks are all examples of resources. The primary functions of an operating system are management of resources and virtualization of resources. Part of the management is implicit in the virtualization.

This web presentation first takes a more careful look at the meaning of virtualization. Then it examines how the concept applies to various resources. Finally, it examines two principal mechanisms used in virtualization and how these mechanisms are used for various resources.

The terms "logical" and "physical" appear often in descriptions of operating systems. These terms refer to different points of view regarding a system resource. The physical view refers to the actual physical state of affairs. The logical view is the view of the application programmer. For resources other than the processor and memory, the logical view is reflected in the operating system application program interface (API) or application binary interface (ABI).

Virtualization refers to process involved in converting a physical view to a logical view. Virtualization serves two important purposes:

The resources managed by an operating system are virtualized in different ways. This section describes the virtual points of view for some of the more important resources.

Physically, a processor can only execute one program at a time, but most operating systems support the appearance of executing several programs (or multiple instances of the same program) simultaneously. Each instance of program execution is called a process. Though several processes may be executing, their logical view is that they have the processor all to themselves.

Memory

When several processes are executing at the same time, the code and data that they are using must be kept in memory to avoid the overhead of transfers from another storage device such as a disk. Consider two processes executing the same program. For example, suppose you have two word processor windows open, each working on a different file. At the machine language level, a particular variable in the two processes appears to to have the same address in both processes. That is, you have two variables with the same logical address. But in fact, the two variables must be able to have different values so they must refer to two different physical addresses.

Physically, most computers have only one display device. However, most operating systems allow several processes to access the display simultaneously. Each uses a logical display called a window.

When a process does graphics on a display device, it must specify coordinates for points, line endpoints, etc. If two processes are using the display at the same time, the coordinates that they provide do not have to be physical screen coordinates. Instead, each process specifies coordinates relative to its own window. This allows the processes to execute without being aware of other processes that are using the display.

Physically, most computers have a single mouse and a single keyboard. Logically, each process has its own mouse and keyboard. A GUI application program just uses event handlers to respond to what appears to be its own mouse and keyboard.

Some processes, in response to mouse events, need to use the coordinates of the mouse. As with display coordinates, the mouse coordinates are relative to the window for the process.

Physically, data on a disk is organized into blocks, typically 512 bytes each. For application programs, there are two logical views.

First, the disk data is organized into files and directories. The operating system API provides functions for manipulating these files and directories as units, disregarding their contents. For example, a file may be moved from one directory to another.

Second, programs frequently deal with files as sequential streams of data. That is, the file data is dealt with using the same functions that would be used for truly sequential streams of data, such as the input from a keyboard.

Physically, printers can only print one thing at a time. Logically, several processes can print data at the same time. The processes do not need to wait for printing from other processes to complete.

The elimination of the wait for output is part of the logical view of most output devices. Processes usually have no need to wait for an output operation to complete.

Many computer systems have a single physical network connection. However, several processes may need network connections simultaneously. For example, a user may be using one process and network connection to download new software, and another process and network connection to send mail. Each process has its own logical network connection.

There are two general mechanisms for giving the appearance of multiple instances of a resource where there is physically only one resource. This section describes these two mechanisms, time sharing and partitioning, with some high-level details for various resources.

Processors, mice, keyboards, printers and network connections are time shared between processes. The important issue for time-shared resources is how the physical resource is switched from one process to another. This issue is dealt with in different ways, depending on the resource.

Processors

The appearance that several processes are running simultaneously on a single processor is one of the earliest virtualizations used in operating systems. To accomplish this, an operating system switches rapidly between processes. For most recent operating systems a process switch is done either when a process needs to wait for input (non-preemptive process switches), or when its alloted time slot has expired (preemptive process switches). Most computer systems today include a timer that sends periodic interrupts to the processor. Whenever an interrupt occurs, the operating system takes over. For timer interrupts, the operating system just stops executing the current process and starts up another.

In order to make this work, an operating system needs to store a snapshot of the state of the current process and restore the state for the next process to execute. This is called dispatching. The stored state information is called a process control block.

The window management system uses the concept of focus to determine which process gets input from the mouse and the keyboard. Some window managers change focus when the user clicks a mouse button while the cursor is in a window. Others change focus whenever the cursor is moved into a window. Some window managers can be configured to work either way.

An operating system uses spooling to share printer time between processes. Spool is an acronym for simultaneous peripheral operation on-line. It involves creating disk files for the printer output of each process. Processes can add data to be printed incrementally. The added data just gets added to the disk file. Once a process signals the end of the print data, printing can begin, provided the printer is not busy. If the printer is busy then the process does not need to wait. The print spooler has all of the data that it needs in the spool file. It just schedules the print job for later execution.

Networks are often used to establish a continuous communication connection between processes on different machines. In reality, long messages are broken up into short packets of data. If a single physical network connection is used by two different processes at the same time, their packets may be interleaved. To ensure that each packet is delivered to the correct process, packets include addresses in addition to their data contents.

Part of a network address identifies a particular machine. This is called the internet address of the machine. An operating system must manage a different kind of address - the part that identifies a particular process. A process that wants to establish a network connection must first request a port. The number assigned to the port serves to identify a particular process in network communication.

Memory, displays, and disks are partitioned resources. These resources are partitioned into "pieces" that are assigned to individual processes. When a resource is partitioned, there is usually some concept of "location" of data handled by the resource. This necessitates a translation mechanism so that different processes do not have to be aware of the physical location of their logical resources. The important issue for partitioned resources is how this translation is done. This issue is dealt with in different ways, depending on the resource.

Paged virtual memory is the most common memory management scheme in use today. Physical memory is divided up into fixed size blocks (a few KB) called pages. Tables in memory, called page tables, are used to map logical pages into physical pages. The operating system maintains a page table for each process. This allows two different processes to have different physical addresses even if the processes are running the same program and using the same logical address.

A paged virtual memory system also allows two or more processes to share memory. To do this, the operating system sets up page tables for the processes so that each contains an entry that refers to the same physical page. The logical addresses need not be the same in different processes.

This is a powerful mechanism. One important use is sharing of code from high-level language libraries. All processes from C coded programs that use printf() are running code in the same physical memory. Programs written in different languages may also be using the same subprograms.

A window is the logical display used by a process. The window management system maintains a coordinate transformation matrix for each window. This matrix is used to translate the logical coordinates into physical screen coordinates.

The window management system is unique in that it allows overlap of the portions of its physical resource that are allocated to different processes. This is made possible by ordering process windows from front to back, hiding part of a window if another is in front of it. The window management system provides mechanisms that allow a user to change the front-to-back ordering.

The file management system is one of the most complex subsystems of an operating system. This is due to the great difference between the logical and physical views. The file management system must build files using disk blocks as its basic component. Most modern operating systems also support a hierarchical directory structure for organizing files. Finally, the operating system provides sequential stream access to file contents. The blocks are not even visible to the application programmer.

Supporting a hierarchical file system is usually just a matter of adding a special type of file for directories. Directory files are essentially just tables for translating file names into disk locations.

Efficient use of disk space for files that can change in size requires non-contiguous storage of file data. That is, data for a single file may be scattered across the disk rather than being physically grouped together. To accomplish this, file systems set up additional structure for recovering file data in the intended sequential order. These additional structures may be grouped together into a single table called a file allocation table, or there may be a separate structure for each file, as in UNIX inodes.