提交 5f481e4d 编写于 作者: N Nikunj A. Dadhania 提交者: Daniel Veillard

Implement cgroup memory controller tunables

Provides interfaces for setting/getting memory tunables like hard_limit,
soft_limit and swap_hard_limit
上级 d390fce4
......@@ -77,6 +77,12 @@ virCgroupControllerTypeFromString;
virCgroupGetCpuacctUsage;
virCgroupGetFreezerState;
virCgroupSetFreezerState;
virCgroupSetMemoryHardLimit;
virCgroupGetMemoryHardLimit;
virCgroupSetMemorySoftLimit;
virCgroupGetMemorySoftLimit;
virCgroupSetSwapHardLimit;
virCgroupGetSwapHardLimit;
# cpu.h
......
......@@ -873,6 +873,112 @@ int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb)
return ret;
}
/**
* virCgroupSetMemoryHardLimit:
*
* @group: The cgroup to change memory hard limit for
* @kb: The memory amount in kilobytes
*
* Returns: 0 on success
*/
int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long kb)
{
return virCgroupSetMemory(group, kb);
}
/**
* virCgroupGetMemoryHardLimit:
*
* @group: The cgroup to get the memory hard limit for
* @kb: The memory amount in kilobytes
*
* Returns: 0 on success
*/
int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long *kb)
{
long long unsigned int limit_in_bytes;
int ret;
ret = virCgroupGetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.limit_in_bytes", &limit_in_bytes);
if (ret == 0)
*kb = (unsigned long) limit_in_bytes >> 10;
return ret;
}
/**
* virCgroupSetMemorySoftLimit:
*
* @group: The cgroup to change memory soft limit for
* @kb: The memory amount in kilobytes
*
* Returns: 0 on success
*/
int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long kb)
{
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.soft_limit_in_bytes",
kb << 10);
}
/**
* virCgroupGetMemorySoftLimit:
*
* @group: The cgroup to get the memory soft limit for
* @kb: The memory amount in kilobytes
*
* Returns: 0 on success
*/
int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long *kb)
{
long long unsigned int limit_in_bytes;
int ret;
ret = virCgroupGetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.soft_limit_in_bytes", &limit_in_bytes);
if (ret == 0)
*kb = (unsigned long) limit_in_bytes >> 10;
return ret;
}
/**
* virCgroupSetSwapHardLimit:
*
* @group: The cgroup to change swap hard limit for
* @kb: The swap amount in kilobytes
*
* Returns: 0 on success
*/
int virCgroupSetSwapHardLimit(virCgroupPtr group, unsigned long kb)
{
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.memsw.limit_in_bytes",
kb << 10);
}
/**
* virCgroupGetSwapHardLimit:
*
* @group: The cgroup to get swap hard limit for
* @kb: The swap amount in kilobytes
*
* Returns: 0 on success
*/
int virCgroupGetSwapHardLimit(virCgroupPtr group, unsigned long *kb)
{
long long unsigned int limit_in_bytes;
int ret;
ret = virCgroupGetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.memsw.limit_in_bytes", &limit_in_bytes);
if (ret == 0)
*kb = (unsigned long) limit_in_bytes >> 10;
return ret;
}
/**
* virCgroupDenyAllDevices:
*
......
......@@ -43,6 +43,13 @@ int virCgroupAddTask(virCgroupPtr group, pid_t pid);
int virCgroupSetMemory(virCgroupPtr group, unsigned long kb);
int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb);
int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long kb);
int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long *kb);
int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long kb);
int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long *kb);
int virCgroupSetSwapHardLimit(virCgroupPtr group, unsigned long kb);
int virCgroupGetSwapHardLimit(virCgroupPtr group, unsigned long *kb);
int virCgroupDenyAllDevices(virCgroupPtr group);
int virCgroupAllowDevice(virCgroupPtr group,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册