mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
domain_cgroup.c: add virDomainCgroupSetupMemtune()
virLXCCgroupSetupMemTune() and qemuSetupMemoryCgroup() shares duplicated code that can be put in a new helper to avoid code repetition. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
f1704e61c3
commit
ca4238ba73
@ -65,3 +65,22 @@ virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blkio)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem)
|
||||
{
|
||||
if (virMemoryLimitIsSet(mem.hard_limit))
|
||||
if (virCgroupSetMemoryHardLimit(cgroup, mem.hard_limit) < 0)
|
||||
return -1;
|
||||
|
||||
if (virMemoryLimitIsSet(mem.soft_limit))
|
||||
if (virCgroupSetMemorySoftLimit(cgroup, mem.soft_limit) < 0)
|
||||
return -1;
|
||||
|
||||
if (virMemoryLimitIsSet(mem.swap_hard_limit))
|
||||
if (virCgroupSetMemSwapHardLimit(cgroup, mem.swap_hard_limit) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -25,3 +25,4 @@
|
||||
|
||||
|
||||
int virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blkio);
|
||||
int virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem);
|
||||
|
@ -1392,6 +1392,7 @@ virSetConnectStorage;
|
||||
|
||||
# hypervisor/domain_cgroup.h
|
||||
virDomainCgroupSetupBlkio;
|
||||
virDomainCgroupSetupMemtune;
|
||||
|
||||
|
||||
# libvirt_internal.h
|
||||
|
@ -112,19 +112,7 @@ static int virLXCCgroupSetupMemTune(virDomainDefPtr def,
|
||||
if (virCgroupSetMemory(cgroup, virDomainDefGetMemoryInitial(def)) < 0)
|
||||
return -1;
|
||||
|
||||
if (virMemoryLimitIsSet(def->mem.hard_limit))
|
||||
if (virCgroupSetMemoryHardLimit(cgroup, def->mem.hard_limit) < 0)
|
||||
return -1;
|
||||
|
||||
if (virMemoryLimitIsSet(def->mem.soft_limit))
|
||||
if (virCgroupSetMemorySoftLimit(cgroup, def->mem.soft_limit) < 0)
|
||||
return -1;
|
||||
|
||||
if (virMemoryLimitIsSet(def->mem.swap_hard_limit))
|
||||
if (virCgroupSetMemSwapHardLimit(cgroup, def->mem.swap_hard_limit) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
return virDomainCgroupSetupMemtune(cgroup, def->mem);
|
||||
}
|
||||
|
||||
|
||||
|
@ -625,19 +625,7 @@ qemuSetupMemoryCgroup(virDomainObjPtr vm)
|
||||
}
|
||||
}
|
||||
|
||||
if (virMemoryLimitIsSet(vm->def->mem.hard_limit))
|
||||
if (virCgroupSetMemoryHardLimit(priv->cgroup, vm->def->mem.hard_limit) < 0)
|
||||
return -1;
|
||||
|
||||
if (virMemoryLimitIsSet(vm->def->mem.soft_limit))
|
||||
if (virCgroupSetMemorySoftLimit(priv->cgroup, vm->def->mem.soft_limit) < 0)
|
||||
return -1;
|
||||
|
||||
if (virMemoryLimitIsSet(vm->def->mem.swap_hard_limit))
|
||||
if (virCgroupSetMemSwapHardLimit(priv->cgroup, vm->def->mem.swap_hard_limit) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
return virDomainCgroupSetupMemtune(priv->cgroup, vm->def->mem);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user