Provides interfaces for setting/getting memory tunables like hard_limit,
soft_limit and swap_hard_limit
Signed-off-by: Nikunj A. Dadhania <nikunj(a)linux.vnet.ibm.com>
---
src/libvirt_private.syms | 6 +++
src/util/cgroup.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++
src/util/cgroup.h | 7 +++
3 files changed, 119 insertions(+), 0 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c2905ba..038dd77 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -77,6 +77,12 @@ virCgroupControllerTypeFromString;
virCgroupGetCpuacctUsage;
virCgroupGetFreezerState;
virCgroupSetFreezerState;
+virCgroupSetMemoryHardLimit;
+virCgroupGetMemoryHardLimit;
+virCgroupSetMemorySoftLimit;
+virCgroupGetMemorySoftLimit;
+virCgroupSetSwapHardLimit;
+virCgroupGetSwapHardLimit;
# cpu.h
diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index 024036a..f94db12 100644
--- a/src/util/cgroup.c
+++ b/src/util/cgroup.c
@@ -874,6 +874,112 @@ int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb)
}
/**
+ * 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:
*
* @group: The cgroup to deny devices for
diff --git a/src/util/cgroup.h b/src/util/cgroup.h
index 2bea49f..b8f2d08 100644
--- a/src/util/cgroup.h
+++ b/src/util/cgroup.h
@@ -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,