New command node-memory-tune to get/set the node memory parameters, only two parameters are allowed to set (pages_to_scan, and sleep_millisecs, see documents in this patch for more details). Example of node-memory-tune's output: Shared memory: pages_to_scan 100 sleep_millisecs 20 pages_shared 0 pages_sharing 0 pages_unshared 0 pages_volatile 0 full_scans 0 --- tools/virsh-host.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 8 ++++ 2 files changed, 124 insertions(+), 0 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index c46288b..713c003 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -37,6 +37,7 @@ #include "util.h" #include "virsh-domain.h" #include "xml.h" +#include "virtypedparam.h" /* * "capabilities" command @@ -884,12 +885,127 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) return true; } +static const vshCmdInfo info_node_memory_tune[] = { + {"help", N_("Get or set node memory parameters")}, + {"desc", N_("Get or set node memory parameters" + " To get the memory parameters, use following command: \n\n" + " virsh # node-memory-tune")}, + {NULL, NULL} +}; + +static const vshCmdOptDef opts_node_memory_tune[] = { + {"shm-pages-to-scan", VSH_OT_INT, VSH_OFLAG_NONE, + N_("number of pages to scan before the shared memory service " + "goes to sleep")}, + {"shm-sleep-millisecs", VSH_OT_INT, VSH_OFLAG_NONE, + N_("number of millisecs the shared memory service should " + "sleep before next scan")}, + {NULL, 0, 0, NULL} +}; + +static bool +cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) +{ + virTypedParameterPtr params = NULL; + int nparams = 0; + unsigned int flags = 0; + unsigned int shm_pages_to_scan = 0; + unsigned int shm_sleep_millisecs = 0; + bool ret = false; + int i = 0; + + if (vshCommandOptUInt(cmd, "shm-pages-to-scan", + &shm_pages_to_scan) < 0) { + vshError(ctl, "%s", _("invalid shm-pages-to-scan number")); + return false; + } + + if (vshCommandOptUInt(cmd, "shm-sleep-millisecs", + &shm_sleep_millisecs) < 0) { + vshError(ctl, "%s", _("invalid shm-sleep-millisecs number")); + return false; + } + + if (shm_pages_to_scan) + nparams++; + + if (shm_sleep_millisecs) + nparams++; + + if (nparams == 0) { + /* Get the number of memory parameters */ + if (virNodeGetMemoryParameters(ctl->conn, NULL, &nparams, flags) != 0) { + vshError(ctl, "%s", + _("Unable to get number of memory parameters")); + goto cleanup; + } + + if (nparams == 0) { + ret = true; + goto cleanup; + } + + /* Now go get all the memory parameters */ + params = vshCalloc(ctl, nparams, sizeof(*params)); + if (virNodeGetMemoryParameters(ctl->conn, params, &nparams, flags) != 0) { + vshError(ctl, "%s", _("Unable to get memory parameters")); + goto cleanup; + } + + /* XXX: Need to sort the returned params once new parameter + * fields not of shared memory are added. + */ + vshPrint(ctl, _("Shared memory:\n")); + for (i = 0; i < nparams; i++) { + char *str = vshGetTypedParamValue(ctl, ¶ms[i]); + vshPrint(ctl, "\t%-15s %s\n", params[i].field, str); + VIR_FREE(str); + } + + ret = true; + } else { + /* Set the memory parameters */ + params = vshCalloc(ctl, nparams, sizeof(*params)); + + if (i < nparams && shm_pages_to_scan) { + if (virTypedParameterAssign(¶ms[i++], + VIR_NODE_MEMORY_SHARED_PAGES_TO_SCAN, + VIR_TYPED_PARAM_UINT, + shm_pages_to_scan) < 0) + goto error; + } + + if (i < nparams && shm_sleep_millisecs) { + if (virTypedParameterAssign(¶ms[i++], + VIR_NODE_MEMORY_SHARED_SLEEP_MILLISECS, + VIR_TYPED_PARAM_UINT, + shm_sleep_millisecs) < 0) + goto error; + } + + if (virNodeSetMemoryParameters(ctl->conn, params, nparams, flags) != 0) + goto error; + else + ret = true; + } + +cleanup: + VIR_FREE(params); + return ret; + +error: + vshError(ctl, "%s", _("Unable to change memory parameters")); + goto cleanup; +} + const vshCmdDef hostAndHypervisorCmds[] = { {"capabilities", cmdCapabilities, NULL, info_capabilities, 0}, {"connect", cmdConnect, opts_connect, info_connect, VSH_CMD_FLAG_NOCONNECT}, {"freecell", cmdFreecell, opts_freecell, info_freecell, 0}, {"hostname", cmdHostname, NULL, info_hostname, 0}, + {"node-memory-tune", cmdNodeMemoryTune, + opts_node_memory_tune, info_node_memory_tune, 0}, {"nodecpustats", cmdNodeCpuStats, opts_node_cpustats, info_nodecpustats, 0}, {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo, 0}, {"nodememstats", cmdNodeMemStats, opts_node_memstats, info_nodememstats, 0}, diff --git a/tools/virsh.pod b/tools/virsh.pod index 559e64d..d1f7068 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -293,6 +293,14 @@ Real-Time-Clock interrupt to fire (to wake up the node) after a time delay specified by the 'duration' parameter. The duration time should be at least 60 seconds. +=item B<node-memory-tune> [I<shm-pages-to-scan>] [I<shm-sleep-millisecs>] + +Allows you to display or set the node memory parameters. +I<shm-pages-to-scan> can be used to set the number of pages to scan +before the shared memory service goes to sleep; I<shm-sleep-millisecs> +can be used to set the number of millisecs the shared memory service should +sleep before next scan. + =item B<capabilities> Print an XML document describing the capabilities of the hypervisor -- 1.7.7.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list