From nobody Wed Jan 22 03:38:29 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=git.sr.ht ARC-Seal: i=1; a=rsa-sha256; t=1693970850; cv=none; d=zohomail.com; s=zohoarc; b=d+p3QwZMgyT4LhIeV6dfOFJaZV5/vA0ElIQMyDtEY8yfuREfI07gnacSJEMsrnLQ9sMDLFLVHsZFcbz88wRIRoprdwyK6EaQ4Nd2ObtZIpG6XBZnsme9WNquRM69zKggccstLEHLtIBloNMT0hfQJD8OYrz2/clecWpzLd4t+ko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693970850; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=nvQOVFho/+F+elliPiAnbwt3GFVgO42cMtNnIQWiiVw=; b=imCe/Pt/KxxwypJU7jrqn1Q2bMSeYihgOjtgAuWA6xEQa+Dk5bDBL/QGcz9PINt2kw4q9SHEFlyva9l5wFWwMJylBnUiCiN4hK4D02rQH7GdEXBVbaUL/hiMROYfGu2MImnBdYBrx2FU5cDbCHTp0K7AsVWEb03fzROj7QsPsfs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1693970850731211.71764180245407; Tue, 5 Sep 2023 20:27:30 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-350-m6bQAftEM9K2ILGPfMBBJQ-1; Tue, 05 Sep 2023 23:27:27 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 27A541040889; Wed, 6 Sep 2023 03:27:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F9ED2026D33; Wed, 6 Sep 2023 03:27:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DF2741946A6F; Wed, 6 Sep 2023 03:27:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4C70919472B5 for ; Wed, 6 Sep 2023 03:27:18 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2CAA1412F2CD; Wed, 6 Sep 2023 03:27:18 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 25D83412F2D6 for ; Wed, 6 Sep 2023 03:27:18 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F2FE218DA730 for ; Wed, 6 Sep 2023 03:27:17 +0000 (UTC) Received: from mail-b.sr.ht (mail-b.sr.ht [173.195.146.151]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-jM6wMXv0O_G9YluNZOqNGw-1; Tue, 05 Sep 2023 23:27:15 -0400 Received: from git.sr.ht (unknown [173.195.146.142]) by mail-b.sr.ht (Postfix) with ESMTPSA id 8B24C11F0E4; Wed, 6 Sep 2023 03:27:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693970849; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=nvQOVFho/+F+elliPiAnbwt3GFVgO42cMtNnIQWiiVw=; b=IwFxn/6vGcxbMmLfXdFGR0EMIWL1vzfyBXS5ZYggjSCNAOWdCb74u+2KETB2mz5d4A+BoE LCU+X7ArB2xnNLrQhyNSrOZ6mls+8JAgM4H3sB+Oh6iFLMDHyl6RJ+3CO6vaYRLxoIIRFe yGQBFjKM6Vf0cewHJihhmq7yagaB7Ds= X-MC-Unique: m6bQAftEM9K2ILGPfMBBJQ-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: jM6wMXv0O_G9YluNZOqNGw-1 From: ~hyman Date: Mon, 08 Aug 2022 23:41:27 +0800 Subject: [PATCH Libvirt v3 07/10] virsh: Introduce limit-dirty-page-rate api MIME-Version: 1.0 Message-ID: <169397083100.4628.15196043252714532301-7@git.sr.ht> In-Reply-To: <169397083100.4628.15196043252714532301-0@git.sr.ht> To: libvir-list@redhat.com X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: ~hyman Cc: Martin Kletzander , Peter Krempa , yong.huang@smartx.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: git.sr.ht Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693970852556100014 From: Hyman Huang(=E9=BB=84=E5=8B=87) Introduce limit-dirty-page-rate virsh api to set or cancel dirty page rate upper limit for virtual CPUs. Usage is below: $ virsh limit-dirty-page-rate --rate \ [--vcpu ] [--config] [--live] [--current] Set the dirty page rate upper limit for the given vcpu specified by the "vcpu"; set for all virtual CPUs if vcpu option is not passed in. Cancel the dirty page rate upper limit if the "rate" option is set to zero. Note that the API requires dirty-ring size configured. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- docs/manpages/virsh.rst | 26 ++++++++++ tools/virsh-domain.c | 109 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 91e1d5de37..33a8f3b9fe 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5273,6 +5273,32 @@ use to avoid keeping them open unnecessarily. Best-e= ffort security label restore may be requested by using the *--seclabel-restore* flag. =20 =20 +limit-dirty-page-rate +--------------------- + +**Syntax:** + +:: + + limit-dirty-page-rate --rate [--vcpu ] + [--config] [--live] [--current] + +Set or cancel a domain's dirty page rate upper limit for the given virtual= CPU +specified by *--vcpu*; set for all virtual CPUs if *--vcpu* is not specifi= ed; +and cancel the domain's dirty page rate upper limit if *--rate* is set to = zero. + +Virtual CPUs will be throttled as needed to keep their dirty page rate wit= hin +the limit if the feature enabled. This could, in some scenes, be used to p= rovide +quality-of-service in the aspect of the memory workload for virtual CPUs. + +If *--live* is specified, affect a running domain. +If *--config* is specified, affect the next startup of a persistent domain. +If *--current* is specified, it is equivalent to either *--live* or +*--config*, depending on the current state of the domain. +Both *--live* and *--config* flags may be given, but *--current* is +exclusive. Not specifying any flag is the same as specifying *--current*. + + NODEDEV COMMANDS =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7abafe2ba3..ae51d9fdfb 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13732,6 +13732,109 @@ cmdDomDirtyRateCalc(vshControl *ctl, const vshCmd= *cmd) return true; } =20 +/* + * "limit-dirty-page-rate" command + */ +static const vshCmdInfo info_limit_dirty_page_rate[] =3D { + {.name =3D "help", + .data =3D N_("Set or cancel dirty page rate upper limit") + }, + {.name =3D "desc", + .data =3D N_("Set or cancel dirty page rate upper limit, " + "require dirty-ring size configured") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_limit_dirty_page_rate[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "rate", + .type =3D VSH_OT_INT, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("Upper limit of dirty page rate (MB/s) for " + "virtual CPUs, use 0 to cancel") + }, + {.name =3D "vcpu", + .type =3D VSH_OT_INT, + .help =3D N_("Index of a virtual CPU") + }, + VIRSH_COMMON_OPT_DOMAIN_PERSISTENT, + VIRSH_COMMON_OPT_DOMAIN_CONFIG, + VIRSH_COMMON_OPT_DOMAIN_LIVE, + VIRSH_COMMON_OPT_DOMAIN_CURRENT, + {.name =3D NULL} +}; + +static bool +cmdLimitDirtyPageRate(vshControl *ctl, const vshCmd *cmd) +{ + g_autoptr(virshDomain) dom =3D NULL; + int vcpu_idx =3D -1; + unsigned long long rate =3D 0; + unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; + bool vcpu =3D vshCommandOptBool(cmd, "vcpu"); + bool current =3D vshCommandOptBool(cmd, "current"); + bool config =3D vshCommandOptBool(cmd, "config"); + bool live =3D vshCommandOptBool(cmd, "live"); + + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (config) + flags |=3D VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |=3D VIR_DOMAIN_AFFECT_LIVE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (vshCommandOptULongLong(ctl, cmd, "rate", &rate) < 0) + return false; + + if (vcpu) { + if (vshCommandOptInt(ctl, cmd, "vcpu", &vcpu_idx) < 0) + return false; + + if (vcpu_idx < 0) { + vshError(ctl, "%s", + _("Invalid vcpu index, using --vcpu to specify cpu in= dex")); + return false; + } + } + + if (vcpu) { + /* Set the dirty page rate upper limit for the specified + * virtual CPU in the given VM; cancel it if rate is set + * to zero. + */ + if (virDomainSetVcpuDirtyLimit(dom, vcpu_idx, + rate, flags) < 0) + return false; + if (rate =3D=3D 0) + vshPrintExtra(ctl, + _("Cancel vcpu[%1$d] dirty page rate upper limit= successfully\n"), + vcpu_idx); + else + vshPrintExtra(ctl, + _("Set vcpu[%1$d] dirty page rate upper limit %2= $lld(MB/s) successfully\n"), + vcpu_idx, rate); + } else { + /* Set all dirty page rate upper limits for virtual CPUs in + * the given VM; cancel it if the rate is set to zero. + */ + if (virDomainSetVcpuDirtyLimit(dom, -1, rate, flags) < 0) + return false; + if (rate =3D=3D 0) + vshPrintExtra(ctl, "%s", + _("Cancel dirty page rate limit for all virtual = CPUs successfully\n")); + else + vshPrintExtra(ctl, + _("Set dirty page rate limit %1$lld(MB/s) for al= l virtual CPUs successfully\n"), + rate); + } + + return true; +} =20 const vshCmdDef domManagementCmds[] =3D { {.name =3D "attach-device", @@ -14396,5 +14499,11 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_dom_fd_associate, .flags =3D 0 }, + {.name =3D "limit-dirty-page-rate", + .handler =3D cmdLimitDirtyPageRate, + .opts =3D opts_limit_dirty_page_rate, + .info =3D info_limit_dirty_page_rate, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.38.5