来自:http://fishcried.com/2015-01-09/cpu_bindings/
前一篇理解cpu topology对CPU Topology进行了学习总结,这里想总结下OpenStack下vCPU与pCPU常用的的绑定方式。 在尝试这些绑定之前,尤其是处理NUMA架构时还是建议看看前一篇文章,或者google一下相关概念,这样才能灵活自如。

使用启动参数isolcpus控制操作系统级别的CPU隔离

存在这样的一个需求,Compute节点操作系统自身与Hypervisor两个怎样才能隔离开,也就是不能让系统自身的服务占用了虚拟化资源。
解决起来很简单,就是指定操作系统只能用哪些cpu,而剩下的是留给hypervisor用的。具体的实现就是使用了isolcpus内核启动参数。

如isolcpus=4,5,6,7,8,表示系统启动后新进程不会使用4-8cpu,

isolcpus = [KNL,SMP]
format: <cpu number>,...,<cpu number> or <cpu number>-<cpu number> or <cpu number>,...,<cpu number>-<cpu number>

isolcpus的原理也很简单:通过设置进程的cpu亲和性来实现.启动时设置init进程的亲和性,后续的进程均会继承init进程的亲和性设置. 这样就达到了整个系统的亲和性一致.如果后续的用户想修改亲和性可以通过taskset来实现.

永久生效需要在grub中修改kernel的启动参数.

使用taskset设置进程亲和性

tasket使用非常简单,能够实时的进行cpu亲和性设置.

# 设置亲和性 taskset -cp mask pid taskset -cp 0-3 1234 # 获取亲和性 taskset -cp pid taskset -cp 1234 

使用Cgroup进行Cpu QOS

Cgroup能够管理cpu资源.cgroup使用了特殊的文件系统,可以像正常的文件操作一样完成cgroup的设置.也可是使用特定的命令来进行设置.具体操作可以参考Linux的Cgroup

Cgroup能够控制隔离cpu资源,但是更多的是QOS功能.

vCPUs Bindings on KVM

virsh vcpupin guest1 4 0,1,2,3,8,9,10,11 

主要是使用virsh vcpupin命令来实现,上面就是将虚机guest1的vcpu 4绑定到host的0,1,2,3,8,9,10,11上.

vCPUs Bindings On Openstack

I版的时候cpu bingdings非常简单,只要设置nova的vcpu_pin_set即可,也是挺粗糙的.

#nova.conf [DEFAULT]
...
vcpu_pin_set=4-31

J版的时候社区完善了功能,可以针对numa特性来进行绑定了.在numa体系中玩binding不是那么简单了.理解cpu topology应该能提供一点帮助.

  • Guest Numa策略 更多查看virt-driver-numa-placement bp

    • hw:numa_nodes=NN - numa of NUMA nodes to expose to the guest.
    • hw:numa_mempolicy=preferred|strict - memory allocation policy
    • hw:numa_cpus.0= - mapping of vCPUS N-M to NUMA node 0
    • hw:numa_cpus.1= - mapping of vCPUS N-M to NUMA node 1
    • hw:numa_mem.0= - mapping N GB of RAM to NUMA node 0
    • hw:numa_mem.1= - mapping N GB of RAM to NUMA node 1
  • vCPUs与pCPUs的绑定,更多查看[vcpu与pcpu的绑定Virt driver pinning guest vCPUs to host pCPUs
    • hw:cpu_policy=shared|dedicated
    • hw:cpu_threads_policy=avoid|separate|isolate|prefer, 只有hw:cpu_policy为dedicated时本属性才生效
      • avoid: the scheduler will not place the guest on a host which has hyperthreads.
      • separate: if the host has threads, each vCPU will be placed on a different core. ie no two vCPUs will be placed on thread siblings
      • isolate: if the host has threads, each vCPU will be placed on a different core and no vCPUs from other guests will be able to be placed on the same core. ie one thread sibling is guaranteed to always be unused,
      • prefer: if the host has threads, vCPU will be placed on the same core, so they are thread siblings.

举例(未验证)

管理员可以设置flavor的元数据来控制vm行为.

nova flavor-key m1.large set hw:numa_mempolicy=strict hw:numa_cpus.0=0,1,2,3 hw:numa_cpus.1=4,5,6,7 hw:numa_mem.0=1 hw:numa_mem.1=1 hw:cpu_policy=decicated hw:cpu_threads_policy=separate 

用户可以自己设置image元数据来达到定制需求,当然flavor的元数据优先级是高于image优先级的.

glance image-update image_id –property hw_numa_mempolicy=strict –property hw_numa_cpus.0=0,1,2,3 –property hw_numa_cpus.1=4,5,6,7 –property hw_numa_mem.0=1 –property hw_numa_mem.1=1 --property hw_cpu_policy=decicated --property hw_cpu_threads_policy=separate 

上面的例子中,cpu的绑定hw:cpu_threads_policy参数其实是不起作用的,到M版代码中也没有相关实现.如果cpu_policy=decicated时,host开启超线程,相关vcpu会绑定在同一个core的threads上, 这样的绑定方式会导致vm性能很差, Be careful! 官方文档有的时候很坑……

参考文档

  1. Pinning processors by common threads and cores
  2. https://wiki.openstack.org/wiki/VirtDriverGuestCPUMemoryPlacement

openStack cpu绑定的更多相关文章

  1. OpenStack Nova 高性能虚拟机之 CPU 绑定

    目录 文章目录 目录 前文列表 KVM KVM 的功能列表 KVM 工具集 KVM 虚拟机的本质是什么 vCPU 的调度与性能问题 Nova 支持的 vCPU 绑定 vcpu\_pin\_set 配置 ...

  2. CPU绑定操作

    使用virsh vcpuinfp命令查看虚拟机VCPU和物理CPU的对应关系 [root@svn ~]# virsh vcpuinfo 16 VCPU: 0 CPU: 3 状态: running CP ...

  3. NGINX源代码剖析 之 CPU绑定(CPU亲和性)

    作者:邹祁峰 邮箱:Qifeng.zou.job@gmail.com 博客:http://blog.csdn.net/qifengzou 日期:2014.06.12 18:44 转载请注明来自&quo ...

  4. openstack cpu pinning

    为了减少CPU竞争,提高CPU cache命中率,可以把guest的vcpu pin到host的物理CPU上. 在openstack中,可以添加以下到flavor extra specs: hw:cp ...

  5. KVM虚拟机CPU绑定性能调优(宿主机上操作)

    获取kvm的pid ps -ef | grep kvm 通过pid找到vcpu在那个物理cpu上,没有绑定固定物理cpu时,执行下面命令可以看出vcpu在不同的物理cpu上切换重复执行 ps -eLo ...

  6. linux下使用taskset设置进程cpu绑定不起作用

    自从大规模使用了虚拟化之后,大流量时soft interrupt在某个cpu很高就是个严重的问题,最近一有时间就研究这个问题,如果网卡本身不支持多队列的话,有没有办法缓解这个问题. 一开始使用rps, ...

  7. 进程和cpu绑定

    #include<stdlib.h> #include<stdio.h> #include<sys/types.h> #include<sys/sysinfo ...

  8. KVM虚拟机绑定物理CPU进行性能调优

    PS:前提是虚拟cpu总个数不多于物理cpu总个数.   绑定方法: 虚拟机的虚拟cpu有1个,实体机物理cpu有8个,可以通过以下方式绑定cpu,绑定的动作不一定要在虚机启动时,可以在任何时候: 绑 ...

  9. [Linux 性能调优] 网卡中断与CPU的绑定问题

    在Linux的网络调优方面,如果你发现网络流量上不去,那么有一个方面需要去查一下:网卡处理网络请求的中断是否被绑定到单个CPU(或者说跟处理其它中断的是同一个CPU). 先说一下背景 网卡与操作系统的 ...

随机推荐

  1. HD-SDI制式学习

    HD-SDI制式学习 1.资料来源(XAPP514) 2.HD-SDI相关知识 需要注意的是每一行的开始为EAV,序列依次为:EAV Blank Video 3.XYZ的格式 4.Line numbe ...

  2. selenium phantomjs 设置代理ip方法

    最近遇到phantomjs动态更换ip的功能,在知乎上看到一篇不错的文章,顺手记下来以备后用 phantomjs selenium 如何动态修改代理? 可以这样做(Python代码): # 不使用代理 ...

  3. dubbo-admin在jdk8下不兼容

    参考这里 修改pom.xml webx的依赖改为3..6版 <dependency> <groupId>com.alibaba.citrus</groupId> & ...

  4. 让Netbeans 8.0 支持 Python 编程

    发布人 admin. 分类 Python, 技术手札 Netbeans版本:Netbeans 8.0 for PHP Python版本:python 2.7.8 1.添加插件更新中心 打开Netbea ...

  5. c#读取Sybase中文乱码的解决办法

    最近需要从Sybase数据库中获取数据.用Sybase.Data.AseClient连接的话比较简单,但中文数据会有乱码.用Sybase自带的工具SQL Advantage设置好编码和语言,是可以正常 ...

  6. <亲测>window+iis+letsencrypt+ssl 手动续期(通配符域名)

    之前提到过 window环境下 生成ssl通配符域名证方法为:https://www.cnblogs.com/duanweishi/p/9491209.html    下文为在window环境下手动续 ...

  7. 【ActiveMQ】之安全机制(一)管控台安全设置

    ActiveMQ 管控台基于jetty,默认端口8161,默认用户名,密码都是admin,这样的安全配置过于弱化,所以我们需要修改一下 1.修改端口 找到conf/jetty.xml文件里面这一段配置 ...

  8. git撤销本地所有未提交的更改

    1. git clean -df2. git reset --hard第一个命令只删除所有untracked的文件,如果文件已经被tracked, 修改过的文件不会被回退.而第二个命令把tracked ...

  9. VS2012 创建的entityframework 4.1版本

    起因:部署网站提示错误“Method not found: 'Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullRe ...

  10. whith ~ as 用法

    个人理解 with self.client.get("/", catch_response=True) as response: 其实就是 response = self.clie ...