这篇文章主要介绍了对KVM虚拟机进行cpu pinning配置的方法,通过文中的各种virsh命令可进行操作,需要的朋友可以参考下
首先需求了解基本的信息

1 宿主机CPU特性查看

使用virsh nodeinfo可以看到一些基本信息

#virsh nodeinfo
CPU model: x86_64
CPU(s):
CPU frequency: MHz
CPU socket(s):
Core(s) per socket:
Thread(s) per core:
NUMA cell(s):
Memory size: KiB

使用virsh capabilities可以查看物理机CPU的详细信息,包括物理CPU个数,每个CPU的核数,是否开了超线程。

#virsh capabilities
<capabilities>
<host>
<uuid>----3235445a564a</uuid>
<cpu>
<arch>x86_64</arch>
<model>SandyBridge</model>
<vendor>Intel</vendor>
<topology sockets='' cores='' threads=''/>
<feature name='erms'/>
<feature name='smep'/>
...
</cpu>
<power_management>
<suspend_disk/>
</power_management>
<migration_features>
<live/>
<uri_transports>
<uri_transport>tcp</uri_transport>
</uri_transports>
</migration_features>
<topology>
<cells num=''>
<cell id=''>
<cpus num=''>
<cpu id='' socket_id='' core_id='' siblings='0,16'/>
...
<cpu id='' socket_id='' core_id='' siblings='7,23'/>
</cpus>
</cell>
<cell id=''>
<cpus num=''>
<cpu id='' socket_id='' core_id='' siblings='8,24'/>
...
<cpu id='' socket_id='' core_id='' siblings='15,31'/>
</cpus>
</cell>
</cells>
</topology>
<secmodel>
<model>none</model>
<doi></doi>
</secmodel>
<secmodel>
<model>dac</model>
<doi></doi>
</secmodel>
</host>
...
</capabilities>

使用virsh freecell命令查看可以当前空闲内存

#virsh freecell --all
: KiB
: KiB
--------------------
Total: KiB

物理CPU的特性也可以通过/proc/cpuinfo查看

#cat /proc/cpuinfo
rocessor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .00GHz
stepping :
cpu MHz : 1200.000
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 3990.67
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management:
...

综合上面的信息,我们可以得出以下信息:

1) 物理CPU为 E5-2640V2,为8核2颗,开启了超线程,在物理机系统上可以看到32个CPU;

2) 物理机内存为128G

2 虚拟机CPU使用情况查看

可以使用virsh vcpuinfo命令查看虚拟机vcpu和物理CPU的对应关系

#virsh vcpuinfo
VCPU:
CPU:
State: running
CPU time: .0s
CPU Affinity: --------yyyyyyyy--------yyyyyyyy
VCPU:
CPU:
State: running
CPU time: .2s
CPU Affinity: --------yyyyyyyy--------yyyyyyyy
...

可以看到vcpu0被调度到物理机CPU25上,目前是使用状态,使用时间是10393.0s

CPU Affinity: --------yyyyyyyy--------yyyyyyyy

yyyyyyy表示可以使用的物理CPU内部的逻辑核,可以看到这台虚拟机可以在8-15, 24-31这些cpu之间调度,为什么不能使用0-7,16-23这些CPU呢,是因为系统的自动numa平衡服务在发生作用,一个虚拟机默认只能使用同一颗物理CPU内部的逻辑核。

使用emulatorpin可以查看虚拟机可以使用那些物理逻辑CPU

#virsh emulatorpin
emulator: CPU Affinity
----------------------------------
*: -

可以看到0-31我们都可以使用,意味这我们也可以强制将CPU调度到任何CPU上。

3 在线pinning虚拟机的cpu

强制让虚拟机只能在26-31这些cpu之间调度

#virsh emulatorpin  - --live

查看结果

#virsh emulatorpin
emulator: CPU Affinity
----------------------------------
*: -

查看vcpu info

#virsh vcpuinfo
VCPU:
CPU:
State: running
CPU time: .5s
CPU Affinity: --------------------------yyyyyy
VCPU:
CPU:
State: running
CPU time: .7s
CPU Affinity: --------------------------yyyyyy
...</p> <p>

查看xml文件

#virsh  dumpxml
<domain type='kvm' id=''>
<name>cacti-</name>
<uuid>23a6455c-5cd1-20cd-ecfe-2ba89be72c41</uuid>
<memory unit='KiB'></memory>
<currentMemory unit='KiB'></currentMemory>
<vcpu placement='static'></vcpu>
<cputune>
<emulatorpin cpuset='26-31'/>
</cputune>

我们也可以强制vcpu和物理机cpu一对一的绑定

强制vcpu 0和物理机cpu 28绑定

强制vcpu 1和物理机cpu 29绑定

强制vcpu 2和物理机cpu 30绑定

强制vcpu 3和物理机cpu 31绑定

#virsh vcpupin
#virsh vcpupin
#virsh vcpupin
#virsh vcpupin

查看xml文件,生效了

#virsh dumpxml
<domain type='kvm' id=''>
<name>cacti-</name>
<uuid>23a6455c-5cd1-20cd-ecfe-2ba89be72c41</uuid>
<memory unit='KiB'></memory>
<currentMemory unit='KiB'></currentMemory>
<vcpu placement='static'></vcpu>
<cputune>
<vcpupin vcpu='' cpuset=''/>
<vcpupin vcpu='' cpuset=''/>
<vcpupin vcpu='' cpuset=''/>
<vcpupin vcpu='' cpuset=''/>
<emulatorpin cpuset='26-31'/>
</cputune>

是vcpuino命令查看,可以看到配置生效了

#virsh vcpuinfo
VCPU:
CPU:
State: running
CPU time: .8s
CPU Affinity: ----------------------------y---
VCPU:
CPU:
State: running
CPU time: .0s
CPU Affinity: -----------------------------y--
...

4 cpu pinning简单的性能测试

cpu pinning到底对cpu的性能影响有多大,进行了一个简单的测试。

测试环境

硬件:ntel(R) Xeon(R) CPU X5650 @ 2.67GHz 2颗

软件:centos 7 update到内核 3.10.0-123.8.1.el7.x86_64

虚拟机:centos 7 update到内核 3.10.0-123.8.1.el7.x86_64

虚拟机cpu:1颗

测试工具:unixbench 5.1.2

不做cpu绑定测试结果

1 CPU in system; running 1 parallel copy of tests
Dhrystone 2 using register variables       28890881.0 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     3880.4 MWIPS (9.0 s, 7 samples)
Execl Throughput                               4146.3 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks       1051084.3 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          286552.2 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       2142638.4 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1726807.0 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 322865.5 lps   (10.0 s, 7 samples)
Process Creation                              13662.4 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   5955.4 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    713.1 lpm   (60.0 s, 2 samples)
System Call Overhead                        2138318.1 lps   (10.0 s, 7 samples)
System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   28890881.0   2475.7
Double-Precision Whetstone                       55.0       3880.4    705.5
Execl Throughput                                 43.0       4146.3    964.2
File Copy 1024 bufsize 2000 maxblocks          3960.0    1051084.3   2654.3
File Copy 256 bufsize 500 maxblocks            1655.0     286552.2   1731.4
File Copy 4096 bufsize 8000 maxblocks          5800.0    2142638.4   3694.2
Pipe Throughput                               12440.0    1726807.0   1388.1
Pipe-based Context Switching                   4000.0     322865.5    807.2
Process Creation                                126.0      13662.4   1084.3
Shell Scripts (1 concurrent)                     42.4       5955.4   1404.6
Shell Scripts (8 concurrent)                      6.0        713.1   1188.4
System Call Overhead                          15000.0    2138318.1   1425.5
                                                                   ========
System Benchmarks Index Score                                        1444.7

做了cpu绑定测试结果

1 CPU in system; running 1 parallel copy of tests
Dhrystone 2 using register variables       29812559.6 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     3928.7 MWIPS (8.9 s, 7 samples)
Execl Throughput                               4314.4 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks       1068627.9 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          291834.2 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       2052612.8 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1737466.2 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 326839.9 lps   (10.0 s, 7 samples)
Process Creation                              14234.5 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   6040.8 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    717.4 lpm   (60.1 s, 2 samples)
System Call Overhead                        2149194.4 lps   (10.0 s, 7 samples)
System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   29812559.6   2554.6
Double-Precision Whetstone                       55.0       3928.7    714.3
Execl Throughput                                 43.0       4314.4   1003.4
File Copy 1024 bufsize 2000 maxblocks          3960.0    1068627.9   2698.6
File Copy 256 bufsize 500 maxblocks            1655.0     291834.2   1763.3
File Copy 4096 bufsize 8000 maxblocks          5800.0    2052612.8   3539.0
Pipe Throughput                               12440.0    1737466.2   1396.7
Pipe-based Context Switching                   4000.0     326839.9    817.1
Process Creation                                126.0      14234.5   1129.7
Shell Scripts (1 concurrent)                     42.4       6040.8   1424.7
Shell Scripts (8 concurrent)                      6.0        717.4   1195.7
System Call Overhead                          15000.0    2149194.4   1432.8
                                                                   ========
System Benchmarks Index Score                                        1464.1

比较

综合得分

绑定 1464.1  不绑定 1444.7

综合得分 性能提升 1.34%

浮点运算

绑定 3928.7  不绑定  3880.4

浮点运算 性能提升 1.24%

对KVM虚拟机进行cpu pinning配置的方法的更多相关文章

  1. kvm虚拟化学习笔记(四)之kvm虚拟机日常管理与配置

    KVM虚拟化学习笔记系列文章列表----------------------------------------kvm虚拟化学习笔记(一)之kvm虚拟化环境安装http://koumm.blog.51 ...

  2. kvm虚拟机日常管理和配置操作命令梳理

    KVM虚拟机的管理主要是通过virsh命令对虚拟机进行管理.1)查看KVM虚拟机配置文件及运行状态KVM虚拟机默认配置文件位置: /etc/libvirt/qemu/autostart目录是配置kvm ...

  3. kvm虚拟机日常管理与配置

    1.  查看KVM虚拟机配置文件及运行状态 (1) KVM虚拟机默认配置文件位置: /etc/libvirt/qemu/ autostart目录是配置kvm虚拟机开机自启动目录.    (2) vir ...

  4. KVM 虚拟机命令行安装配置

    KVM作为linux内核的一部分,有着无法比拟的优势,相信KVM的大范围企业应用指日可待. 一.KVM宿主服务器环境配置 1. 查看CPU是否支持VT技术 cat /proc/cpuinfo | eg ...

  5. kvm虚拟机在线调整硬件配置

    #centos5.x版本不支持动态调整内存,CPU,以下是在centos6.x上测试 1.查看虚拟机信息 shell> virsh dumpxml cos_v1 | head -n 10 < ...

  6. KVM虚拟机cpu资源限制和vcpu亲缘性绑定

    前言 KVM中添加的实例存在资源分布不均的情况,这样如果有消耗资源的实例会影响到其他实例的服务正常运行,所以给kvm做资源限制是很有必要的,下面记录一下在centos7中KVM环境下使用cgroup限 ...

  7. Linux中如何克隆KVM虚拟机

    转载:https://yq.aliyun.com/articles/64860 作者 digoal 日期 2016-11-11 标签 Linux , KVM , 虚拟化 , 克隆 背景 当需要批量部署 ...

  8. kvm虚拟化学习笔记(二)之linux kvm虚拟机安装

    KVM虚拟化学习笔记系列文章列表----------------------------------------kvm虚拟化学习笔记(一)之kvm虚拟化环境安装http://koumm.blog.51 ...

  9. kvm虚拟化学习笔记(三)之windows kvm虚拟机安装

    KVM虚拟化学习笔记系列文章列表----------------------------------------kvm虚拟化学习笔记(一)之kvm虚拟化环境安装http://koumm.blog.51 ...

随机推荐

  1. python之路---05 字典 集合

    二十.字典 可变数据类型 {key:value}形式   查找效率高   key值必须是不可变的数据类型 1.增删改查 1).增    dic["新key"] = "新v ...

  2. redhat 6.4下PXE+Kickstart无人值守安装操作系统

    一 前言 作为中小公司的运维,经常会遇到一些机械式的重复工作,例如:有时公司同时上线几十甚至上百台服务器,而且需要我们在短时间内完成系统安装.常规的办法有什么?1.光盘安装系统:每个服务器DVD内置光 ...

  3. mongo之 前后台创建索引 --noIndexBuildRetry

    在数据量超大的情形下,任何数据库系统在创建索引时都是一个耗时的大工程.MongoDB也不例外.因此,MongoDB索引的创建有两个选择,一个是前台方式,一个是后台方式.那这两种方式有什么差异呢,在创建 ...

  4. 服务网关Zuul

    路由+过滤器 = Zuul 核心是一系列的过滤器 Zuul的四种过滤器API 前置(PRE) 后置(POST) 路由(Route) 错误(Error) Zuul组织架构图 二.Zuul的使用 1 创建 ...

  5. 打开RAD Studio XE5提示"displayNotification:内存不够"解决办法

    操作方法: 在RAD Studio XE5快捷方式上鼠标右击选择属性,在弹出的快捷方式标签页中将目标(T):"C:\Program Files (x86)\Embarcadero\RAD S ...

  6. XE5开发Android程序调用电话相关功能(短信息和电话) [转]

    其实都可以通过intent和URI调用系统功能.Windows程序员可以理解成是ShellExecute.这个是万金油.可以有调用各种功能.后面会介绍. 1.短信息.很简单 方法a.不使用Intent ...

  7. NDK学习笔记(五)Reader机制

    针对每一种后缀名Nuke都提供了对应的模块.为了决定用哪个版本的reader或writer模块,Nuke会先解析文件后缀名再以此为依据调用相关模块. 以JPG为例: 该文件格式有两种后缀名:.jpg和 ...

  8. “无法获得锁 /var/lib/dpkg/lock -open (11:资源暂时不可用)”的方法

    另外的ubuntu 问题 在更新的时候有时候会出现 “无法获得锁 /var/lib/dpkg/lock -open (11:资源暂时不可用)”的方法 解决办法: 在ubuntu系统的termial下, ...

  9. Flsk-Werkzeug-请求参数获取备忘

    Werkzeug:response,request,routing 获取请求参数:data,form,args,files,cookies,headers,method,url routing:Rul ...

  10. pytest.10.使用fixture参数化测试预期结果

    From: http://www.testclass.net/pytest/test_api_with_expected_result/ 背景 接上一节v2ex网站的查看论坛节点信息的api. 我们在 ...