AL3452 OS Unit-5
AL3452 OS Unit-5
Virtual Machines
• The main idea is that a VMM (Virtual Machine Monitor) creates the illusion of multiple
(virtual) machines on the same physical hardware
• Type 2 hypervisors that may make use of all the wonderful services and abstractions
offered by an underlying operating system
1. Safety: the hypervisor should have full control of the virtualized resources
2. Fidelity: the behavior of a program on a virtual machine should be identical to that of the
same program running on bare hardware
3. Efficiency: much of the code in the virtual machine should run without intervention by
the hypervisor
• A failure in one virtual machine does not bring down any others
• Different servers can run on different virtual machines, thus maintaining the partial-
failure model that a multicomputer has, but at a lower cost and with easier maintainability
• Checkpointing and migrating virtual machines (e.g., for load balancing across multiple
servers) is much easier than migrating processes running on a normal operating system
Example: Cloud
The key idea of a cloud is straightforward: outsource your computation or storage needs
to a well-managed data center run by a company specializing in this and staffed by
experts in the area
History
• IBM VM370 divided a mainframe into multiple virtual machines, each running its own
operating system.
• A major difficulty with the VM approach involved disk systems. Suppose that the
physical machine had three disk drives but wanted to support seven virtual machines.
• Clearly, it could not allocate a disk drive to each virtual machine. The solution was to
provide virtual disks— termed minidisks in IBM’s VM operating system.
• The minidisks are identical to the system’s hard disks in all respects except size.
• The system implemented each minidisk by allocating as many tracks on the physical
disks as the minidisk needed.
• Once the virtual machines were created, users could run any of the operating systems or
software packages that were available on the underlying machine.
• For the IBM VM system, a user normally ran CMS—a single-user interactive operating
system.
• For many years after IBM introduced this technology, virtualization remained in its
domain.
2. Programs running within that environment show only minor performance decreases.
• These requirements of fidelity, performance, and safety still guide virtualization efforts
today.
• By the late 1990s, Intel 80x86 CPUs had become common, fast, and rich in features.
• Both Xen and VMware created technologies, still used today, to allow guest operating
systems to run on the 80x86.
• Since that time, virtualization has expanded to include all common CPUs, many
commercial and open-source tools, and many operating systems.
• Possible guest operating systems include many versions of Windows, Linux, Solaris, and
BSD, including even MS-DOS and IBM OS/2.
Building Blocks
1. Trap and Emulate
• Problem with VMM is that guest OS expects to have unrestricted access to hardware,
runs privileged instructions, unlike user processes. But one guest cannot access, must be
isolated from other guests.
• All CPUs have multiple privilege levels. There is ring 0,1,2,3 in x86 CPUs. Normally,
user process in ring 3 and OS in ring 0. Privileged instructions only run in ring 0. So,
guest OS must be protected from guest apps. But not fully privileged like host OS/VMM.
It is in ring 1.
• Trap and emulate VMM: Guest OS runs at lower privilege level than VMM, traps to VMM
for privileged operation.
• When the kernel in the guests attempt to execute a privileged instruction, that is an error
because the system is in user mode and causes a trap to the VMM in the real machine. The
VMM gains control and executes the action that attempted by the guest kernel on the part
of the guest. It then returns control to the virtual machine. This is called the trap and
emulate method.
• All non-privileged instructions run natively on the hardware, providing the same
performance for guests as native applications. Privileged instructions create extra
overhead, however, causing the guest to run more slowly than it would natively.
• Drawback
o Some x86 instructions which change hardware state , run in both privileged
and unprivileged modes
2. Binary Translation
•
• Static binary translation means using a processor to translate an image from an
architecture to another before execution
• The guest OS system were supposed to run on level 0 but since virtual layer occupies that
level, it moves guest OS execution at privilege level 1 and leaves user applications at
level 3
• The non virtualizable kernel code of the guest OS is translated by virtual layer into new
sequences of instructions that have intended effect on virtual hardware
• In hardware assisted virtualization the virtual layer sits in a new root mode privilege level
under level 0
• Guest OS privileged and sensitive calls are set to auto trap to the hypervisor while user
request are executed directly to the CPU for high performance
• Type 0 hypervisors have existed for many years under many names, including
“partitions” and “domains”.
• They are a hardware feature, and that brings its own positives and negatives.
• The VMM itself is encoded in the firmware and loaded at boot time. In turn, it loads the
guest images to run in each partition.
• The feature set of a type 0 hypervisor tends to be smaller than those of the other types
because it is implemented in hardware.
• For example, a system might be split into four virtual systems, each with dedicated
CPUs, memory, and I/O devices.
• Each guest believes that it has dedicated hardware because it does, simplifying many
implementation details.
Type 1 Hypervisor
• Type 1 hypervisors are commonly found in company data centers and are in a sense
becoming “the data-center operating system.”
• They are special-purpose operating systems that run natively on the hardware, but rather
than providing system calls and other interfaces for running programs, they create, run,
and manage guest operating systems.
• In addition to running on standard hardware, they can run on type 0 hypervisors, but not
on other type 1 hypervisors.
• Whatever the platform, guests generally do not know they are running on anything but
the native hardware.
• Where the host CPU allows, they use multiple modes to give guest operating systems
their own control and improved performance.
• They implement device drivers for the hardware they run on, because no other
component could do so.
• Because they are operating systems, they must also provide CPU scheduling, memory
management, I/O management, protection, and even security.
• Frequently, they provide APIs, but those APIs support applications in guests or external
applications that supply features like backups, monitoring, and security
Type 2 Hypervisor
• This type of VMM is simply another process run and managed by the host,.
• The operating system running on top of the hypervisor in both cases is called the guest
operating system.
• For a type 2 hypervisor, the operating system running on the hardware is called the host
operating system.
• Type 2 hypervisors, sometimes referred to as hosted hypervisors, depend for much of their
functionality on a host operating system such as Windows, Linux, or OS X.
• When it starts for the first time, it acts like a newly booted computer and expects to find a
DVD, USB drive, or CD-ROM containing an operating system in the drive. This time,
however, the drive could be a virtual device.
• For instance, it is possible to store the image as an ISO file on the hard drive of the host and
have the hypervisor pretend it is reading from a proper DVD drive. It then installs the
operating system to its virtual disk (again really just a Windows, Linux, or OS X file) by
running the installation program found on the DVD.
• Once the guest operating system is installed on the virtual disk, it can be booted and run.
• The various categories of virtualization are summarized in the table below for both type 1
and type 2 hypervisors. For each combination of hypervisor and kind of virtualization, some
examples are given.
Paravirtualization
• It is quite different from full virtualization, because it never even aims to present a
virtual machine that looks just like the actual underlying hardware
• In paravirtualization, the virtual machine does not necessarily simulate hardware but
instead offers a special API that can only be used by modifying the guest OS.
• The system call to hypervisor is called hypercall.
Programming-Environment Virtualization
• For example, Oracle’s Java has many features that depend on its running in the Java
virtual machine (JVM), including specific methods for security and memory
management.
Emulation
• This method works relatively efficiently because the applications were compiled for the
same instruction set as the target system uses.
• Emulation is useful when the host system has one system architecture and the guest
system was compiled for a different architecture.
• Emulation can increase the life of programs and allow us to explore old architectures
without having an actual old machine.
Application Containment
• If the applications are all compiled for the same operating system, then we do not need complete
virtualization to provide these features. We can instead use application containment.
• Consider one example of application containment. Starting with version 10, Oracle Solaris has
included containers, or zones, that create a virtual layer between the operating system and the
applications. In this system, only one kernel is installed, and the hardware is not virtualized.
Rather, the operating system and its devices are virtualized, providing processes within a zone
with the impression that they are the only processes on the system. One or more containers
can be created, and each can have its own applications, network stacks, network address and
ports, user accounts, and so on. CPU and memory resources can be divided among the zones
and the system-wide processes. Each zone in fact can run its own scheduler to optimize the
performance of its applications on the allotted resources. Figure shows a Solaris 10 system
with two containers and the standard “global” user space.
Virtualization and Operating system components
1. CPU Scheduling
2. Memory management
3. IO management
4. Storage management
5. Live migration
CPU Scheduling
• The VMM has number of physical CPUs available and a number of threads to run on
those CPUs and are called VMM threads or guest threads.
Memory management
• Each virtual machine consumes memory based on its configured size and additional
overhead memory for virtualization
• Since hypervisor manages page sharing, the virtual machine OS are unaware of what is
happening in the physical system
• Memory ballooning allows the total RAM required by guest VMs to exceed the amount
of physical RAM available on the host.
• When the host system runs low on physical RAM resources, memory ballooning
allocates it selectively to VMs.
IO management
• With virtualization, each guest needs atleast one IP address for communication.
• So, server running a VMM may have dozens of addresses and the VMM acts as a virtual
switch to route the network packets to the addressed guests.
Storage management
• Both boot block and general data access need to be provided by VMM
• In type 1 hypervisor, storage guest root disk and configuration information within file
system provided by VMM as disk image
• Guest OS sometimes need more disk space than available in their root disk image.
• VMM provide a mechanism to capture a physical system as it is currently configured and
convert it to a guest that the VMM can manage and run
Live migration
• Live migration provides the ability to move a virtual machine between host with no
interruption to service
1. The source VMM establishes a connection with the target VMM and confirms that it is
allowed to send a guest.
2. The target creates a new guest by creating a new VCPU, new nested page table, and other state
storage.
4. The source sends all read-write pages to the target, marking them as clean.
5. The source repeats step 4, as during that step some pages were probably modified by the guest
and are now dirty. These pages need to be sent again and marked again as clean.
6. When the cycle of steps 4 and 5 becomes very short, the source VMM freezes the guest, sends
the VCPU’s final state, sends other state details, sends the final dirty pages, and tells the target to
start running the guest. Once the target acknowledges that the guest is running, the source
terminates the guest.
MOBILE OS –ANDROID
• The Android operating system was designed by the Open Handset Alliance (led primarily
by Google) and was developed for Android smartphones and tablet computers
• Android runs on a variety of mobile platforms and is open-sourced, partly explaining its
rapid rise in popularity
• It is based on the Linux kernel—Android introduces only a few new concepts to the
Linux kernel itself, using most of the Linux facilities you are already familiar with
(processes, user IDs, virtual memory, file systems, scheduling, etc.) in sometimes very
different ways than they were originally intended
• A large amount of the Android operating system is written in a high-level language, the
Java programming language.
• The kernel and a large number of low level libraries are written in C and C++
• Android is an unusual operating system in the way it combines open-source code with
closed-source third-party applications
• The open-source part of Android is called the Android Open-Source Project (AOSP)
and is completely open and free to be used and modified by anyone
• When it comes to offering compatible apps, the most important service is Google Play
– The first and most important is requiring that any device shipping with it must be
a compatible Android device as per the CDD (Compatibility Definition
Document)
Google Play must know about any features of a device that an application requires so the
application is not made available on devices that lack those features
Design Goals
A number of key design goals for the Android platform evolved during its development:
2. Strongly support proprietary third-party applications with a robust and stable API
3. Allow all third-party applications, including those from Google, to compete on a level
playing field
4. Provide an application security model in which users do not have to deeply trust third-
party applications
5. Support typical mobile user interaction: spending short amounts of time in many apps
6. Manage application processes for users, simplifying the user experience around
applications so that users do not have to worry about closing applications when done with
them
Android Architecture
• Android is built on top of the standard Linux kernel, with only a few significant
extensions to the kernel itself
• As in a traditional Linux system, Android’s first user-space process is init, which is the
root of all other processes
• First is the init process, which spawns a number of low-level daemon processes
• One of these is zygote, which is the root of the higher-level Java language processes
• The first process zygote always starts is called system server, which contains all of the
core operating system services
• Key parts of this are the power manager, package manager, window manager, and
activity manager
• Applications interact with the operating system through calls to libraries provided by it,
which together compose the Android framework
• Figure below shows the typical design for Android framework APIs that interact with
system services, in this case the package manager
Linux Extensions
1. Wake Locks
An idle CPU, however, is not the same thing as true sleep. For example:
1. On many chipsets the idle state uses significantly more power than a true sleep state
2. An idle CPU can wake up at any moment if some work happens to become available,
even if that work is not important
3. Just having the CPU idle does not tell you that you can turn off other hardware that
would not be needed in a true sleep
Wake locks on Android allow the system to go in to a deeper sleep mode, without being tied to
an explicit user action like turning the screen off
2. Out-Of-Memory Killer
• Linux includes an ‘‘out-of-memory killer’’ that attempts to recover when memory is
extremely low
• With paging and swap, it is rare for applications themselves to see out-of-memory
failures
Dalvik
• Dalvik implements the Java language environment on Android that is responsible for
running applications as well as most of its system code
Binder IPC
1. Email client
2. SMS program
3. Calendar
4. Maps
5. Browser
Application framework
• Developers have full access to same framework APIs used by core applications
• Content providers enable applications to access data from other applications or to share
their own data
• A notification manager enables all applications to display custom alerts in the status bar
• Surface Manager: Manages access to the display subsystem and seamlessly composites
2D and 3D graphic layers from multiple applications
• LibWebcore: A modern web browser engine which powers both the Android browser and
an embeddable web view
• Android uses a file system that's similar to disk-based file system on other platforms
• All Android devices have two file storage areas: Internal and External storage
• The superblock is the key for maintaining file system. It is an 8KB block of disk space
that maintains current status of the file system
ODEX File
• In Android file system, applications come in packages with the extension .apk
• These application packages or APKs contain certain .odex files whose supposed function
is to save space
• odex files are actually collections of parts of an application that are optimized before
booting
DEODEX
• Deodexing is basically repackaging of these APKs in a certain way, such that they are
reassembled into classes.dex files
• All pieces of an application package are put together back in one place
SQLite
• The design goal of SQLite is to allow the programs to be operated without database
installation or administration
• SQLite database allows methods to open the database connection, perform queries and
query updates and close the database
6. SQLiteQuery: A SQLite program that represents a query that reads the resulting rows in
CursorWindow
iOS
• iOS was designed to run on Apple iPhone and iPad mobile devices
• iOS is structured on the Mac OS X operating system, with added functionality pertinent
to mobile devices
iOS Architecture
• Cocoa Touch is an API for Objective-C that provides several frameworks for developing
applications that run on iOS devices
• Cocoa Touch provides support for hardware features unique to mobile devices, such as
touch screens
• The media services layer provides services for graphics, audio, and video
• The core services layer provides a variety of features, including support for cloud
computing and databases
• The bottom layer represents the core operating system, which is based on the kernel
environment
o UI Kit framework
o Message UI framework
o iAd framework
o Account framework
o Twitter framework
Media Layer
– C-based API designed to ease the handling of advanced text layout and
font rendering requirements
o Image IO framework
– Provides a mechanism for locating and retrieving videos and photo files
located on the device
– It allows new photos and videos to the standard device photo album
– Provides a set of video and image filtering and manipulation capabilities for
application developers
– Provides foundation for majority of visual effects and animation used by UIkit
framework
o OpenGL ES framework
o GLKit framework
o NewsstandKit framework
– Intended as a central location for users to gain access to newspapers and
magazines
o AV foundation framework
• Features
o Peer-to-peer services
o iCloud storage
o Block objects
o In-App purchase
o SQLite
o XML support
o Data protection
– Enables application code to be written that works with HTTP, FTP and
domain name servers
o EventKit framework
Core OS Layer
• Contains low level features that most other technologies are built upon
o Accelerate framework
o Security framework
– Provides all the security interfaces that can connect to external networks
including certificates, public and private keys, trust policies, key chains,
encryption, digests and HMAC