Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

KVM performance optimization

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Why should KVM be tuned?

Performance loss is the key. KVM uses full virtualization technology, and full virtualization needs a software to simulate the hardware, so there is a certain amount of wear and tear, especially IPUBO, so it needs to be optimized.

The performance optimization of KVM is mainly in the aspects of CPU, memory and IZP O. Of course, for these aspects of optimization, it is also necessary to divide the scene, and the optimization direction of different scenes is also different.

II. Ideas and steps of KVM optimization

The performance of KVM is already good, but there are some fine-tuning measures that can further improve the performance of KVM.

1. Optimization of CPU

To consider the number of CPU, the total number of all guestcpu should not exceed the total number of physical machine CPU. "if exceeded, it will have a serious impact on performance, and it is recommended that you choose to replicate the host CPU configuration."

2. Memory optimization

(1) KSM (Kernel Samepage Merging, same page merging)

The minimum unit of memory allocation is page (page), and the default size is 4KB. You can merge memory with the same content on host machine to save memory use, especially when the virtual machine operating system is the same, there must be many memory values with the same content. If KSM is enabled, the memory will be merged into one. Of course, this process will result in performance loss, so whether to turn it on or not, you need to consider the use scenario.

KSM is of great significance to the KVM environment. When there are many clients running the same system on KVM, there will be many identical memory pages between the clients, especially the read-only kernel code pages can be shared between the clients, thus reducing the memory resources occupied by the clients and running more clients at the same time.

KSM has a slight impact on system performance, trading efficiency for space. If the system has plenty of memory, you don't need to turn on KSM. If you want to run as many KVM clients in parallel as possible, you can open KSM.

Ll / sys/kernel/mm/ksm/ View kernel information

Number of pages merged by pages_shared

The number of virtual pages that pages_sharing is sharing a single page

The number of pages that page_unshared has as a sharing candidate but is not currently shared

The number of pages that page_volatile changes frequently as a sharing candidate, and the KSM service will not merge this page

The number of times full_scan scanned KSM for repetitive content

Whether merge_across_nodes allows merging in NUMA nodes

The number of pages scanned by pages_to_scan at a time, which affects system performance

Time interval between sleep_milisecs scans

The size of each page is 4KB, and the shared memory can be calculated as: 4 pages = memory size (KB)

Cd / sys/kernel/mm/ksm/cat run / / whether to enable KSM,0 is not enabled, 1 is to enable echo 1 > run / / temporarily enable KSM, can only use redirection, does not support VI editor vi / etc/rc.local / / add echo 1 > / sys/kernel/mm/ksm/run, let KSM open self-boot cat pages_to_scan / / scan the same page regularly, sleep_millisecs decides how long it will take Pages_to_scan decides how many pages to view each time. The default is 100. the larger the better, but more than 2000 is invalid. You need to enable two services, ksmtuned and tuned, to support changing pages.

(2) set a limit on memory

If we have multiple virtual machines, in order to prevent one virtual machine from making uncontrolled use of memory resources, causing other virtual machines to fail to use properly, we need to limit the use of memory.

Virsh memtune c01 / / View the current virtual machine c01 memory limit in KB

Virsh memtune-help

Virsh memtune C01-- hard-limit 1024000-- live / / sets mandatory maximum memory and takes effect online virsh memtune C01 / / View

(3) large page backend memory (Huge Page Backed Memory)

When the logical address is translated to the physical address, CPU maintains a translation backup buffer TLB, which is used to cache the translation result, while the TLB capacity is very small, so if the page is very small, the TLB is easily filled, which can easily lead to cache miss. On the contrary, when the page becomes larger, the TLB needs to save fewer cache items, which will reduce the cache miss. By providing the client with large-page back-end memory, you can reduce the memory consumed by the client and improve the TLB hit ratio, thereby improving KVM performance.

Intel's x86 CPU usually uses 4KB memory pages, but it can also be configured to use large pages (huge page): x86132 is 4MB PAE x86164 and x86632 PAE is 2MB, which is another optimization technology of KVM virtual machines.

With large pages, the page tables of KVM's virtual machines will use less memory and will improve the efficiency of CPU.

Cat / proc/meminfo / / View memory information, no large pages available

Echo 25000 > / proc/sys/vm/nr_hugepages / / specify the number of memory pages required for large pages (effective temporarily)

Sysctl-w vm.nr_hugepages=25000 / / specify the number of memory pages needed for large pages permanently or add vm.nr_hugepages=2500 to / etc/sysctl.conf to permanently set the number of memory pages required for large-page file systems.

Note: the number of pages required by a large-page file system can be roughly estimated by dividing the memory required by the client by the page size.

Virsh destroy C01 / / deleting the original domain virsh edit C01 / / Editing the virtual machine's XML configuration file uses large pages to allocate memory

Mount-t hugetlbfs / dev/hugepages/ Mount hugetlbfs file system systemctl restart libvirtd.servicevirsh start C01 / / enable virtual machine cat / proc/meminfo | grep HugePage / / View

Virsh destroy C01 / / Delete cat / proc/meminfo again | grep HugePage / / check again and find that the big page has been released

3. Optimization of IPUBO

In the actual production environment, in order to avoid excessive consumption of disk resources and the impact on other virtual machines, we hope that the consumption of disk resources of each virtual machine can be controlled. For example, if multiple virtual machines write data to the hard disk, the one who can write first can adjust the weight weight of iUnip O. The higher the weight, the higher the priority of writing to the disk.

There are two ways to control disk Icano.

(1) the weight in the whole, ranging from 100 to 1000.

(2) to limit the specific Istroke O.

Virsh blkiotune c01 / / View the iUnip O parameters of c01

Virsh blkiotune C01-- weight 500 / / set the weight to 500virsh blkiotune C01 / / check again

Virsh edit C01 / / can also edit the XML configuration file of the virtual machine

Virsh blkiotune-- help / / View usage help

4. System tuning tool tuned/tuned-adm

CentOS introduces a new set of system tuning tool tuned/tuned-adm after version 6.3. among them, tuned is a server program, which is used to monitor and collect data from various components of the system, and dynamically adjust the system settings according to the information provided by the data to achieve the purpose of dynamic optimization of the system. Tuned-adm is a client program used to deal with tuned, manage and configure tuned/tuned-adm in a command-line way, and provide some pre-configured optimization solutions for direct use. Of course, different systems and application scenarios have different optimization solutions. The pre-configured optimization strategy of tuned-adm does not always meet the requirements, so customization is needed. Tuned-adm allows users to create and customize new tuning solutions.

Yum install tuned- y / / install and launch the tuned tool service tuned starttuned-adm active / / to view the current optimization plan

Tuned-adm list / / View the pre-set optimization plan

Tuned-adm profile virtual-host / / modify the optimization scheme to virtual-host

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report