mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
Implement cgroup memory controller tunables
Provides interfaces for setting/getting memory tunables like hard_limit, soft_limit and swap_hard_limit
This commit is contained in:
parent
d390fce413
commit
5f481e4df1
@ -77,6 +77,12 @@ virCgroupControllerTypeFromString;
|
|||||||
virCgroupGetCpuacctUsage;
|
virCgroupGetCpuacctUsage;
|
||||||
virCgroupGetFreezerState;
|
virCgroupGetFreezerState;
|
||||||
virCgroupSetFreezerState;
|
virCgroupSetFreezerState;
|
||||||
|
virCgroupSetMemoryHardLimit;
|
||||||
|
virCgroupGetMemoryHardLimit;
|
||||||
|
virCgroupSetMemorySoftLimit;
|
||||||
|
virCgroupGetMemorySoftLimit;
|
||||||
|
virCgroupSetSwapHardLimit;
|
||||||
|
virCgroupGetSwapHardLimit;
|
||||||
|
|
||||||
|
|
||||||
# cpu.h
|
# cpu.h
|
||||||
|
@ -873,6 +873,112 @@ int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb)
|
|||||||
return ret;
|
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:
|
* virCgroupDenyAllDevices:
|
||||||
*
|
*
|
||||||
|
@ -43,6 +43,13 @@ int virCgroupAddTask(virCgroupPtr group, pid_t pid);
|
|||||||
int virCgroupSetMemory(virCgroupPtr group, unsigned long kb);
|
int virCgroupSetMemory(virCgroupPtr group, unsigned long kb);
|
||||||
int virCgroupGetMemoryUsage(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 virCgroupDenyAllDevices(virCgroupPtr group);
|
||||||
|
|
||||||
int virCgroupAllowDevice(virCgroupPtr group,
|
int virCgroupAllowDevice(virCgroupPtr group,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user