Unit V - OS
Unit V - OS
UNIT V
5.1. OVERVIEW
Idea: To abstract the hardware of a single computer like CPU, memory, disk drives etc., into
several different execution environments, thus creates the illusion that each separate
environment is running on its own private computer.
Hence a single physical machine can run multiple operating systems concurrently, each in its
own virtual machine.
Uses of Virtualization:
• for data-center operations,
• for efficient application development, and
• software testing
5.2. HISTORY
Most systems could not support virtualization. However, virtualization establishes the system
requirements and a target for functionality. Virtualization requirements are:
• Fidelity. AVMM provides an environment for programs that is identical to the
original machine.
• Performance. Programs running within that environment have minor performance
decreases.
• Safety. The VMM is in complete control of system resources.
By late 1990s, Intel 80x86 CPUs had become common, fast, and rich in features.
FEATURES
stopped and taken out of use for a while then the changes are made and tested.
lOMoARcPSD|25525186
The ability to virtualize depends on the features of CPU. If features are sufficient, then VMM
(Virtual Machine Manager) can be written that provides a guest environment. Otherwise,
virtualization is impossible.
5.4.1. Trap-and-Emulate
On dual-mode system, virtual machine guest can execute only in user mode. The
kernel runs in kernel mode, and it is not safe to allow user-level code to run in kernel mode.
Following procedure is followed to perform the transfer:
When the kernel in the guest attempts 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.
lOMoARcPSD|25525186
• But kernel mode privilege mode code runs slower due to trap-and-emulate
o Especially a problem when multiple guests running, each needing trap-
andemulate
• CPUs adding hardware support, mode CPU modes to improve virtualization
performance.
• Some CPUs don’t have clean separation between privileged and nonprivileged
instructions
• Earlier Intel x86 CPUs are among them o Earliest Intel CPU designed for a calculator
• Backward compatibility means difficult to improve
• Consider Intel x86 popf instruction
o Loads CPU flags register from contents of the stack
o If CPU in privileged mode -> all flags are replaced o
If CPU in user mode -> only some flags replaced o
No trap is generated
In this method, caching provides the solution. The replacement code for each instruction that
needs to be translated is cached. All later executions of that instruction run from the
translation cache and need not be translated again. If the cache is large enough, this method
can greatly improve performance.
In Intel x86 CPU family, Intel added new virtualization support (VT-x instructions) in
successive generations. No binary translation is needed.
In fact, all major general-purpose CPUs now provide extended hardware support for
virtualization. Example: AMD virtualization technology (AMDV).
It defines two new modes of operation - host and guest - thus moving from a dual-mode to a
multimode processor.
The VMM can enable host mode, define the characteristics of each guest virtual machine, and
then switch the system to guest mode, passing control of the system to a guest operating
system
lOMoARcPSD|25525186
that is running in virtual machine. In guest mode, the virtualized operating system thinks it is
running on native hardware and sees whatever devices are included in the host's definition of
the guest.
If the guest tries to access a virtualized resource, then control is passed to the VMM to
manage that interaction.
A nested page-table violation caused by an attempt to access unavailable memory can result
in the guest's exit. With AMD's RVI memorymanagement enhancements, VMMs no longer
need to implement software NPTs. In essence, these
CPUs implement nested page tables in hardware to allow the VMM to fully control paging
while the CPUs accelerate the translation from virtual to physical addresses. The NPTs add a
new layer, one representing the guest's view of logical-tophysical address translation.
The CPU page-table walking function includes this new layer as necessary, walking through
the guest table to the VMM table to find the physical address desired.
o ATLB miss results in a performance penalty, because more tables must be traversed to
complete the lookup. o Figure shows the extra translation work performed by the
hardware to translate from a guest virtual address to a final physical address.
o First, the VMM sets up protection domains to tell the CPU which physical memory
belongs to each guest. Next, it assigns the I/O devices to the protection domains,
allowing them direct access to those memory regions and only those regions.
o The hardware then transforms the address in a DMA request issued by an I/O device
to the host physical memory address associated with the I/O.
o In this manner, DMA transfers are passed through between a guest and a device
without VMM interference.
o Similarly, interrupts must be delivered to the appropriate guest and must not be visible
to other guests.
o By providing an interrupt remapping feature, CPUs with virtualization hardware
assistance automatically deliver an interrupt destined for a guest to a core that is
currently running a thread of that guest.
o While a virtual machine is created, whatever be the hypervisor type, its creator gives
the VMM certain parameters.
o These parameters include the number of CPUs, amount of memory, networking
details, and storage details that the VMM will take into account when creating the
guest.
o Example, if a user wants to create a new guest with two virtual CPUs, 4 GB of
memory, 10 GB of disk space, one network interface that gets its IP address via DHCP,
and access to the DVD drive. The VMM then creates the virtual machine with those
parameters.
lOMoARcPSD|25525186
Type 0 hypervisors exists with the names "partitions" and "domains." They are a
hardware feature.
o The VMM itself is encoded in the firmware and loaded at boot time.
o In turn, it loads the guest images to run in each partition.
o The feature set of type 0 hypervisor is smaller than other types because it is
implemented in hardware.
o For example, a system might be split into four virtual systems, each with edicated
CPUs, memory, and I/O devices. Each guest believes that it has dedicated hardware
because of simplifying many implementation details.
o Making the I/O available has some difficulty, as it is not easy to dedicate I/O devices
to guests if there are not enough.
o Solution: hypervisor manages the shared access or grants all devices to a control
partition. In control partition, a guest operating system provides services via daemons
to other guests, and the hypervisor routes I/O requests appropriately.
o Some type 0 hypervisors can move physical CPUs and memory between running
guests. In this case, the guests are paravirtualized, aware of virtualization and assisting
in its execution.
o A guest must watch for signals from the hardware or VMM that a hardware change
has occurred, probe its hardware devices to detect the change, and add or subtract
CPUs or memory from its available resources. o A type 0 hypervisor can run
multiple guest operating systems one in each hardware partition.
o All of those guests, as they run on raw hardware it can be VMMs. o Each guest
operating system in type 0 hypervisor is a native operating system with a subset of
hardware made available to it. Hence, it can have its own guest operating systems.
o Other types of hypervisors cannot provide this virtualization-withinvirtualization
functionality.
o Type 1 Hypervisors are found in company data centers to become "the datacenter
operating system."
o These are special-purpose operating systems that run natively on the hardware, to
support system calls and other interfaces for running programs, they create, run, and
manage guest operating systems.
lOMoARcPSD|25525186
Advantage: Ability to consolidate more operating systems and applications onto fewer
systems. o For example, rather than having ten systems running at 10 percent utilization each, a data
center might have one server manage the entire load.
o If utilization increases, guests and their applications can be moved to lessloaded
systems live, without interruption of service. o Using snapshots and cloning, system
can save the states of guests and duplicate those states are easily.
o These hypervisors provide fewer virtualization features than other type 1 hypervisors.
o They treat a guest operating system as another process, but provide special handling
when the guest tries to execute special instructions.
5.5.5. Paravirtualization
o Paravirtualization presents the guest with a system that is similar but not identical to
the guest's preferred system.
o The guest must be modified to run on the paravirtualized virtual hardware. The gain
for this extra work is more efficient use of resources and a smaller virtualization layer.
o Xen VMM became the leader in paravirtulization by implementing several
techniques to optimize the performance of guests and the host system.
o For example, Xen VMM provides clean and simple device abstractions that allow
efficient I/O communication between the guest and VMM. For each device used by
lOMoARcPSD|25525186
each guest, there was a circular buffer shared by the guest and VMM via shared
memory. Read and write data are placed in this buffer, as shown in Figure below.
o For memory management in Xen each guest had its own set of page tables, set to
readonly. Xen required the guest to use a hypercall to the hypervisor VMM, when a
pagetable change was needed. o This means that the guest operating system's kernel
code must have been changed from the default code to these Xen-specific methods.
To optimize the performance, Xen allowed the guest to queue up multiple page-table
changes asynchronously via hypercalls and then checked to ensure that the changes
were complete before continuing operation.
o Xen allowed virtualization of x86 CPUs without the use of binary translation.
o Xen has taken advantage of hardware features supporting virtualization. Hence it does
not require modified guests and does not need the paravirtualization method.
5.5.7. Emulation
o Virtualization is the common method for running applications designed for one
operating system on a different operating system, but on the same CPU.
o It works efficiently because the applications were compiled for the instruction set that
the target system uses. o But what if an application or operating system needs to run
on a different CPU? Translate all source CPU's instructions into the equivalent
instructions of the target CPU. Such an environment is no longer virtualized but is
fully emulated.
Emulation is useful when the host system has one system architecture
and the guest system was compiled for a different architecture.
o Example, suppose a company has replaced its outdated computer system with a new
system but would like to continue to run certain important programs that were
compiled for the old system.
The programs could be run in an emulator that translates each of the outdated system's
instructions into the native instruction set of the new system.
o Emulation can increase the life of programs and allow exploring old architectures
without having an actual old machine.
Challenge of Emulation
o Oracle Solaris version 10 has included containers, or zones, that create a virtual layer
between the operating system and the applications. o In this system, only one kernel
is installed, and the hardware is not virtualized. It provides processes within a zone
with the impression that they are the only processes on the system.
o Each zone can run its own scheduler to optimize the performance of its applications
on the allotted resources.
o Figure below shows a Solaris 10 system with two containers and the standard "global"
user space.
o Containers are much lighter weight than other virtualization methods. They use fewer
system resources and are faster to instantiate and destroy.
o Hence it is used in cloud computing.
o FreeBSD was the first operating system to include a container-like feature (called
"jails"), and AIX has a similar feature.
lOMoARcPSD|25525186
• The VMM has a number of physical CPUs available and a number of threads to run
on those CPUs.
• The threads can be VMM threads or guest threads. Guests are configured with a
certain number of virtual CPUs at creation time, and that number can be adjusted
throughout the life of the VM.
• When there are enough CPUs to allocate the requested number to each guest, the
VMM can treat the CPUs as dedicated and schedule only a given guest's threads on
that guest's CPUs. In this situation, the guests act like native operating systems
running on native CPU.
• In some other situations, there may not be enough CPUs to go around. The VMM
itself needs some CPU cycles for guest management and I/O management and can
steal cycles from the guests by scheduling its threads across all the system CPUs.
lOMoARcPSD|25525186
Case of over-commitment
It is more difficult where the guests are configured for more CPUs than exist in the
system.
o VMM can use standard scheduling algorithms to make progress on each thread but
can add a fairness aspect to those algorithms.
o Example, if there are 6 hardware CPUs needs to be allocated to 12 guest, the VMM
can allocate CPU resources proportionally, giving each guest half of the CPU
resources it believes it has.
o The VMM can still present all 12 virtual CPUs to the guests, but in mapping them
onto physical CPUs, the VMM can use its scheduler to distribute them appropriately.
o The time-of-day clocks in virtual machines are incorrect because timers take longer to
trigger than they would on dedicated CPUs.
o To correct this, the VMM makes an application available for each type of operating
system that the system administrator can install into the guests. This application
corrects clock drift and can have other functions, such as virtual device management.
To do that, the VMM first evaluates each guest's maximum memory size.
1. A guest believes it controls memory allocation via its page table management, but in
reality VMM maintains a nested page table that translates the guest page table to real
page table. The VMM optimize the guest's use of memory without the guest's knowledge
or help. One approach is to provide double paging. o Here, the VMM has its own page-
replacement algorithms and loads pages into a backing store that the guest believes is
physical memory.
o VMM knows less about the guest's memory access patterns than the guest does, so its
paging is less efficient, creating performance problems.
o ● VMMs do use this method when other methods are not available or are not
providing enough free memory. However, it is not the preferred approach. A pseudo-
device driver uses device-driver interfaces, appearing to the kernel to be a device
lOMoARcPSD|25525186
driver, but does not actually control a device. Rather, it is an easy way to add kernel-
mode code without directly modifying the kernel.
lOMoARcPSD|25525186
2. VMM install in each guest a pseudo- device driver or kernel module that the VMM
controls. This balloon memory manager communicates with the VMM and is told to
allocate or deallocate memory.
o If told to allocate, it allocates memory and tells the operating system to pin the
allocated pages into physical memory hence it cannot be moved or paged out. To the
guest, these pinned pages appear to decrease the amount of physical memory it has
available, creating memory pressure.
o The guest then may free up other physical memory to be sure it has enough free
memory. Meanwhile, the VMM, knowing that the pages pinned by the balloon
process will never be used, removes those physical pages from the guest and allocates
them to another guest.
o At the same time, the guest is using its own memory-management and paging
algorithms to manages the available memory. o If memory pressure within the entire
system decreases, the VMM will tell the balloon process within the guest to unpin and
free some or all of the memory, allowing the guest more pages for its use.
3. Another common method for reducing memory pressure is for the VMM to determine if
the same page has been loaded more than once. In this case, VMM reduces the number of
copies of the page to one and maps the other users of the page to that one copy.
o Example: VMware randomly samples guest memory and creates a hash for each page
sampled. That hash value is a "thumbprint" of the page. o The hash of every page
examined is compared with other hashes stored in a hash table. If there is a match, the
pages are compared byte by byte to see if they really are identical. If they are, one
page is freed, and its logical address is mapped to the other's physical address.
o If multiple guests run the same operating system, then only one copy of the active
operating-system pages need be in memory. Similarly, multiple guests could be
running the same set of applications, again a likely source of memory sharing. o The
overall effect is to enable guests to behave and perform as if they had the full amount
of memory requested, although in reality they have less.
5.6.3. I/O
o Hypervisors are less concerned with how they represent the underlying hardware to
their guests.
o To deal with variety of I/O devices, operating systems uses flexible I/O mechanisms.
o Device-driver provides a uniform interface to the operating system whatever the I/O
device.
o They are designed to allow third-party hardware manufacturers to provide device
drivers connecting their devices to the operating system. o Usually, device drivers
can be dynamically loaded and unloaded. Virtualization takes advantage and provides
specific virtualized devices to guest operating systems.
o I/O devices may be dedicated to guests or the VMM may have device drivers onto
which it maps guest I/O.
o I/O in virtual environments is complicated and requires VMM design and
implementation.
o With type 0 hypervisors that provide direct device access, guests often run at the same
speed as native operating systems. When it instead provide shared devices,
performance may suffer.
lOMoARcPSD|25525186
o With direct device access in type 1 and 2 hypervisors, performance can be similar to
that of native operating systems if certain hardware support is present. The hardware
needs to provide DMA pass-through with facilities like VT-d, as well as direct
interrupt delivery. Given how frequently interrupts occur, the guests on hardware
without these features have worse performance than if they were running natively. o
VMMS provide shared access to devices. Consider a disk drive to which multiple
guests have access. The VMM must provide protection while the device is being
shared, assuring that a guest can access only the blocks specified in the guest's
configuration. In such instances, the VMM must be part of every I/O, checking it for
correctness as well as routing the data to and from the appropriate devices and guests.
One of the features found in type 0 and type 1 hypervisors is the live migration of a running
guest from one system to another.
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
lOMoARcPSD|25525186
possible to upgrade, replace, and remove your battery that no longer holds a charge. In
addition, Android phones come with SD card slots for expandable storage.
lOMoARcPSD|25525186
1. Applications
An application is the top layer of the android architecture. The pre-installed
applications like camera, gallery, home, contacts, etc., and third-party applications
downloaded from the play store like games, chat applications, etc., will be installed on this
layer.
It runs within the Android run time with the help of the classes and services provided
by the application framework.
2. Application framework
Application Framework provides several important classes used to create an Android
application. It provides a generic abstraction for hardware access and helps in managing the
user interface with application resources.
lOMoARcPSD|25525186
Android Emulator
The Emulator is a new application in the Android operating system. The Emulator is a new
prototype used to develop and test android applications without using any physical device.
The android emulator has all of the hardware and software features like mobile devices
except phone calls.
Advantages of Android Operating System
o Android Google Developer o
Android Users o Android
Multitasking o Google Play Store
App
o Android Notification and Easy Access o
Android Widget Disadvantages of
Android Operating System o Android
Advertisement pop-ups
o Android require Gmail ID o
Android Battery Drain o
Android Malware/Virus/Security
IOS
IOS is a Mobile Operating System that was developed by Apple Inc. for iPhones,
iPads, and other Apple mobile devices. iOS is the second most popular and most used Mobile
Operating System after Android.
The structure of the iOS operating System is Layered based. Its communication
doesn’t occur directly. The layer’s between the Application Layer and the Hardware layer
will help for Communication. The lower level gives basic services on which all applications
rely and the higher-level layers provide graphics and interface-related services. Most of the
system interfaces come with a special package called a framework.
A framework is a directory that holds dynamic shared libraries like .a files, header
files, images, and helper apps that support the library. Each layer has a set of frameworks that
are helpful for developers.
Architecture of IOS
lOMoARcPSD|25525186
CORE OS Layer:
All the IOS technologies are built under the lowest level layer i.e. Core OS layer. These
technologies include:
1. Core Bluetooth Framework
2. External Accessories Framework
3. Accelerate Framework
4. Security Services Framework
5. Local Authorization Framework etc.
It supports 64 bit which enables the application to run faster.
CORE SERVICES Layer:
Some important frameworks are present in the CORE SERVICES Layer which helps the iOS
operating system to cure itself and provide better functionality. It is the 2nd lowest layer in
the Architecture as shown above. Below are some important frameworks present in this layer:
1. Address Book Framework-
The Address Book Framework provides access to the contact details of the user.
2. Cloud Kit Framework-
This framework provides a medium for moving data between your app and iCloud.
3. Core Data Framework-
This is the technology that is used for managing the data model of a Model View
Controller app.
4. Core Foundation Framework-
This framework provides data management and service features for iOS applications. 5.
Core Location Framework-
This framework helps to provide the location and heading information to the application.
6. Core Motion Framework-
All the motion-based data on the device is accessed with the help of the Core Motion
Framework.
7. Foundation Framework-
Objective C covering too many of the features found in the Core Foundation framework.
8. HealthKit Framework-
This framework handles the health-related information of the user.
9. HomeKit Framework-
This framework is used for talking with and controlling connected devices with the user’s
home.
10. Social Framework-
It is simply an interface that will access users’ social media accounts.
11. StoreKit Framework-
This framework supports for buying of contents and services from inside iOS apps.
MEDIA Layer:
With the help of the media layer, we will enable all graphics video, and audio technology of
the system. This is the second layer in the architecture. The different frameworks of MEDIA
layers are:
1. ULKit Graphics-
This framework provides support for designing images and animating the view content.
2. Core Graphics Framework-
This framework support 2D vector and image-based rendering and it is a native drawing
engine for iOS.
3. Core Animation-
lOMoARcPSD|25525186
This framework helps in optimizing the animation experience of the apps in iOS.
4. Media Player Framework-
This framework provides support for playing the playlist and enables the user to use their
iTunes library.
5. AV Kit-
This framework provides various easy-to-use interfaces for video presentation, recording,
and playback of audio and video.
6. Open AL-
This framework is an Industry Standard Technology for providing Audio.
7. Core Images-
This framework provides advanced support for motionless images.
8. GL Kit-
This framework manages advanced 2D and 3D rendering by hardware-accelerated
interfaces.
COCOA TOUCH:
COCOA Touch is also known as the application layer which acts as an interface for the user
to work with the iOS Operating system. It supports touch and motion events and many more
features. The COCOA TOUCH layer provides the following frameworks :
1. EvenKit Framework-
This framework shows a standard system interface using view controllers for viewing and
changing events.
2. GameKit Framework-
This framework provides support for users to share their game-related data online using a
Game Center.
3. MapKit Framework-
This framework gives a scrollable map that one can include in your user interface of the
app.
4. PushKit Framework-
This framework provides registration support.
• More Costly.
• Less User Friendly as Compared to Android Operating System.
• Not Flexible as it supports only IOS devices.
• Battery Performance is poor.