|
|
c480ed |
From 5101d214a63b31847f80048d4ee34b5e62176ddd Mon Sep 17 00:00:00 2001
|
|
|
c480ed |
Message-Id: <5101d214a63b31847f80048d4ee34b5e62176ddd@dist-git>
|
|
|
c480ed |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
Date: Mon, 1 Jul 2019 17:06:52 +0200
|
|
|
c480ed |
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)Memory*Limit
|
|
|
c480ed |
MIME-Version: 1.0
|
|
|
c480ed |
Content-Type: text/plain; charset=UTF-8
|
|
|
c480ed |
Content-Transfer-Encoding: 8bit
|
|
|
c480ed |
|
|
|
c480ed |
They all need virCgroupV1GetMemoryUnlimitedKB() so it's easier to
|
|
|
c480ed |
move them in one commit.
|
|
|
c480ed |
|
|
|
c480ed |
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
|
|
|
c480ed |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c480ed |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
(cherry picked from commit 900c58b7f963d5054921e31bbd0b6005155b284a)
|
|
|
c480ed |
|
|
|
c480ed |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
|
|
|
c480ed |
|
|
|
c480ed |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
Message-Id: <c85e4973bb1718a5c9a36f971f9544b46b213183.1561993100.git.phrdina@redhat.com>
|
|
|
c480ed |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c480ed |
---
|
|
|
c480ed |
src/util/vircgroup.c | 128 ++-------------------------
|
|
|
c480ed |
src/util/vircgroupbackend.h | 30 +++++++
|
|
|
c480ed |
src/util/vircgrouppriv.h | 6 ++
|
|
|
c480ed |
src/util/vircgroupv1.c | 168 ++++++++++++++++++++++++++++++++++++
|
|
|
c480ed |
4 files changed, 211 insertions(+), 121 deletions(-)
|
|
|
c480ed |
|
|
|
c480ed |
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
|
|
|
c480ed |
index ed7252243c..6708eef0da 100644
|
|
|
c480ed |
--- a/src/util/vircgroup.c
|
|
|
c480ed |
+++ b/src/util/vircgroup.c
|
|
|
c480ed |
@@ -634,7 +634,7 @@ virCgroupMakeGroup(virCgroupPtr parent,
|
|
|
c480ed |
*
|
|
|
c480ed |
* Returns 0 on success, -1 on error
|
|
|
c480ed |
*/
|
|
|
c480ed |
-static int
|
|
|
c480ed |
+int
|
|
|
c480ed |
virCgroupNew(pid_t pid,
|
|
|
c480ed |
const char *path,
|
|
|
c480ed |
virCgroupPtr parent,
|
|
|
c480ed |
@@ -1537,51 +1537,6 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group,
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
-/*
|
|
|
c480ed |
- * Retrieve the "memory.limit_in_bytes" value from the memory controller
|
|
|
c480ed |
- * root dir. This value cannot be modified by userspace and therefore
|
|
|
c480ed |
- * is the maximum limit value supported by cgroups on the local system.
|
|
|
c480ed |
- * Returns this value scaled to KB or falls back to the original
|
|
|
c480ed |
- * VIR_DOMAIN_MEMORY_PARAM_UNLIMITED. Either way, remember the return
|
|
|
c480ed |
- * value to avoid unnecessary cgroup filesystem access.
|
|
|
c480ed |
- */
|
|
|
c480ed |
-static unsigned long long int virCgroupMemoryUnlimitedKB;
|
|
|
c480ed |
-static virOnceControl virCgroupMemoryOnce = VIR_ONCE_CONTROL_INITIALIZER;
|
|
|
c480ed |
-
|
|
|
c480ed |
-static void
|
|
|
c480ed |
-virCgroupMemoryOnceInit(void)
|
|
|
c480ed |
-{
|
|
|
c480ed |
- virCgroupPtr group;
|
|
|
c480ed |
- unsigned long long int mem_unlimited = 0ULL;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virCgroupNew(-1, "/", NULL, -1, &group) < 0)
|
|
|
c480ed |
- goto cleanup;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (!virCgroupHasController(group, VIR_CGROUP_CONTROLLER_MEMORY))
|
|
|
c480ed |
- goto cleanup;
|
|
|
c480ed |
-
|
|
|
c480ed |
- ignore_value(virCgroupGetValueU64(group,
|
|
|
c480ed |
- VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
- "memory.limit_in_bytes",
|
|
|
c480ed |
- &mem_unlimited));
|
|
|
c480ed |
- cleanup:
|
|
|
c480ed |
- virCgroupFree(&group);
|
|
|
c480ed |
- virCgroupMemoryUnlimitedKB = mem_unlimited >> 10;
|
|
|
c480ed |
-}
|
|
|
c480ed |
-
|
|
|
c480ed |
-static unsigned long long int
|
|
|
c480ed |
-virCgroupGetMemoryUnlimitedKB(void)
|
|
|
c480ed |
-{
|
|
|
c480ed |
- if (virOnce(&virCgroupMemoryOnce, virCgroupMemoryOnceInit) < 0)
|
|
|
c480ed |
- VIR_DEBUG("Init failed, will fall back to defaults.");
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virCgroupMemoryUnlimitedKB)
|
|
|
c480ed |
- return virCgroupMemoryUnlimitedKB;
|
|
|
c480ed |
- else
|
|
|
c480ed |
- return VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
-}
|
|
|
c480ed |
-
|
|
|
c480ed |
-
|
|
|
c480ed |
/**
|
|
|
c480ed |
* virCgroupSetMemory:
|
|
|
c480ed |
*
|
|
|
c480ed |
@@ -1652,7 +1607,7 @@ virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb)
|
|
|
c480ed |
int
|
|
|
c480ed |
virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb)
|
|
|
c480ed |
{
|
|
|
c480ed |
- return virCgroupSetMemory(group, kb);
|
|
|
c480ed |
+ VIR_CGROUP_BACKEND_CALL(group, setMemoryHardLimit, -1, kb);
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
@@ -1667,18 +1622,7 @@ virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb)
|
|
|
c480ed |
int
|
|
|
c480ed |
virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb)
|
|
|
c480ed |
{
|
|
|
c480ed |
- long long unsigned int limit_in_bytes;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virCgroupGetValueU64(group,
|
|
|
c480ed |
- VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
- "memory.limit_in_bytes", &limit_in_bytes) < 0)
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
-
|
|
|
c480ed |
- *kb = limit_in_bytes >> 10;
|
|
|
c480ed |
- if (*kb >= virCgroupGetMemoryUnlimitedKB())
|
|
|
c480ed |
- *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
-
|
|
|
c480ed |
- return 0;
|
|
|
c480ed |
+ VIR_CGROUP_BACKEND_CALL(group, getMemoryHardLimit, -1, kb);
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
@@ -1693,25 +1637,7 @@ virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb)
|
|
|
c480ed |
int
|
|
|
c480ed |
virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb)
|
|
|
c480ed |
{
|
|
|
c480ed |
- unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (kb > maxkb) {
|
|
|
c480ed |
- virReportError(VIR_ERR_INVALID_ARG,
|
|
|
c480ed |
- _("Memory '%llu' must be less than %llu"),
|
|
|
c480ed |
- kb, maxkb);
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (kb == maxkb)
|
|
|
c480ed |
- return virCgroupSetValueI64(group,
|
|
|
c480ed |
- VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
- "memory.soft_limit_in_bytes",
|
|
|
c480ed |
- -1);
|
|
|
c480ed |
- else
|
|
|
c480ed |
- return virCgroupSetValueU64(group,
|
|
|
c480ed |
- VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
- "memory.soft_limit_in_bytes",
|
|
|
c480ed |
- kb << 10);
|
|
|
c480ed |
+ VIR_CGROUP_BACKEND_CALL(group, setMemorySoftLimit, -1, kb);
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
@@ -1726,18 +1652,7 @@ virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb)
|
|
|
c480ed |
int
|
|
|
c480ed |
virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb)
|
|
|
c480ed |
{
|
|
|
c480ed |
- long long unsigned int limit_in_bytes;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virCgroupGetValueU64(group,
|
|
|
c480ed |
- VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
- "memory.soft_limit_in_bytes", &limit_in_bytes) < 0)
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
-
|
|
|
c480ed |
- *kb = limit_in_bytes >> 10;
|
|
|
c480ed |
- if (*kb >= virCgroupGetMemoryUnlimitedKB())
|
|
|
c480ed |
- *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
-
|
|
|
c480ed |
- return 0;
|
|
|
c480ed |
+ VIR_CGROUP_BACKEND_CALL(group, getMemorySoftLimit, -1, kb);
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
@@ -1752,25 +1667,7 @@ virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb)
|
|
|
c480ed |
int
|
|
|
c480ed |
virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb)
|
|
|
c480ed |
{
|
|
|
c480ed |
- unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (kb > maxkb) {
|
|
|
c480ed |
- virReportError(VIR_ERR_INVALID_ARG,
|
|
|
c480ed |
- _("Memory '%llu' must be less than %llu"),
|
|
|
c480ed |
- kb, maxkb);
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (kb == maxkb)
|
|
|
c480ed |
- return virCgroupSetValueI64(group,
|
|
|
c480ed |
- VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
- "memory.memsw.limit_in_bytes",
|
|
|
c480ed |
- -1);
|
|
|
c480ed |
- else
|
|
|
c480ed |
- return virCgroupSetValueU64(group,
|
|
|
c480ed |
- VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
- "memory.memsw.limit_in_bytes",
|
|
|
c480ed |
- kb << 10);
|
|
|
c480ed |
+ VIR_CGROUP_BACKEND_CALL(group, setMemSwapHardLimit, -1, kb);
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
@@ -1785,18 +1682,7 @@ virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb)
|
|
|
c480ed |
int
|
|
|
c480ed |
virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb)
|
|
|
c480ed |
{
|
|
|
c480ed |
- long long unsigned int limit_in_bytes;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virCgroupGetValueU64(group,
|
|
|
c480ed |
- VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
- "memory.memsw.limit_in_bytes", &limit_in_bytes) < 0)
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
-
|
|
|
c480ed |
- *kb = limit_in_bytes >> 10;
|
|
|
c480ed |
- if (*kb >= virCgroupGetMemoryUnlimitedKB())
|
|
|
c480ed |
- *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
-
|
|
|
c480ed |
- return 0;
|
|
|
c480ed |
+ VIR_CGROUP_BACKEND_CALL(group, getMemSwapHardLimit, -1, kb);
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
|
|
|
c480ed |
index 8bdfc5c835..cdbca4b907 100644
|
|
|
c480ed |
--- a/src/util/vircgroupbackend.h
|
|
|
c480ed |
+++ b/src/util/vircgroupbackend.h
|
|
|
c480ed |
@@ -227,6 +227,30 @@ typedef int
|
|
|
c480ed |
(*virCgroupGetMemoryUsageCB)(virCgroupPtr group,
|
|
|
c480ed |
unsigned long *kb);
|
|
|
c480ed |
|
|
|
c480ed |
+typedef int
|
|
|
c480ed |
+(*virCgroupSetMemoryHardLimitCB)(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long kb);
|
|
|
c480ed |
+
|
|
|
c480ed |
+typedef int
|
|
|
c480ed |
+(*virCgroupGetMemoryHardLimitCB)(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long *kb);
|
|
|
c480ed |
+
|
|
|
c480ed |
+typedef int
|
|
|
c480ed |
+(*virCgroupSetMemorySoftLimitCB)(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long kb);
|
|
|
c480ed |
+
|
|
|
c480ed |
+typedef int
|
|
|
c480ed |
+(*virCgroupGetMemorySoftLimitCB)(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long *kb);
|
|
|
c480ed |
+
|
|
|
c480ed |
+typedef int
|
|
|
c480ed |
+(*virCgroupSetMemSwapHardLimitCB)(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long kb);
|
|
|
c480ed |
+
|
|
|
c480ed |
+typedef int
|
|
|
c480ed |
+(*virCgroupGetMemSwapHardLimitCB)(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long *kb);
|
|
|
c480ed |
+
|
|
|
c480ed |
struct _virCgroupBackend {
|
|
|
c480ed |
virCgroupBackendType type;
|
|
|
c480ed |
|
|
|
c480ed |
@@ -269,6 +293,12 @@ struct _virCgroupBackend {
|
|
|
c480ed |
virCgroupSetMemoryCB setMemory;
|
|
|
c480ed |
virCgroupGetMemoryStatCB getMemoryStat;
|
|
|
c480ed |
virCgroupGetMemoryUsageCB getMemoryUsage;
|
|
|
c480ed |
+ virCgroupSetMemoryHardLimitCB setMemoryHardLimit;
|
|
|
c480ed |
+ virCgroupGetMemoryHardLimitCB getMemoryHardLimit;
|
|
|
c480ed |
+ virCgroupSetMemorySoftLimitCB setMemorySoftLimit;
|
|
|
c480ed |
+ virCgroupGetMemorySoftLimitCB getMemorySoftLimit;
|
|
|
c480ed |
+ virCgroupSetMemSwapHardLimitCB setMemSwapHardLimit;
|
|
|
c480ed |
+ virCgroupGetMemSwapHardLimitCB getMemSwapHardLimit;
|
|
|
c480ed |
};
|
|
|
c480ed |
typedef struct _virCgroupBackend virCgroupBackend;
|
|
|
c480ed |
typedef virCgroupBackend *virCgroupBackendPtr;
|
|
|
c480ed |
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
|
|
|
c480ed |
index 3a968c1ce2..7b985280e1 100644
|
|
|
c480ed |
--- a/src/util/vircgrouppriv.h
|
|
|
c480ed |
+++ b/src/util/vircgrouppriv.h
|
|
|
c480ed |
@@ -88,6 +88,12 @@ int virCgroupGetValueForBlkDev(virCgroupPtr group,
|
|
|
c480ed |
const char *path,
|
|
|
c480ed |
char **value);
|
|
|
c480ed |
|
|
|
c480ed |
+int virCgroupNew(pid_t pid,
|
|
|
c480ed |
+ const char *path,
|
|
|
c480ed |
+ virCgroupPtr parent,
|
|
|
c480ed |
+ int controllers,
|
|
|
c480ed |
+ virCgroupPtr *group);
|
|
|
c480ed |
+
|
|
|
c480ed |
int virCgroupNewPartition(const char *path,
|
|
|
c480ed |
bool create,
|
|
|
c480ed |
int controllers,
|
|
|
c480ed |
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
|
|
|
c480ed |
index 4f1d79a758..779288fb97 100644
|
|
|
c480ed |
--- a/src/util/vircgroupv1.c
|
|
|
c480ed |
+++ b/src/util/vircgroupv1.c
|
|
|
c480ed |
@@ -1378,6 +1378,51 @@ virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group,
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
+/*
|
|
|
c480ed |
+ * Retrieve the "memory.limit_in_bytes" value from the memory controller
|
|
|
c480ed |
+ * root dir. This value cannot be modified by userspace and therefore
|
|
|
c480ed |
+ * is the maximum limit value supported by cgroups on the local system.
|
|
|
c480ed |
+ * Returns this value scaled to KB or falls back to the original
|
|
|
c480ed |
+ * VIR_DOMAIN_MEMORY_PARAM_UNLIMITED. Either way, remember the return
|
|
|
c480ed |
+ * value to avoid unnecessary cgroup filesystem access.
|
|
|
c480ed |
+ */
|
|
|
c480ed |
+static unsigned long long int virCgroupV1MemoryUnlimitedKB;
|
|
|
c480ed |
+static virOnceControl virCgroupV1MemoryOnce = VIR_ONCE_CONTROL_INITIALIZER;
|
|
|
c480ed |
+
|
|
|
c480ed |
+static void
|
|
|
c480ed |
+virCgroupV1MemoryOnceInit(void)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ virCgroupPtr group;
|
|
|
c480ed |
+ unsigned long long int mem_unlimited = 0ULL;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virCgroupNew(-1, "/", NULL, -1, &group) < 0)
|
|
|
c480ed |
+ goto cleanup;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (!virCgroupV1HasController(group, VIR_CGROUP_CONTROLLER_MEMORY))
|
|
|
c480ed |
+ goto cleanup;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ ignore_value(virCgroupGetValueU64(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
+ "memory.limit_in_bytes",
|
|
|
c480ed |
+ &mem_unlimited));
|
|
|
c480ed |
+ cleanup:
|
|
|
c480ed |
+ virCgroupFree(&group);
|
|
|
c480ed |
+ virCgroupV1MemoryUnlimitedKB = mem_unlimited >> 10;
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+static unsigned long long int
|
|
|
c480ed |
+virCgroupV1GetMemoryUnlimitedKB(void)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ if (virOnce(&virCgroupV1MemoryOnce, virCgroupV1MemoryOnceInit) < 0)
|
|
|
c480ed |
+ VIR_DEBUG("Init failed, will fall back to defaults.");
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virCgroupV1MemoryUnlimitedKB)
|
|
|
c480ed |
+ return virCgroupV1MemoryUnlimitedKB;
|
|
|
c480ed |
+ else
|
|
|
c480ed |
+ return VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
static int
|
|
|
c480ed |
virCgroupV1SetMemory(virCgroupPtr group,
|
|
|
c480ed |
unsigned long long kb)
|
|
|
c480ed |
@@ -1494,6 +1539,123 @@ virCgroupV1GetMemoryUsage(virCgroupPtr group,
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
+static int
|
|
|
c480ed |
+virCgroupV1SetMemoryHardLimit(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long kb)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ return virCgroupV1SetMemory(group, kb);
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
+static int
|
|
|
c480ed |
+virCgroupV1GetMemoryHardLimit(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long *kb)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ long long unsigned int limit_in_bytes;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virCgroupGetValueU64(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
+ "memory.limit_in_bytes", &limit_in_bytes) < 0)
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ *kb = limit_in_bytes >> 10;
|
|
|
c480ed |
+ if (*kb >= virCgroupV1GetMemoryUnlimitedKB())
|
|
|
c480ed |
+ *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ return 0;
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
+static int
|
|
|
c480ed |
+virCgroupV1SetMemorySoftLimit(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long kb)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (kb > maxkb) {
|
|
|
c480ed |
+ virReportError(VIR_ERR_INVALID_ARG,
|
|
|
c480ed |
+ _("Memory '%llu' must be less than %llu"),
|
|
|
c480ed |
+ kb, maxkb);
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (kb == maxkb)
|
|
|
c480ed |
+ return virCgroupSetValueI64(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
+ "memory.soft_limit_in_bytes",
|
|
|
c480ed |
+ -1);
|
|
|
c480ed |
+ else
|
|
|
c480ed |
+ return virCgroupSetValueU64(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
+ "memory.soft_limit_in_bytes",
|
|
|
c480ed |
+ kb << 10);
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
+static int
|
|
|
c480ed |
+virCgroupV1GetMemorySoftLimit(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long *kb)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ long long unsigned int limit_in_bytes;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virCgroupGetValueU64(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
+ "memory.soft_limit_in_bytes", &limit_in_bytes) < 0)
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ *kb = limit_in_bytes >> 10;
|
|
|
c480ed |
+ if (*kb >= virCgroupV1GetMemoryUnlimitedKB())
|
|
|
c480ed |
+ *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ return 0;
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
+static int
|
|
|
c480ed |
+virCgroupV1SetMemSwapHardLimit(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long kb)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (kb > maxkb) {
|
|
|
c480ed |
+ virReportError(VIR_ERR_INVALID_ARG,
|
|
|
c480ed |
+ _("Memory '%llu' must be less than %llu"),
|
|
|
c480ed |
+ kb, maxkb);
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (kb == maxkb)
|
|
|
c480ed |
+ return virCgroupSetValueI64(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
+ "memory.memsw.limit_in_bytes",
|
|
|
c480ed |
+ -1);
|
|
|
c480ed |
+ else
|
|
|
c480ed |
+ return virCgroupSetValueU64(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
+ "memory.memsw.limit_in_bytes",
|
|
|
c480ed |
+ kb << 10);
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
+static int
|
|
|
c480ed |
+virCgroupV1GetMemSwapHardLimit(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long *kb)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ long long unsigned int limit_in_bytes;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virCgroupGetValueU64(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
+ "memory.memsw.limit_in_bytes", &limit_in_bytes) < 0)
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ *kb = limit_in_bytes >> 10;
|
|
|
c480ed |
+ if (*kb >= virCgroupV1GetMemoryUnlimitedKB())
|
|
|
c480ed |
+ *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ return 0;
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
virCgroupBackend virCgroupV1Backend = {
|
|
|
c480ed |
.type = VIR_CGROUP_BACKEND_TYPE_V1,
|
|
|
c480ed |
|
|
|
c480ed |
@@ -1534,6 +1696,12 @@ virCgroupBackend virCgroupV1Backend = {
|
|
|
c480ed |
.setMemory = virCgroupV1SetMemory,
|
|
|
c480ed |
.getMemoryStat = virCgroupV1GetMemoryStat,
|
|
|
c480ed |
.getMemoryUsage = virCgroupV1GetMemoryUsage,
|
|
|
c480ed |
+ .setMemoryHardLimit = virCgroupV1SetMemoryHardLimit,
|
|
|
c480ed |
+ .getMemoryHardLimit = virCgroupV1GetMemoryHardLimit,
|
|
|
c480ed |
+ .setMemorySoftLimit = virCgroupV1SetMemorySoftLimit,
|
|
|
c480ed |
+ .getMemorySoftLimit = virCgroupV1GetMemorySoftLimit,
|
|
|
c480ed |
+ .setMemSwapHardLimit = virCgroupV1SetMemSwapHardLimit,
|
|
|
c480ed |
+ .getMemSwapHardLimit = virCgroupV1GetMemSwapHardLimit,
|
|
|
c480ed |
};
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
--
|
|
|
c480ed |
2.22.0
|
|
|
c480ed |
|