KVM virtualization theory

KVM virtualization theory

Preface

KVM Virtualization The
US Environmental Protection EPA report once counted a set of statistics: When EPA studied the energy efficiency of servers and data centers, it was found that in fact, servers are only working 5% of the time, and the rest of the time has been dormant.

The birth of KVM is to solve the phenomenon of low computer utilization.

1. Virtualization technology

Virtualize a computer into multiple logical computers through virtualization technology, and run multiple logical computers on one computer at the same time. At the same time, each logical computer can run different operating systems, and application programs can run in independent spaces. And do not affect each other, thereby improving the efficiency of the computer,

1. Simulate multiple operating systems (centos, win10, suse) in one operating system (win10), and each operating system can run different services (nginx and tomcat), thereby realizing a host to build a cluster
2. Realize the functions
of physical hardware by means of software/applications. For example: ensp realizes the functions of physical devices in the form of software (Layer 2 switches, routers, Layer 3 switches, etc.), workstations, etc.

2. Development of Virtualization Technology

Prototype:

In 1961, the IBM 709 machine implemented a time-sharing system, which divided the CPU usage into multiple extremely short time slices (1/100sec). Each time slice performed different tasks. By polling these time slices, a cpu was polled. Disguised as multiple CPUs.
In 1972, IBM officially named the time-sharing system of the system370 machine as a virtual machine.
In 1990, the system390 machine launched by IBM supports logical partitioning (a cpu is divided into multiple copies, independent of each other, that is, logical partitioning) )
Xen:

Coming out in 2003, an external hypervisor/VMM program (virtual machine management program) can control the host machine and allocate resources to multiple clients.
Supported virtualization technologies: fully virtualized and
para -virtualized KVM:

It came out in 2007 and is now built into the kernel. Supported virtualization technology: full virtualization
Q: Why should KVM be placed in the kernel?
Answer: Put in the kernel is to improve the utilization of computer performance

supplement:

Full virtualization : All physical hardware resources are abstracted through software, and finally
the method used for invocation : using hypervisor (VMM) software. The principle is to establish an abstraction layer between the underlying hardware and the server, and the core-based virtualization The machine is an open source product hypervisor (VMM) for Linux systems that can capture CPU instructions.
Paravirtualization : need to modify the operating system.
Pass-through : use physical hardware resources directly (device support is required, not perfect yet)

Three, virtualization features

1. Advantages

Centralized management (remote management, maintenance) to
improve hardware utilization (low utilization of physical resources, such as peak, virtualization solves "idle" capacity)
dynamic adjustment of machine/resource configuration (virtualization separates system applications and service hardware) , Improved flexibility)
High reliability (additional functions and solutions can be deployed, which can improve application environments such as transparent load balancing, migration, and recovery replication)

2. Disadvantages

The high upfront cost (initial hardware support)
reduces hardware utilization (in certain scenarios, for example: applications that are extremely resource-intensive may not be suitable for virtualization)
greater error impact (local physical machine down opportunities cause virtual machines to be unavailable, At the same time, all the files in the virtual machine may be damaged. The
implementation of complex configuration and management (management personnel operation and maintenance, troubleshooting difficulties)
certain restrictions (virtualization technology involves various restrictions, must be compatible with support/compatible virtualization servers, applications And the supplier's combined use)
Security (the security risks of virtualization technology itself)

3. Case

VMwareWorkstation: Use software to achieve virtual multi-operating system
VirtualBox: Use software to virtualize multiple physical device functions
Take VMwareworkstation as an example

The workstation supports the virtualization technology of Intel and AMD.
Hardware-assisted virtualization technology Intel-VT-x AMD-V
Intel VT-x technology mainly includes the virtualization technology of CPU, memory and I/O, and provides optimized processing ( Early to make up for the defects of X86 architecture virtualization)
AMD-V is a set of hardware extensions and hardware-assisted virtualization technologies for the x86 processor system architecture, which can simplify pure software virtualization solutions and
improve VMM (virtual machine monitor) Design, make full use of hardware resources, and improve the virtualization efficiency of servers and data centers.
VMM (virtual machine monitor/management program) haperivisor
VMM is a system software that can maintain multiple efficient and isolated program environments (virtual machines), At the same time, it can manage the real resources of the computer system and provide interfaces for virtual machines

4. Main functions of VMM

Insert picture description here

Logical division of physical resources (converted into virtual resources)
call virtual resource supply

Four, KVM architecture and principles

Insert picture description here

1. KVM virtualization architecture/mode

Guest mode (guestOS): The OS in the VM is GuestOS

The mode in which the client runs in the operating system. The client is divided into kernel mode and user mode. The functions are as follows:

  • Customer mode
    Provide users with user space tools for virtual machine management and perform I/O on behalf of users. Qemu_ works in this mode (the main function of Qemu)
  • Linux kernel mode
    Simulates CPU and memory, realizes client mode switching, and handles the launch of client mode, KVM runs in this mode

2. KVM principle

The following components constitute a complete virtualization platform

Guest: The guest system, including CPU (vCPU), memory driver (Console, network card, I/O device driver, etc.),
is run in a restricted CPU mode by KVM.

The KVM kernel module simulates the processor and memory to support virtual machine operation

Qemu mainly handles I/O and provides customers with a user space /dev/kvm tool ibvirt for virtual machine management

  • ioctl (definition) A system call dedicated to device input and output operations
  • libvirt: KVM management tool

Simple understanding

1) The KVM driver provides processor, memory virtualization, and guest I/O interception. After guest I/O is intercepted, it is handed over to Qemu for processing.
2) Qemu uses the interface libkvm to call (ioctl) the virtual machine device interface/ dev/kvm allocates resources, manages, and maintains virtual machines.
3) Clients-user layer/virtualization layer (QEMU)-kernel (kvm) are called through API interfaces.

3. KVM workflow

  • The user-mode Qemu uses the interface libkvm to enter the kernel mode through the ioctl system call.
    The KVM driver creates a virtual CPU and virtual memory for the virtual machine,
    then executes the VMLAU.NCH instruction to enter the guest mode, loads the Guest OS and runs.
  • If an abnormality occurs during the operation of the Guest OS, the operation of the Guest OS is suspended, the current state is saved and the kernel mode is exited to handle these abnormalities.
  • When the kernel mode handles these exceptions, if I/O is not required, then re-enter the client mode after the processing is completed.
    If I/O is needed, then enter the user mode, then Qemu will handle the I/O, after the processing is completed, enter the kernel mode, and then enter the client mode

4. Comparison before and after virtualization

Before virtualization
①Each host has an operating system
②Software and hardware are closely integrated
③Running multiple applications on the same host usually causes conflicts
④The utilization of system resources is low (for example: 5%)
⑤The cost of hardware is high and insufficient After flexible
virtualization,
①Break the interdependence of operating system and hardware
②Through the technology of encapsulating into virtual machine, manage the operating system and application program as a single individual
③Strong security and fault isolation
④Virtual machine is independent of hardware, they Can run on any hardware

to sum up

1. Introduction to KVM technology
What technology is it: virtualization

2. KVM technology positioning (practical application)
workstation and virtualbox
modules based on hardware resources/equipment/operating system

3. The core function of KVM virtualization technology (principle)
QEMU (working in the user layer, controlling the ibkvm tool (I has a role, controlling KVM in the kernel) to call physical virtualization resources
(the way to call physical virtualization resources is ioctl, Provide virtual machine)
KVM (working at the kernel layer, virtualizing/abstracting physical hardware resources, providing Qemu component calls)

4. KVM core component functions
QEMU
function: control I/O virtualization, call hardware resources
KVM
function: provide virtual machine with CPU, memory (hardware resources) virtualization

Guess you like

Origin blog.csdn.net/qq_35456705/article/details/114953557