From nobody Mon Feb 9 09:22:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1691423786; cv=none; d=zohomail.com; s=zohoarc; b=eLxP9H2OjLotwK1P/dKqi4mdFs4n83/nMA7VqCKmVoke/IUzMYZcOIsuXWkB8KvfCMCiOlDPK676/eSBY5kn11pv81LbAvI5GxN5rwFCL+x8vH0E4Y3phPVJXVCOn6hYVbjqKw5o9PZO9SloGyq2+L/0eF7w4IypxQt5s2MSN+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691423786; 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=2AzbjkVhf1utLmIep6aqbIMLeQhr7/n4u4KYVrZZQKc=; b=I5wTn7htDIPUcp9WAvfwf1ck+bFEc6wlMLD6nPPnXG+1EW/IyJ4XpqCcdLTuL/nqoZQkwHQPfuFuRq5SCVzbyqOY9jnMyxLRec5Lku3d2n4WAfvQGID1idToHYqt75IOekuuJXQFAYP8OMAgqtscVqLn1gfl01qkEsndiR3lDBc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1691423786671391.23530249601606; Mon, 7 Aug 2023 08:56:26 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-651-opoFj5eDNCWaenFkvIev0Q-1; Mon, 07 Aug 2023 11:56:22 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7B7533C108E3; Mon, 7 Aug 2023 15:56:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D10744104; Mon, 7 Aug 2023 15:56:19 +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 018E3194658D; Mon, 7 Aug 2023 15:56:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 67BE41946586 for ; Mon, 7 Aug 2023 15:56:11 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 4C919403174; Mon, 7 Aug 2023 15:56:11 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast10.extmail.prod.ext.rdu2.redhat.com [10.11.55.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 44CD840F16E for ; Mon, 7 Aug 2023 15:56:11 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [205.139.110.61]) (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 288221C05145 for ; Mon, 7 Aug 2023 15:56:11 +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-192-UU5dvS7WP9i9h_WSwOXfGw-1; Mon, 07 Aug 2023 11:56:09 -0400 Received: from git.sr.ht (unknown [173.195.146.142]) by mail-b.sr.ht (Postfix) with ESMTPSA id 8841611F00B; Mon, 7 Aug 2023 15:56:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691423785; 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=2AzbjkVhf1utLmIep6aqbIMLeQhr7/n4u4KYVrZZQKc=; b=Bwwf/iUiiLEoLKxMNR1iLPJ/+lUF0Xw6bsw2kI1WZVQIv4wfZ+Y578W33Hsd1qW2zQlWDr p9v/uDm94OWiSMUIU4Z+hjiiXw+G5KQMMaQNKRPklekIAhzM/0xb5qtScDip+4sDbJNrJn 14VWOO5YoIXMjQ+AvCsuJqYyNwrCAdU= X-MC-Unique: opoFj5eDNCWaenFkvIev0Q-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: UU5dvS7WP9i9h_WSwOXfGw-1 From: ~hyman Date: Mon, 08 Aug 2022 23:41:27 +0800 Subject: [PATCH Libvirt v2 07/10] virsh: Introduce limit-dirty-page-rate api MIME-Version: 1.0 Message-ID: <169142376567.1452.17600824269401067909-7@git.sr.ht> In-Reply-To: <169142376567.1452.17600824269401067909-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.10 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: 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.5 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: 1691423812802100003 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 ] 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 | 21 ++++++++ tools/virsh-domain.c | 109 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index f4e5a0bd62..59eecbcef0 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5273,6 +5273,27 @@ 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 ] + +Set or cancel a domain's dirty page rate upper limit for the given vcpu sp= ecified +by the ``vcpu``; set for all virtual CPUs if ``vcpu`` if not specified and= cancel +the domain's dirty page rate upper limit if ``rate`` is set to zero. +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. + +CPU will be throttled as needed to keep their dirty page rate within the l= imit +if the feature enabled. This could, in some scenes, be used to provide +quality-of-service in the aspect of the memory workload for virtual CPUs. + + 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 f8758f18a3..c0b0ef7472 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13812,6 +13812,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 index")); + 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 all virtual CPUs successfully\n"), + rate); + } + + return true; +} =20 const vshCmdDef domManagementCmds[] =3D { {.name =3D "attach-device", @@ -14476,5 +14579,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