libvirt-bin support for hugepages: apparmor needs a rule for hugetlbfs

Bug #1001584 reported by Antti S. Lankila
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
libvirt (Ubuntu)
Expired
Medium
Unassigned

Bug Description

Firstly, transparent hugepages can be enabled with:

# echo always > /sys/kernel/mm/transparent_hugepage/enabled

they are nice and easy to get working, but do not survive memory pressure on the host. I/O pressure on the host breaks the 2M pages back to 4k pages, and therefore renders transparent hugepages useless for long-lived processes, as nothing will reassemble the 4k pages back to 2M pages after memory pressure has ceased. So, kvm should be set up using explicit hugetlbfs support for now.

Firstly, kvm is very irritating in that it tends to silently use ordinarily backed memory if hugepage support fails to work, so for a while I thought things were fine despite I had just wasted >8 GB of memory on unused hugepages. This is, however, something to fix within kvm itself rather, and it may be that this is how kvm maintainers prefer it to work. I personally disagree, but it is possible to cat /proc/meminfo and observe if kvm is using hugepages or not: HugePages_Free value equals HugePages_Total when nobody is using hugepages.

I chose to mount hugetlbfs at /hugepages, which makes the directory for kvm's memory pages /hugepages/libvirt/qemu. libvirt-bin had to be restarted for it to recognize the hugetlbfs mount location. I need total of 4400 hugetlb pages for my VMs, so I wrote a /etc/sysctl.d/60-custom.conf which says "vm.nr_hugepages=4400" and set that value using sysctl -w. I had to retry that command a bunch of times, each time getting more hugepages than before, until finally I got all 4400.

However, apparmor still denies access to the hugepage mount point by default. I added a line such as "/hugepages/libvirt/qemu/* rw," to every virtual machine's apparmor profie, which are generated from /etc/apparmor.d/libvirt/TEMPLATE by libvirt-aa-helper. I did not discover a way to regenerate the files from the TEMPLATE, so I just manually modified every one after fixing the TEMPLATE file.

I would suggest that libvirt-aa-helper should detect hugepages usage from the domain configuration file (<memoryBacking><hugepages/></memoryBacking>) and then find out where hugepages are mounted and add that rw grant to that location.

$ lsb_release -rd
Description: Ubuntu 12.04 LTS
Release: 12.04

$ apt-cache policy libvirt-bin
libvirt-bin:
  Installed: 0.9.8-2ubuntu17.1
  Candidate: 0.9.8-2ubuntu17.1
  Version table:
 *** 0.9.8-2ubuntu17.1 0
        500 http://fi.archive.ubuntu.com/ubuntu/ precise-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     0.9.8-2ubuntu17 0
        500 http://fi.archive.ubuntu.com/ubuntu/ precise/main amd64 Packages

Changed in libvirt (Ubuntu):
importance: Undecided → Medium
Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Please see

http://wiki.debian.org/Hugepages

and

http://www.linux-kvm.com/content/get-performance-boost-backing-your-kvm-guest-hugetlbfs

for more info on how to use hugepages. In particular, if you need exactly
4400 pages (8.8G) for your guest, then do reserve some extra pages for
overhead.

Unless that solves your problem for you, could you please have your system
provide some debugging information using

sudo apport-collect 1001584

on the server?

Changed in libvirt (Ubuntu):
status: New → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for libvirt (Ubuntu) because there has been no activity for 60 days.]

Changed in libvirt (Ubuntu):
status: Incomplete → Expired
Revision history for this message
Guilhem Lettron (guilhem-fr) wrote :

I confirm, adding "/hugepages/libvirt/qemu/* rw," solve hugepages kvm.

To "really" solve this problem, I think a package like "cgroup-lite" must be created with a default mount point to "/sys/fs/hugepages" and add "/sys/fs/hugepages/libvirt/qemu/* rw," to apparmor abstraction.

What do you think about it ?

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : Re: [Bug 1001584] Re: libvirt-bin support for hugepages: apparmor needs a rule for hugetlbfs

Quoting Guilhem Lettron (<email address hidden>):
> I confirm, adding "/hugepages/libvirt/qemu/* rw," solve hugepages kvm.
>
> To "really" solve this problem, I think a package like "cgroup-lite"
> must be created with a default mount point to "/sys/fs/hugepages" and
> add "/sys/fs/hugepages/libvirt/qemu/* rw," to apparmor abstraction.
>
> What do you think about it ?

That sounds like a good idea. I'll add it to UDS topics for the libvirt
blueprint - thanks!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.