mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 05:17:59 +03: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;
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user