From nobody Tue Nov 26 09:42:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1581975016292356.5507681085172; Mon, 17 Feb 2020 13:30:16 -0800 (PST) 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-179-VVK1WMInP6W-8ljc8N0bzw-1; Mon, 17 Feb 2020 16:30:13 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 486C9801E67; Mon, 17 Feb 2020 21:30:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 021BB5DA76; Mon, 17 Feb 2020 21:30:07 +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 85F9935B09; Mon, 17 Feb 2020 21:30:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01HLTbEe031992 for ; Mon, 17 Feb 2020 16:29:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 99C7410E60DF; Mon, 17 Feb 2020 21:29:37 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 950021003342 for ; Mon, 17 Feb 2020 21:29:35 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0FF7D8026E3 for ; Mon, 17 Feb 2020 21:29:35 +0000 (UTC) Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-305-EstgAPnDMk-zAX_1zrvRkQ-1; Mon, 17 Feb 2020 16:29:32 -0500 Received: by mail-qv1-f68.google.com with SMTP id n8so8201813qvg.11; Mon, 17 Feb 2020 13:29:32 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975015; 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=TaluYkgBZazlzuwVmFq3zdIf0tPdsYfuNbFSZSZpP9M=; b=OWvFkux9LUgobuca8TXEII4t/fVWa1NXPqByXvgRIgO604fg6K4KDwYu/TQ14FSCbxhhjH 8msbR8f1GZz15LlG7qLS4lI/JweShnQy24nD8s458p2qz80+YAwY8KZhjpohQLdEWx14oV wPj7W1DGtUMybMy0yq1Kgyz5LPVzEEg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YDSPrc6zUPSrXAJj1rpCVw/NxCKjC4eFzZnQnTzRJog=; b=NIWBMQXtF9DnC6I3a+XgqmsmmAw/pHyRIIZ9gPvxkwPWBTUw7ss3jkJ0gYp48BYrXj KCjV29pi4wpfDMYrsM+wETkA1Wqvne8ZhiOG464I///+u9NfYL1dgmonpjo7ASx7xbxM MGDY/usNpb72SSlFDQh/ObM7ZhkRMH3jK2cjnWOaEndoZN4WuyUA4R44q5Wmp7F87Xsb jyH7USM6CLz5RhQuzBCYRRcq8Hgxbj6btL5Sg1fIfajDnSmINck1LprWcp1CcOpBWRcF Yhav08v7mWgy3GjBjhOmdezqOF7ZhFp1f6TB/HZxXlPCr4Y/FweGVDtLT1KAu32VjlaK k+ww== X-Gm-Message-State: APjAAAXY9k14ISwjr9jMZ0vCYoS8SUm5y9skinVvRaBHPKcBvMX7YUTd IpsgQ6F+vjRnNepJ4MbLoIMJ0+QmUVc= X-Google-Smtp-Source: APXvYqx0P+yUHm6+WUr+FdDboFddsy8YHmErxSm7b9ZD+Y1JFbTtRBZjbzXgiPcitlA/qiBeolI7jg== X-Received: by 2002:a0c:e408:: with SMTP id o8mr14427672qvl.236.1581974972156; Mon, 17 Feb 2020 13:29:32 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 05/14] domain_cgroup.c: add virDomainCgroupSetupMemtune() Date: Mon, 17 Feb 2020 16:29:12 -0500 Message-Id: <20200217212921.251616-6-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: EstgAPnDMk-zAX_1zrvRkQ-1 X-MC-Unique: VVK1WMInP6W-8ljc8N0bzw-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01HLTbEe031992 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" virLXCCgroupSetupMemTune() and qemuSetupMemoryCgroup() shares duplicated code that can be put in a new helper to avoid code repetition. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- src/hypervisor/domain_cgroup.c | 19 +++++++++++++++++++ src/hypervisor/domain_cgroup.h | 1 + src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 14 +------------- src/qemu/qemu_cgroup.c | 14 +------------- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/hypervisor/domain_cgroup.c b/src/hypervisor/domain_cgroup.c index bef60f56c5..e60abd536c 100644 --- a/src/hypervisor/domain_cgroup.c +++ b/src/hypervisor/domain_cgroup.c @@ -65,3 +65,22 @@ virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomain= Blkiotune blkio) =20 return 0; } + + +int +virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem) +{ + if (virMemoryLimitIsSet(mem.hard_limit)) + if (virCgroupSetMemoryHardLimit(cgroup, mem.hard_limit) < 0) + return -1; + + if (virMemoryLimitIsSet(mem.soft_limit)) + if (virCgroupSetMemorySoftLimit(cgroup, mem.soft_limit) < 0) + return -1; + + if (virMemoryLimitIsSet(mem.swap_hard_limit)) + if (virCgroupSetMemSwapHardLimit(cgroup, mem.swap_hard_limit) < 0) + return -1; + + return 0; +} diff --git a/src/hypervisor/domain_cgroup.h b/src/hypervisor/domain_cgroup.h index af244bd2d2..82ba47e85f 100644 --- a/src/hypervisor/domain_cgroup.h +++ b/src/hypervisor/domain_cgroup.h @@ -25,3 +25,4 @@ =20 =20 int virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blki= o); +int virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index dc06b1ae24..1bc5d17000 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1391,6 +1391,7 @@ virSetConnectStorage; =20 # hypervisor/domain_cgroup.h virDomainCgroupSetupBlkio; +virDomainCgroupSetupMemtune; =20 =20 # libvirt_internal.h diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 96a89256a1..eac1ee1ee0 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -112,19 +112,7 @@ static int virLXCCgroupSetupMemTune(virDomainDefPtr de= f, if (virCgroupSetMemory(cgroup, virDomainDefGetMemoryInitial(def)) < 0) return -1; =20 - if (virMemoryLimitIsSet(def->mem.hard_limit)) - if (virCgroupSetMemoryHardLimit(cgroup, def->mem.hard_limit) < 0) - return -1; - - if (virMemoryLimitIsSet(def->mem.soft_limit)) - if (virCgroupSetMemorySoftLimit(cgroup, def->mem.soft_limit) < 0) - return -1; - - if (virMemoryLimitIsSet(def->mem.swap_hard_limit)) - if (virCgroupSetMemSwapHardLimit(cgroup, def->mem.swap_hard_limit)= < 0) - return -1; - - return 0; + return virDomainCgroupSetupMemtune(cgroup, def->mem); } =20 =20 diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 475c063823..0c2f5f1b25 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -625,19 +625,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 virDomainCgroupSetupMemtune(priv->cgroup, vm->def->mem); } =20 =20 --=20 2.24.1