内存
struct _virDomainDef {
     ...
    struct {
        unsigned long max_balloon;  
        unsigned long cur_balloon;  
        unsigned long hugepage_backed;
        unsigned long hard_limit;
        unsigned long soft_limit;
        unsigned long min_guarantee;
        unsigned long swap_hard_limit;
    } mem;
    ...
}
 
选项:
1. hard_limit:  ---> memory.limit_in_bytes
it represents the maximum memory the guest can use.
guest能使用的最大内存
 
2. soft_limit  ---> memory.soft_limit_in_bytes
it represents the memory upper limit enforced during memory contention.
内存紧张时的保证。
比如:1G内存的物理主机,我们分配两个虚拟机器,设置hard_limit均为600M。但这样如果在资源紧张时就傻逼了。
需要设置soft_limit=500M,保证最多只有这么多内存可被用。
 
3. min_guarantee ---> 
it represents the minimum  memory guaranteed to be reserved for the guest
注:lxc未设置这个
 
4. swap_hard_limit  ---> memory.memsw.limit_in_bytes
 it represents the maximum swap plus memory the guest can use. This limit has to be more than
 
接口:
virDomainSetMemoryParameters: 
virDomainGetMemoryParameters
lxc实现: lxcDomainSetMemoryParameters lxcDomainGetMemoryParameters{
     根本不同的参数,设置或者获取hard_limit, soft_limit, swap_hard_limit  的值  
}
 
 
virDomainSetMemory:(不停用虚拟机的情况下动态增加内存的使用值)
Dynamically change the target amount of physical memory allocated to a domain.
在lxc的实现中,就是设置:memory.limit_in_bytes的值,跟hard_limit一致
 
virDomainSetMaxMemory:
Dynamically change the maximum amount of physical memory allocated to a domain
在lxc的实现中lxcDomainSetMaxMemory{ // 这个地方跟接口语义不太符合
if (newmax < vm->def->mem.cur_balloon) {
        lxcError(VIR_ERR_INVALID_ARG,
                         "%s", _("Cannot set max memory lower than current memory"));
        goto cleanup;
    }

vm->def->mem.max_balloon = newmax; // 这个值没有回写到cgroup中,而是用来在lxcDomainSetMemory中作做判断用

}
xml中的配置选项:
<memory>286954</memory> 这个参数必须有,不然启动不成功
<memtune>
    <hard_limit>1048576</hard_limit>
    <soft_limit>131072</soft_limit>
    <swap_hard_limit>2097152</swap_hard_limit>
    <min_guarantee>65536</min_guarantee> #对lx无效
  </memtune>
lxc相关:
我们直接用virDomainSetMemoryParameters来控制参数, virDomainSetMemory之类不好用。
总结:lxc中需要配置的参数:
hard_limit,soft_limit,swap_hard_limit   
可 以通过virDomainSetMemory动态增加内存,但增加不能超过max_balloon的值,所以,当增加的内存指超过max_balloon 的时候,需要先调用virDomainSetMaxMemory增加内存,然后再调用virDomainSetMemory
Python接口:
CPU
 
CGROUP主要设置参数
cpu.shares
cpuset.cpus
 
选项:
struct _virDomainDef {
unsigned short vcpus;
unsigned short maxvcpus;
    int cpumasklen;
    char *cpumask;

struct {
        unsigned long shares;
        int nvcpupin;
        virDomainVcpupinDefPtr *vcpupin;
    } cputune;

}
 
 
相关接口:
_virSchedParameter
virDomainGetSchedulerParameters
virDomainSetSchedulerParameters
Python接口:
/**
* virDomainGetMaxVcpus:
* @domain: pointer to domain object
*
* Provides the maximum number of virtual CPUs supported for
* the guest VM. If the guest is inactive, this is basically
* the same as virConnectGetMaxVcpus(). If the guest is running
* this will reflect the maximum number of virtual CPUs the
* guest was booted with.  For more details, see virDomainGetVcpusFlags().
*
* Returns the maximum of virtual CPU or -1 in case of error.
*/
virDomainGetMaxVcpus():
/**
* virDomainSetVcpus:
* @domain: pointer to domain object, or NULL for Domain0
* @nvcpus: the new number of virtual CPUs for this domain
*
* Dynamically change the number of virtual CPUs used by the domain.
* Note that this call may fail if the underlying virtualization hypervisor
* does not support it or if growing the number is arbitrary limited.
* This function requires privileged access to the hypervisor.
*
* This command only changes the runtime configuration of the domain,
* so can only be called on an active domain.  It is hypervisor-dependent
* whether it also affects persistent configuration; for more control,
* use virDomainSetVcpusFlags().
*
* Returns 0 in case of success, -1 in case of failure.
*/
virDomainSetVcpus()
virDomainGetVcpusFlags/virDomainSetVcpusFlags()
/**
* virDomainPinVcpu:
* @domain: pointer to domain object, or NULL for Domain0
* @vcpu: virtual CPU number
* @cpumap: pointer to a bit map of real CPUs (in 8-bit bytes) (IN)
*      Each bit set to 1 means that corresponding CPU is usable.
*      Bytes are stored in little-endian order: CPU0-7, 8-15...
*      In each byte, lowest CPU number is least significant bit.
* @maplen: number of bytes in cpumap, from 1 up to size of CPU map in
*     underlying virtualization system (Xen...).
*     If maplen < size, missing bytes are set to zero.
*     If maplen > size, failure code is returned.
*
* Dynamically change the real CPUs which can be allocated to a virtual CPU.
* This function requires privileged access to the hypervisor.
*
* This command only changes the runtime configuration of the domain,
* so can only be called on an active domain.
*
* Returns 0 in case of success, -1 in case of failure.
*/
virDomainPinVcpu()
以上接口lxc均为实现
virDomainGetSchedulerType()
lxc实现:lxcGetSchedulerType{
schedulerType = strdup("posix"); 
return schedulerType; // 简单地返回,不知道有什么鸟用
}
/*
*
*/
virDomainSetSchedulerParameters()
lxc实现:
virDomainGetSchedulerParameters()
virCgroupCpuSetInherit
xml中的配置选项:
<cputune>
    <vcpupin vcpu="0" cpuset="1-4,^2"/>
    <vcpupin vcpu="1" cpuset="0,1"/>
    <vcpupin vcpu="2" cpuset="2,3"/>
    <vcpupin vcpu="3" cpuset="0,4"/>
    <cpushares>2048</cpushares> 
/*应该是shares,而不是cpushares (virXPathULong("string(./cputune/shares[1])", ctxt, 文档中这个地方时有错误的*/
  </cputune>

[zz]libvirt中CPU和内存的细粒度管理机制相关推荐

  1. linux监测cpu 内存,Linux中CPU与内存性能监测.docx

    Linux中CPU与内存性能监测(出处://chenleixing/article/details 在系统维护的过程中,随时可能有需要查看 CPU 使用率内存使用情况的需要,尤其是涉及到JVM,程序调 ...

  2. 计算机中cpu是不是内存,电脑卡是cpu还是内存

    大家好,我是时间财富网智能客服时间君,上述问题将由我为大家进行解答. 电脑卡和CPU.内存都有关系,可能是CPU性能过低,需要更换性能更好的CPU.也可能是内存太小,需要升级内存. 中央处理器(CPU ...

  3. 【好书摘要】性能优化中CPU、内存、磁盘IO、网络性能的依赖

    系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长期和持续的过程,不 是说现在优化了,测试了,以后就可以一劳永逸了,也不是说书本上 ...

  4. Linux中CPU与内存性能监测

    在系统维护的过程中,随时可能有需要查看 CPU 使用率内存使用情况的需要,尤其是涉及到JVM,程序调优的情况,并根据相应信息分析系统状况的需要. top命令 top命令是Linux下常用的性能分析工具 ...

  5. 【Android】获取当前的app中cpu和内存的百分比 -调研报告

    背景 项目要求获取当前app运行时的cpu和内存状况. 调研 CPU获取 Android实现获取当前的app的cpu实时使用情况的代码 以下是获取当前app的CPU实时使用情况的代码(Java): p ...

  6. Linux中CPU和内存使用情况查看

    vmstat命令可以查看系统整体的cpu,内存的使用情况 [root@izuf643wxgfg kk_bak]# vmstat -t 1 r: 表示系统中 CPU 等待处理的线程.由于 CPU 每次只 ...

  7. cpu缓冲区大小怎么设置_linux中cpu、内存、磁盘使用情况检查及处理

    第一部分:查看cpu使用情况 1.查看物理cpu个数 grep 'physical id' /proc/cpuinfo 2.查看cpu核心数 grep 'core id' /proc/cpuinfo ...

  8. linux系统限制内存使用率,linux中限制CPU和内存占用率方法

    在linux中CPU与内存占用率限制的方法有几种我这里整理常用的两种,希望文章对各位同学会有所帮助哦. 查看cpu占用 在命令行中输入 "top" 即可启动 top top 的全屏 ...

  9. Linux内存管理机制(最透彻的一篇)

    摘要:本章首先以应用程序开发者的角度审视Linux的进程内存管理,在此基础上逐步深入到内核中讨论系统物理内存管理和内核内存的使用方法.力求从外到内.水到渠成地引导网友分析Linux的内存管理与使用.在 ...

最新文章

  1. Pandas库常用函数和操作
  2. jsp常见获取地址函数之间的不同
  3. Java多线程相关的常用接口
  4. LeetCode每日一题: 缺失数字(No.268)
  5. .Net Core WebAPI + Axios +Vue 实现下载与下载进度条
  6. redis 简单应用
  7. 怎么复活不了睡袋_测评 | 萌新的北京冬季户外睡袋初体验
  8. Oracle数据库的ORA-00257故障解决过程(转载)
  9. 简单小爬虫爬取招标信息
  10. 雷达通信术语中英文对照
  11. java forward方法_JAVA的服务重定向:使用forward()方法转发请求和使用sendRedirect()方法重定向的区别...
  12. OAS、Swagger和Springfox
  13. Bandizip6.27百度网盘
  14. Linux下oracle 数据库表空间、用户的创建,数据的导入导出操作指南
  15. LNMP环境搭建之编译安装指南(php-5.3.27.tar.gz)
  16. Domino内置备份功能妙用
  17. 这样print才够劲!
  18. 输出电容的ESR对DC_DC的影响——电感发烫排查思路
  19. 对今天知识的回顾15
  20. 希捷服务器硬盘15k有几代,硬盘巨头推最后一代15k机械硬盘:再见,机械硬盘

热门文章

  1. 企业IM-1功能需求
  2. 《深入理解Spark:核心思想与源码分析》——1.2节Spark初体验
  3. Sql 某一字段统计
  4. 集合 判断是否为同一元素 总结
  5. 京东首页302 Found报错 监控宝教你如何第一时间发现
  6. jQuery可悬停控制图片轮播
  7. 在Eclipse中使用JUnit4进行单元测试
  8. 陶哲轩实分析 习题 13.5.6
  9. [转载] 百科全说——何裕民:性格影响疾病(10-12-20)
  10. outlook express 邮件超过2G时的解决方法