mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-23 03:42:19 +00:00
memtune: Let virsh know the unlimited value for memory tunables
Display or set unlimited values for memory parameters. Unlimited is represented by INT64_MAX in memory cgroup. Signed-off-by: Nikunj A. Dadhania <nikunj@linux.vnet.ibm.com> Reported-by: Justin Clift <jclift@redhat.com>
This commit is contained in:
parent
63dbc84a88
commit
d94a14f89d
@ -696,6 +696,7 @@ typedef enum {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define VIR_DOMAIN_MEMORY_FIELD_LENGTH 80
|
#define VIR_DOMAIN_MEMORY_FIELD_LENGTH 80
|
||||||
|
#define VIR_DOMAIN_MEMORY_PARAM_UNLIMITED (INT64_MAX >> 10)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VIR_DOMAIN_MEMORY_HARD_LIMIT:
|
* VIR_DOMAIN_MEMORY_HARD_LIMIT:
|
||||||
|
@ -815,7 +815,7 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
|
|||||||
int i;
|
int i;
|
||||||
virCgroupPtr cgroup = NULL;
|
virCgroupPtr cgroup = NULL;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
unsigned long val;
|
unsigned long long val;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -7036,7 +7036,7 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
|
|||||||
int i;
|
int i;
|
||||||
virCgroupPtr group = NULL;
|
virCgroupPtr group = NULL;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
unsigned long val;
|
unsigned long long val;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -355,8 +355,6 @@ static int virCgroupSetValueU64(virCgroupPtr group,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* This is included for completeness, but not yet used */
|
|
||||||
|
|
||||||
static int virCgroupSetValueI64(virCgroupPtr group,
|
static int virCgroupSetValueI64(virCgroupPtr group,
|
||||||
int controller,
|
int controller,
|
||||||
@ -376,6 +374,8 @@ static int virCgroupSetValueI64(virCgroupPtr group,
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* This is included for completeness, but not yet used */
|
||||||
static int virCgroupGetValueI64(virCgroupPtr group,
|
static int virCgroupGetValueI64(virCgroupPtr group,
|
||||||
int controller,
|
int controller,
|
||||||
const char *key,
|
const char *key,
|
||||||
@ -858,8 +858,18 @@ int virCgroupForDomain(virCgroupPtr driver ATTRIBUTE_UNUSED,
|
|||||||
*
|
*
|
||||||
* Returns: 0 on success
|
* Returns: 0 on success
|
||||||
*/
|
*/
|
||||||
int virCgroupSetMemory(virCgroupPtr group, unsigned long kb)
|
int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb)
|
||||||
{
|
{
|
||||||
|
unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
||||||
|
|
||||||
|
if (kb > maxkb)
|
||||||
|
return -EINVAL;
|
||||||
|
else if (kb == maxkb)
|
||||||
|
return virCgroupSetValueI64(group,
|
||||||
|
VIR_CGROUP_CONTROLLER_MEMORY,
|
||||||
|
"memory.limit_in_bytes",
|
||||||
|
-1);
|
||||||
|
else
|
||||||
return virCgroupSetValueU64(group,
|
return virCgroupSetValueU64(group,
|
||||||
VIR_CGROUP_CONTROLLER_MEMORY,
|
VIR_CGROUP_CONTROLLER_MEMORY,
|
||||||
"memory.limit_in_bytes",
|
"memory.limit_in_bytes",
|
||||||
@ -894,7 +904,7 @@ int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb)
|
|||||||
*
|
*
|
||||||
* Returns: 0 on success
|
* Returns: 0 on success
|
||||||
*/
|
*/
|
||||||
int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long kb)
|
int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb)
|
||||||
{
|
{
|
||||||
return virCgroupSetMemory(group, kb);
|
return virCgroupSetMemory(group, kb);
|
||||||
}
|
}
|
||||||
@ -907,7 +917,7 @@ int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long kb)
|
|||||||
*
|
*
|
||||||
* Returns: 0 on success
|
* Returns: 0 on success
|
||||||
*/
|
*/
|
||||||
int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long *kb)
|
int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb)
|
||||||
{
|
{
|
||||||
long long unsigned int limit_in_bytes;
|
long long unsigned int limit_in_bytes;
|
||||||
int ret;
|
int ret;
|
||||||
@ -915,7 +925,7 @@ int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long *kb)
|
|||||||
VIR_CGROUP_CONTROLLER_MEMORY,
|
VIR_CGROUP_CONTROLLER_MEMORY,
|
||||||
"memory.limit_in_bytes", &limit_in_bytes);
|
"memory.limit_in_bytes", &limit_in_bytes);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
*kb = (unsigned long) limit_in_bytes >> 10;
|
*kb = limit_in_bytes >> 10;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -927,8 +937,18 @@ int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long *kb)
|
|||||||
*
|
*
|
||||||
* Returns: 0 on success
|
* Returns: 0 on success
|
||||||
*/
|
*/
|
||||||
int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long kb)
|
int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb)
|
||||||
{
|
{
|
||||||
|
unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
||||||
|
|
||||||
|
if (kb > maxkb)
|
||||||
|
return -EINVAL;
|
||||||
|
else if (kb == maxkb)
|
||||||
|
return virCgroupSetValueI64(group,
|
||||||
|
VIR_CGROUP_CONTROLLER_MEMORY,
|
||||||
|
"memory.soft_limit_in_bytes",
|
||||||
|
-1);
|
||||||
|
else
|
||||||
return virCgroupSetValueU64(group,
|
return virCgroupSetValueU64(group,
|
||||||
VIR_CGROUP_CONTROLLER_MEMORY,
|
VIR_CGROUP_CONTROLLER_MEMORY,
|
||||||
"memory.soft_limit_in_bytes",
|
"memory.soft_limit_in_bytes",
|
||||||
@ -944,7 +964,7 @@ int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long kb)
|
|||||||
*
|
*
|
||||||
* Returns: 0 on success
|
* Returns: 0 on success
|
||||||
*/
|
*/
|
||||||
int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long *kb)
|
int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb)
|
||||||
{
|
{
|
||||||
long long unsigned int limit_in_bytes;
|
long long unsigned int limit_in_bytes;
|
||||||
int ret;
|
int ret;
|
||||||
@ -952,7 +972,7 @@ int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long *kb)
|
|||||||
VIR_CGROUP_CONTROLLER_MEMORY,
|
VIR_CGROUP_CONTROLLER_MEMORY,
|
||||||
"memory.soft_limit_in_bytes", &limit_in_bytes);
|
"memory.soft_limit_in_bytes", &limit_in_bytes);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
*kb = (unsigned long) limit_in_bytes >> 10;
|
*kb = limit_in_bytes >> 10;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -964,8 +984,18 @@ int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long *kb)
|
|||||||
*
|
*
|
||||||
* Returns: 0 on success
|
* Returns: 0 on success
|
||||||
*/
|
*/
|
||||||
int virCgroupSetSwapHardLimit(virCgroupPtr group, unsigned long kb)
|
int virCgroupSetSwapHardLimit(virCgroupPtr group, unsigned long long kb)
|
||||||
{
|
{
|
||||||
|
unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
||||||
|
|
||||||
|
if (kb > maxkb)
|
||||||
|
return -EINVAL;
|
||||||
|
else if (kb == maxkb)
|
||||||
|
return virCgroupSetValueI64(group,
|
||||||
|
VIR_CGROUP_CONTROLLER_MEMORY,
|
||||||
|
"memory.memsw.limit_in_bytes",
|
||||||
|
-1);
|
||||||
|
else
|
||||||
return virCgroupSetValueU64(group,
|
return virCgroupSetValueU64(group,
|
||||||
VIR_CGROUP_CONTROLLER_MEMORY,
|
VIR_CGROUP_CONTROLLER_MEMORY,
|
||||||
"memory.memsw.limit_in_bytes",
|
"memory.memsw.limit_in_bytes",
|
||||||
@ -980,7 +1010,7 @@ int virCgroupSetSwapHardLimit(virCgroupPtr group, unsigned long kb)
|
|||||||
*
|
*
|
||||||
* Returns: 0 on success
|
* Returns: 0 on success
|
||||||
*/
|
*/
|
||||||
int virCgroupGetSwapHardLimit(virCgroupPtr group, unsigned long *kb)
|
int virCgroupGetSwapHardLimit(virCgroupPtr group, unsigned long long *kb)
|
||||||
{
|
{
|
||||||
long long unsigned int limit_in_bytes;
|
long long unsigned int limit_in_bytes;
|
||||||
int ret;
|
int ret;
|
||||||
@ -988,7 +1018,7 @@ int virCgroupGetSwapHardLimit(virCgroupPtr group, unsigned long *kb)
|
|||||||
VIR_CGROUP_CONTROLLER_MEMORY,
|
VIR_CGROUP_CONTROLLER_MEMORY,
|
||||||
"memory.memsw.limit_in_bytes", &limit_in_bytes);
|
"memory.memsw.limit_in_bytes", &limit_in_bytes);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
*kb = (unsigned long) limit_in_bytes >> 10;
|
*kb = limit_in_bytes >> 10;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,15 +40,15 @@ int virCgroupForDomain(virCgroupPtr driver,
|
|||||||
|
|
||||||
int virCgroupAddTask(virCgroupPtr group, pid_t pid);
|
int virCgroupAddTask(virCgroupPtr group, pid_t pid);
|
||||||
|
|
||||||
int virCgroupSetMemory(virCgroupPtr group, unsigned long kb);
|
int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb);
|
||||||
int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb);
|
int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb);
|
||||||
|
|
||||||
int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long kb);
|
int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb);
|
||||||
int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long *kb);
|
int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb);
|
||||||
int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long kb);
|
int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb);
|
||||||
int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long *kb);
|
int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb);
|
||||||
int virCgroupSetSwapHardLimit(virCgroupPtr group, unsigned long kb);
|
int virCgroupSetSwapHardLimit(virCgroupPtr group, unsigned long long kb);
|
||||||
int virCgroupGetSwapHardLimit(virCgroupPtr group, unsigned long *kb);
|
int virCgroupGetSwapHardLimit(virCgroupPtr group, unsigned long long *kb);
|
||||||
|
|
||||||
int virCgroupDenyAllDevices(virCgroupPtr group);
|
int virCgroupDenyAllDevices(virCgroupPtr group);
|
||||||
|
|
||||||
|
@ -3007,7 +3007,10 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
|
|||||||
params[i].value.l);
|
params[i].value.l);
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_MEMORY_PARAM_ULLONG:
|
case VIR_DOMAIN_MEMORY_PARAM_ULLONG:
|
||||||
vshPrint(ctl, "%-15s: %llu\n", params[i].field,
|
if (params[i].value.ul == VIR_DOMAIN_MEMORY_PARAM_UNLIMITED)
|
||||||
|
vshPrint(ctl, "%-15s: unlimited\n", params[i].field);
|
||||||
|
else
|
||||||
|
vshPrint(ctl, "%-15s: %llu kB\n", params[i].field,
|
||||||
params[i].value.ul);
|
params[i].value.ul);
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_MEMORY_PARAM_DOUBLE:
|
case VIR_DOMAIN_MEMORY_PARAM_DOUBLE:
|
||||||
@ -3059,6 +3062,10 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
|
|||||||
sizeof(temp->field));
|
sizeof(temp->field));
|
||||||
min_guarantee = 0;
|
min_guarantee = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If the user has passed -1, we interpret it as unlimited */
|
||||||
|
if (temp->value.ul == -1)
|
||||||
|
temp->value.ul = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
||||||
}
|
}
|
||||||
if (virDomainSetMemoryParameters(dom, params, nparams, 0) != 0)
|
if (virDomainSetMemoryParameters(dom, params, nparams, 0) != 0)
|
||||||
vshError(ctl, "%s", _("Unable to change memory parameters"));
|
vshError(ctl, "%s", _("Unable to change memory parameters"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user