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:
Daniel Henrique Barboza 2020-02-17 16:29:12 -05:00 committed by Ján Tomko
parent f1704e61c3
commit ca4238ba73
5 changed files with 23 additions and 26 deletions

View File

@ -65,3 +65,22 @@ virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blkio)
return 0; 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;
}

View File

@ -25,3 +25,4 @@
int virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blkio); int virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blkio);
int virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem);

View File

@ -1392,6 +1392,7 @@ virSetConnectStorage;
# hypervisor/domain_cgroup.h # hypervisor/domain_cgroup.h
virDomainCgroupSetupBlkio; virDomainCgroupSetupBlkio;
virDomainCgroupSetupMemtune;
# libvirt_internal.h # libvirt_internal.h

View File

@ -112,19 +112,7 @@ static int virLXCCgroupSetupMemTune(virDomainDefPtr def,
if (virCgroupSetMemory(cgroup, virDomainDefGetMemoryInitial(def)) < 0) if (virCgroupSetMemory(cgroup, virDomainDefGetMemoryInitial(def)) < 0)
return -1; return -1;
if (virMemoryLimitIsSet(def->mem.hard_limit)) return virDomainCgroupSetupMemtune(cgroup, def->mem);
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;
} }

View File

@ -625,19 +625,7 @@ qemuSetupMemoryCgroup(virDomainObjPtr vm)
} }
} }
if (virMemoryLimitIsSet(vm->def->mem.hard_limit)) return virDomainCgroupSetupMemtune(priv->cgroup, vm->def->mem);
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;
} }