Day 21 — CS Fundamentals December — Deep dive into Hypervisors
In yesterday’s article, I mentioned about virtualization technology and virtual machines with a brief idea and working associated around hypervisor.
But I believed that considering hypervisor as the main entity around which virtualization revolves, I should write another article dedicated to talk about what is underneath the hypervisor and how exactly it allocates resources to the VMs.
Let’s dive in!
Types of hypervisors
So, there are two types of hypervisors:
- Type 1 or Bare-metal hypervisor: So, these are the hypervisors which are directly installed over the host hardware without the need of host OS. And here, the hypervisor directly communicates with the host hardware.
- Type 2 or Hosted hypervisor: So, these are the hypervisors which are installed over the host operating system as a software and the host OS deals with the host hardware for the hypervisor.
Under the hood of the hypervisor
So, the hypervisor has three components:
- Dispatcher:It is the entrypoint to the hypervisor for the instructions coming from the guest OSs. It is the top level control module of the hypervisor. It decides which should be the next module (allocator or interpreter) to invoke.
So, whenever any instruction from a guest OS attempts to change the resource assignments to that guest OS (RAM, storage, processing power), then those instructions trap to the dispatcher.
- Allocator: It is invoked whenever there is an attempt to change the resource assignments associated with any of the VMs/guest OS. So, the instructions which attempt to change the resource assignments with some VM are passed directly from the dispatcher to the allocator.
- Interpreter: This component emulates the effects of instructions when operating on virtual resources. And finally, it returns the control back to the guest OS as soon as the routine completes.
Mechanics behind allocating the host resources to the VMs
So, there are four major kinds of host resources which are required by Virtual Machines in general:
- CPU (processing power)
- Memory (RAM)
- Network
- Storage (disk space)
=> Allocating CPU power to the Virtual Machine
VM requests processing power from hypervisor. Hypervisor takes that request and schedules it for operations. Then, the hypervisor passes the operated requests to the underlying host OS and then, the host OS talks to the host kernel and finally, responds with the right amount of processing power to the hypervisor and then, to the VM.
=> Allocating Memory (RAM) to the Virtual Machine
This is fairly straightforward. So while creating the VM, when you are configuring the settings for the VM, you also specify the amount of RAM to be allocated to that VM. The VM gets access to only that amount of RAM. In the future, it can be re-allocated as well on the basis of the utilization.
=> Allocating Network to the Virtual Machine
Now, the VM, just like any other computer, might require internet support. But obviously, it doesn’t have its own physical network hardware to provide internet because well, it is a “virtual machine”. So, the hypervisor emulates a virtual network hardware for the VM. So, due to this, each VM has its own Virtual NICs (Network Interface Card). The VMs pass their requests to these Virtual NICs and these Virtual NICs pass the network requests to the Virtual Switches present in the hypervisor. And finally, the hypervisor passes the requests from their Virtual Switches to the physical network switches of the underlying host and finally, the host provides the required network bandwidth to the VM.
=> Allocating storage (disk space) to the Virtual Machine
Each VM has its own individual virtual disk storage. All the VMs share the storage from the physical disk of the underlying host. Every VM has their carved-out regions of spaces in the physical for them. Now, whenever a VM writes something to its virtual disk, the data blocks are sent to the virtual SCSI disk adapter and the hypervisor passes these data blocks to the iSCSI disk adapter of the physical host to write the passed data blocks at the right spot in the carved out region of physical disk corresponding to that VM.
That’s it!
Thanks for reaching till here!
I hope you understood and got a good and deep dive into hypervisors :)
If you liked the article, do give it some claps :D
Stay tuned for another article which is going to come tomorrow associated with some other interesting CS fundamental.
LinkedIn — https://www.linkedin.com/in/yashvardhan-kukreja-607b24142/
GitHub — https://www.github.com/yashvardhan-kukreja
Email — yash.kukreja.98@gmail.com
Adios!