[libvirt] [PATCH 0/3] add percentage limit support for RAM filesystems in LXC container

From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> Chen Hanxiao (3): add percentage limit parse and define support for RAM filesystems enable percentage limit of RAM filesystem in lxc container docs: add docs for percentage limitation docs/formatdomain.html.in | 4 +++- src/conf/domain_conf.c | 21 +++++++++++++++++---- src/conf/domain_conf.h | 1 + src/lxc/lxc_container.c | 14 +++++++++++--- 4 files changed, 32 insertions(+), 8 deletions(-) -- 1.8.2.1

From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> This patch enables percentage limit for ram filesystem <filesystem type='ram'> <source usage='10%'/> <target dir='/mnt'/> </filesystem> Percentage limit would have more priority than size limit. Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/conf/domain_conf.c | 21 +++++++++++++++++---- src/conf/domain_conf.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d3f1ca2..25cfde2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6068,19 +6068,27 @@ virDomainFSDefParseXML(xmlNodePtr node, } if (def->type == VIR_DOMAIN_FS_TYPE_RAM) { + int len; if (!usage) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing 'usage' attribute for RAM filesystem")); goto error; } + len = strlen(usage); + if ('%' == usage[len - 1]) { + VIR_DEBUG("usage is %s\n", usage); + *(usage + len - 1) = '\0'; + def->usage_percentage = true; + } + if (virStrToLong_ull(usage, NULL, 10, &def->usage) < 0) { virReportError(VIR_ERR_XML_ERROR, _("cannot parse usage '%s' for RAM filesystem"), usage); goto error; } - if (virScaleInteger(&def->usage, units, - 1024, ULLONG_MAX) < 0) + if (!(def->usage_percentage) && + virScaleInteger(&def->usage, units, 1024, ULLONG_MAX) < 0) goto error; } @@ -14866,8 +14874,13 @@ virDomainFSDefFormat(virBufferPtr buf, break; case VIR_DOMAIN_FS_TYPE_RAM: - virBufferAsprintf(buf, " <source usage='%lld' units='KiB'/>\n", - def->usage / 1024); + if (def->usage_percentage) { + virBufferAsprintf(buf, " <source usage='%lld%%'/>\n", + def->usage); + } else { + virBufferAsprintf(buf, " <source usage='%lld' units='KiB'/>\n", + def->usage / 1024); + } break; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4561ccc..abfa756 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -891,6 +891,7 @@ struct _virDomainFSDef { int wrpolicy; /* enum virDomainFSWrpolicy */ int format; /* enum virStorageFileFormat */ unsigned long long usage; /* in bytes */ + bool usage_percentage; /* flag for percentage limit */ char *src; char *dst; bool readonly; -- 1.8.2.1

On Thu, Nov 28, 2013 at 05:14:43PM +0800, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
This patch enables percentage limit for ram filesystem
<filesystem type='ram'> <source usage='10%'/> <target dir='/mnt'/> </filesystem>
Percentage limit would have more priority than size limit.
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/conf/domain_conf.c | 21 +++++++++++++++++---- src/conf/domain_conf.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-)
I'm not really convinced we need this feature. Seems like more code for little real benefit. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

-----Original Message----- From: Daniel P. Berrange [mailto:berrange@redhat.com] Sent: Thursday, November 28, 2013 6:35 PM To: Chen Hanxiao Cc: libvir-list@redhat.com Subject: Re: [libvirt] [PATCH 1/3] add percentage limit parse and define support for RAM filesystems
On Thu, Nov 28, 2013 at 05:14:43PM +0800, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
This patch enables percentage limit for ram filesystem
<filesystem type='ram'> <source usage='10%'/> <target dir='/mnt'/> </filesystem>
Percentage limit would have more priority than size limit.
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/conf/domain_conf.c | 21 +++++++++++++++++---- src/conf/domain_conf.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-)
I'm not really convinced we need this feature. Seems like more code for little real benefit.
I think we should follow the style of mount(8). It accepted this style. And this feature could bring us convenience in config, free us from counting the size. Thanks.
Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

-----Original Message----- From: libvir-list-bounces@redhat.com [mailto:libvir-list-bounces@redhat.com]
On Thu, Nov 28, 2013 at 05:14:43PM +0800, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
This patch enables percentage limit for ram filesystem
<filesystem type='ram'> <source usage='10%'/> <target dir='/mnt'/> </filesystem>
Percentage limit would have more priority than size limit.
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/conf/domain_conf.c | 21 +++++++++++++++++---- src/conf/domain_conf.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-)
I'm not really convinced we need this feature. Seems like more code for little real benefit.
I think we should follow the style of mount(8). It accepted this style.
And this feature could bring us convenience in config, free us from counting the size.
Thanks.
Hi Daniel Do we really don't need this feature? Or we may need some code optimization? Thanks.

On Thu, Dec 05, 2013 at 07:40:58PM +0800, Chen Hanxiao wrote:
-----Original Message----- From: libvir-list-bounces@redhat.com [mailto:libvir-list-bounces@redhat.com]
On Thu, Nov 28, 2013 at 05:14:43PM +0800, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
This patch enables percentage limit for ram filesystem
<filesystem type='ram'> <source usage='10%'/> <target dir='/mnt'/> </filesystem>
Percentage limit would have more priority than size limit.
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/conf/domain_conf.c | 21 +++++++++++++++++---- src/conf/domain_conf.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-)
I'm not really convinced we need this feature. Seems like more code for little real benefit.
I think we should follow the style of mount(8). It accepted this style.
And this feature could bring us convenience in config, free us from counting the size.
Do we really don't need this feature? Or we may need some code optimization?
I just don't see this as a compelling feature. I think it is more important to have a single canonical representation of memory allocation. User convenience is something for higher level tools to worry about. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 12/05/2013 04:56 AM, Daniel P. Berrange wrote:
This patch enables percentage limit for ram filesystem
<filesystem type='ram'> <source usage='10%'/> <target dir='/mnt'/> </filesystem>
I just don't see this as a compelling feature. I think it is more important to have a single canonical representation of memory allocation. User convenience is something for higher level tools to worry about.
But do higher level tools already have a way to query libvirt what the current host's available ram is, in order to determine percentages itself? We can't really migrate online LXC guests, but for an offline guest setup, copying XML from one host with small memory to another host with large memory, and still having the guest have a fixed percentage of the host resources (more memory assigned to the guest on the larger host), seems like a reasonable desire; to achieve that, the management tool needs to be able to either request percentages (no change to the guest xml being copied) or know the host resource limits (and rewrite the xml rather than merely copy it). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Thu, Dec 05, 2013 at 06:12:22AM -0700, Eric Blake wrote:
On 12/05/2013 04:56 AM, Daniel P. Berrange wrote:
This patch enables percentage limit for ram filesystem
<filesystem type='ram'> <source usage='10%'/> <target dir='/mnt'/> </filesystem>
I just don't see this as a compelling feature. I think it is more important to have a single canonical representation of memory allocation. User convenience is something for higher level tools to worry about.
But do higher level tools already have a way to query libvirt what the current host's available ram is, in order to determine percentages itself? We can't really migrate online LXC guests, but for an offline guest setup, copying XML from one host with small memory to another host with large memory, and still having the guest have a fixed percentage of the host resources (more memory assigned to the guest on the larger host), seems like a reasonable desire; to achieve that, the management tool needs to be able to either request percentages (no change to the guest xml being copied) or know the host resource limits (and rewrite the xml rather than merely copy it).
We do have APIs for querying host RAM, but if we wanted this, which I don't think we do, then tmpfs RAM % would want to be relative to guest RAM allocation not host RAM. It doesn't make sense to have guest XML whose semantics differ according to the host environment - they should be self-contained. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 12/05/2013 06:17 AM, Daniel P. Berrange wrote:
On Thu, Dec 05, 2013 at 06:12:22AM -0700, Eric Blake wrote:
On 12/05/2013 04:56 AM, Daniel P. Berrange wrote:
> > This patch enables percentage limit for ram filesystem > > <filesystem type='ram'> > <source usage='10%'/> > <target dir='/mnt'/> > </filesystem> >
We do have APIs for querying host RAM, but if we wanted this, which I don't think we do, then tmpfs RAM % would want to be relative to guest RAM allocation not host RAM.
Ah - if you make that argument, then I agree - a management tool can always calculate a percentage of guest-visible RAM.
It doesn't make sense to have guest XML whose semantics differ according to the host environment - they should be self-contained.
Right - if we ever supported live migration, changing guest-visible attributes during the migration is a non-starter. So the XML must not be tied to host percentage, at which point I don't see a reason for supporting percentage in the XML. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

-----Original Message----- From: Daniel P. Berrange [mailto:berrange@redhat.com] Sent: Thursday, December 05, 2013 9:17 PM
I just don't see this as a compelling feature. I think it is more important to have a single canonical representation of memory allocation. User convenience is something for higher level tools to worry about.
But do higher level tools already have a way to query libvirt what the current host's available ram is, in order to determine percentages itself? We can't really migrate online LXC guests, but for an offline guest setup, copying XML from one host with small memory to another host with large memory, and still having the guest have a fixed percentage of the host resources (more memory assigned to the guest on the larger host), seems like a reasonable desire; to achieve that, the management tool needs to be able to either request percentages (no change to the guest xml being copied) or know the host resource limits (and rewrite the xml rather than merely copy it).
We do have APIs for querying host RAM, but if we wanted this, which I don't think we do, then tmpfs RAM % would want to be relative to guest RAM allocation not host RAM. It doesn't make sense to have guest XML whose semantics differ according to the host environment - they should be self-contained.
If we could set tmpfs RAM % according to guest memory allocation(domain/memory section), does that make sense?
Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/lxc/lxc_container.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 2bdf957..408499a 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -1447,9 +1447,17 @@ static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs, VIR_DEBUG("usage=%lld sec=%s", fs->usage, sec_mount_options); - if (virAsprintf(&data, - "size=%lld%s", fs->usage, sec_mount_options) < 0) - goto cleanup; + if (fs->usage_percentage) { + VIR_DEBUG("use percentage limit for tmpfs"); + if (virAsprintf(&data, + "size=%lld%%%s", fs->usage, sec_mount_options) < 0) + goto cleanup; + } else { + VIR_DEBUG("use size limit for tmpfs"); + if (virAsprintf(&data, + "size=%lld%s", fs->usage, sec_mount_options) < 0) + goto cleanup; + } if (virFileMakePath(fs->dst) < 0) { virReportSystemError(errno, -- 1.8.2.1

From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- docs/formatdomain.html.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 096e2a3..ac330cb 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2233,7 +2233,9 @@ An in-memory filesystem, using memory from the host OS. The source element has a single attribute <code>usage</code> which gives the memory usage limit in KiB, unless units - are specified by the <code>units</code> attribute. Only used + are specified by the <code>units</code> attribute. + Attribute <code>usage</code> with a suffix % will gives + the memory usage limit by percentage.Only used by LXC driver. <span class="since"> (since 0.9.13)</span></dd> <dt><code>type='bind'</code></dt> -- 1.8.2.1

On 11/28/2013 02:14 AM, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- docs/formatdomain.html.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 096e2a3..ac330cb 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2233,7 +2233,9 @@ An in-memory filesystem, using memory from the host OS. The source element has a single attribute <code>usage</code> which gives the memory usage limit in KiB, unless units - are specified by the <code>units</code> attribute. Only used + are specified by the <code>units</code> attribute. + Attribute <code>usage</code> with a suffix % will gives + the memory usage limit by percentage.Only used
Although we are not taking this series, remember that English always has space after a sentence. s/\.Only/. Only/ -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

-----Original Message----- From: Eric Blake [mailto:eblake@redhat.com] Sent: Thursday, December 05, 2013 9:50 PM To: Chen Hanxiao; libvir-list@redhat.com Subject: Re: [libvirt] [PATCH 3/3] docs: add docs for percentage limit
On 11/28/2013 02:14 AM, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- docs/formatdomain.html.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 096e2a3..ac330cb 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2233,7 +2233,9 @@ An in-memory filesystem, using memory from the host OS. The source element has a single attribute <code>usage</code> which gives the memory usage limit in KiB, unless units - are specified by the <code>units</code> attribute. Only used + are specified by the <code>units</code> attribute. + Attribute <code>usage</code> with a suffix % will gives + the memory usage limit by percentage.Only used
Although we are not taking this series, remember that English always has space after a sentence. s/\.Only/. Only/
Thanks, I see.
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (3)
-
Chen Hanxiao
-
Daniel P. Berrange
-
Eric Blake