From nobody Wed Feb 11 00:36:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1572407008; cv=none; d=zoho.com; s=zohoarc; b=Roert9JWo+Gn/hb2MhuWndr6voNjCDmu4+KnKJGRxcQjGyf2WnH7fbmno6U5spLy+qG9ggXD+x8evXKwpUEqw/RKEhV9bQIMr+VDLAhq2Bj4r7xmZkZGo01G83m/c45awQB5ES2PgbU9XTnSmGTDcicRYrPuuxrGOsNBhcHZPjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572407008; 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:References:Sender:Subject:To; bh=+8J88uE2+gfBIN3TpLF1cfHRGeSGnlpAVoXuklWeVWc=; b=lneBmvj707KOv0DwGjfN+v2BqI40NAk3nYr4sjXursIUDgNLly7UHlIES9LrYxou6AuIA/6zdyky9rZxqG6ohI9eMNViKEbaVfOH9lM/GSWEKQyvnisw4CoqXfMYCpS5B5c7v52KEebkl2IgMUyGATo8fAtCfm2nQ4P0p8JZsYo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1572407008969537.3906672448655; Tue, 29 Oct 2019 20:43:28 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-366-WLY6BkNKMomgFmc82f9_sQ-1; Tue, 29 Oct 2019 23:43:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C8A9107AD29; Wed, 30 Oct 2019 03:43:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F3C75D6D0; Wed, 30 Oct 2019 03:43:18 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4D2421809567; Wed, 30 Oct 2019 03:43:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9U3hA9J030990 for ; Tue, 29 Oct 2019 23:43:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id D996A60C4E; Wed, 30 Oct 2019 03:43:10 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D32CB60C4B for ; Wed, 30 Oct 2019 03:43:08 +0000 (UTC) Received: from cmccmta2.chinamobile.com (cmccmta2.chinamobile.com [221.176.66.80]) by mx1.redhat.com (Postfix) with ESMTP id 1000E3086272 for ; Wed, 30 Oct 2019 03:42:47 +0000 (UTC) Received: from spf.mail.chinamobile.com (unknown[172.16.121.17]) by rmmx-syy-dmz-app07-12007 (RichMail) with SMTP id 2ee75db906a5203-ba676; Wed, 30 Oct 2019 11:42:29 +0800 (CST) Received: from localhost.localdomain (unknown[112.25.154.149]) by rmsmtp-syy-appsvr09-12009 (RichMail) with SMTP id 2ee95db9069cb4a-0e0db; Wed, 30 Oct 2019 11:42:28 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572407007; h=from:from:sender:sender: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:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+8J88uE2+gfBIN3TpLF1cfHRGeSGnlpAVoXuklWeVWc=; b=IyBcMfN4vmh+EEmv0wecdtgE/gRyFiG+axxQspCnBZ5Hu/yRaVpN6tOkPBKik4IgB2esnP 5rdHCCoJ5cXS1Ous9LK3a28xAVHj4Io9bW0tpRjbQ0ViBik+pzD889cNXV1v+RbP0pkqGw L3wr9gH6d4P+KMFoy30Jh2iImoVvMIw= X-RM-TRANSID: 2ee75db906a5203-ba676 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 X-RM-TRANSID: 2ee95db9069cb4a-0e0db From: Mao Zhongyi To: libvir-list@redhat.com Date: Wed, 30 Oct 2019 11:42:13 +0800 Message-Id: <20191030034213.2888382-5-maozhongyi@cmss.chinamobile.com> In-Reply-To: <20191030034213.2888382-1-maozhongyi@cmss.chinamobile.com> References: <20191030034213.2888382-1-maozhongyi@cmss.chinamobile.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 238 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 30 Oct 2019 03:43:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 30 Oct 2019 03:43:01 +0000 (UTC) for IP:'221.176.66.80' DOMAIN:'cmccmta2.chinamobile.com' HELO:'cmccmta2.chinamobile.com' FROM:'maozhongyi@cmss.chinamobile.com' RCPT:'' X-RedHat-Spam-Score: -0.698 (RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE) 221.176.66.80 cmccmta2.chinamobile.com 221.176.66.80 cmccmta2.chinamobile.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Zhang Shengju , Mao Zhongyi Subject: [libvirt] [PATCH 4/4] util: consolidate QEMU and LXC memory related duplicate code X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: WLY6BkNKMomgFmc82f9_sQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Both qemu and lxc drivers have some duplicate code when dealing with cgroups, such as virLXCCgroupSetupMemTune() and qemuSetupMemoryCgroup(), duplicate code over 80, so consolidate the same chunk into a separate routine. Signed-off-by: Mao Zhongyi Signed-off-by: Zhang Shengju --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 28 +--------------------------- src/qemu/qemu_cgroup.c | 14 +------------- src/util/vircgroup.c | 30 ++++++++++++++++++++++++++++++ src/util/vircgroup.h | 1 + 5 files changed, 34 insertions(+), 40 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3df2af55bd..ff002fc60b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1686,6 +1686,7 @@ virCgroupSetMemorySoftLimit; virCgroupSetMemSwapHardLimit; virCgroupSetOwner; virCgroupSetupBlkio; +virCgroupSetupMemory; virCgroupSupportsCpuBW; virCgroupTerminateMachine; =20 diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index fdf8df79aa..ea6c14dfef 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -102,32 +102,6 @@ static int virLXCCgroupSetupCpusetTune(virDomainDefPtr= def, } =20 =20 -static int virLXCCgroupSetupMemTune(virDomainDefPtr def, - virCgroupPtr cgroup) -{ - int ret =3D -1; - - if (virCgroupSetMemory(cgroup, virDomainDefGetMemoryInitial(def)) < 0) - goto cleanup; - - if (virMemoryLimitIsSet(def->mem.hard_limit)) - if (virCgroupSetMemoryHardLimit(cgroup, def->mem.hard_limit) < 0) - goto cleanup; - - if (virMemoryLimitIsSet(def->mem.soft_limit)) - if (virCgroupSetMemorySoftLimit(cgroup, def->mem.soft_limit) < 0) - goto cleanup; - - if (virMemoryLimitIsSet(def->mem.swap_hard_limit)) - if (virCgroupSetMemSwapHardLimit(cgroup, def->mem.swap_hard_limit)= < 0) - goto cleanup; - - ret =3D 0; - cleanup: - return ret; -} - - static int virLXCCgroupGetMemSwapUsage(virCgroupPtr cgroup, virLXCMeminfoPtr meminfo) { @@ -438,7 +412,7 @@ int virLXCCgroupSetup(virDomainDefPtr def, if (virCgroupSetupBlkio(cgroup, def) < 0) goto cleanup; =20 - if (virLXCCgroupSetupMemTune(def, cgroup) < 0) + if (virCgroupSetupMemory(cgroup, def) < 0) goto cleanup; =20 if (virLXCCgroupSetupDeviceACL(def, cgroup) < 0) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index c9925ee5ca..22f77a03ad 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -554,19 +554,7 @@ qemuSetupMemoryCgroup(virDomainObjPtr vm) } } =20 - if (virMemoryLimitIsSet(vm->def->mem.hard_limit)) - if (virCgroupSetMemoryHardLimit(priv->cgroup, vm->def->mem.hard_li= mit) < 0) - return -1; - - if (virMemoryLimitIsSet(vm->def->mem.soft_limit)) - if (virCgroupSetMemorySoftLimit(priv->cgroup, vm->def->mem.soft_li= mit) < 0) - return -1; - - if (virMemoryLimitIsSet(vm->def->mem.swap_hard_limit)) - if (virCgroupSetMemSwapHardLimit(priv->cgroup, vm->def->mem.swap_h= ard_limit) < 0) - return -1; - - return 0; + return virCgroupSetupMemory(priv->cgroup, vm->def); } =20 =20 diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 165e5f4854..12af8759f7 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1670,6 +1670,36 @@ virCgroupSetMemory(virCgroupPtr group, unsigned long= long kb) setMemory, -1, kb); } =20 +/** + * virCgroupSetupMemory + * + * @group: The cgroup to change memory for + * @def: pointer to domian def + * + * Returns: 0 on success, -1 on error. + */ +int +virCgroupSetupMemory(virCgroupPtr group, virDomainDefPtr def) +{ + int ret =3D -1; + + if (virMemoryLimitIsSet(def->mem.hard_limit)) + if (virCgroupSetMemoryHardLimit(group, def->mem.hard_limit) < 0) + goto cleanup; + + if (virMemoryLimitIsSet(def->mem.soft_limit)) + if (virCgroupSetMemorySoftLimit(group, def->mem.soft_limit) < 0) + goto cleanup; + + if (virMemoryLimitIsSet(def->mem.swap_hard_limit)) + if (virCgroupSetMemSwapHardLimit(group, def->mem.swap_hard_limit) = < 0) + goto cleanup; + + ret =3D 0; + cleanup: + return ret; +} + =20 /** * virCgroupGetMemoryStat: diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 9815c51fda..17f07ea53c 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -179,6 +179,7 @@ int virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, unsigned long long *wbps); =20 int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb); +int virCgroupSetupMemory(virCgroupPtr group, virDomainDefPtr def); int virCgroupGetMemoryStat(virCgroupPtr group, unsigned long long *cache, unsigned long long *activeAnon, --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list