1
# -*- coding: utf-8 -*-
3
# Copyright 2014-2015 Canonical Limited.
5
# This file is part of charm-helpers.
7
# charm-helpers is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Lesser General Public License version 3 as
9
# published by the Free Software Foundation.
11
# charm-helpers is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Lesser General Public License for more details.
16
# You should have received a copy of the GNU Lesser General Public License
17
# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
20
from charmhelpers.core import fstab
21
from charmhelpers.core import sysctl
22
from charmhelpers.core.host import (
30
def hugepage_support(user, group='hugetlb', nr_hugepages=256,
31
max_map_count=65536, mnt_point='/run/hugepages/kvm',
32
pagesize='2MB', mount=True):
33
"""Enable hugepages on system.
36
user (str) -- Username to allow access to hugepages to
37
group (str) -- Group name to own hugepages
38
nr_hugepages (int) -- Number of pages to reserve
39
max_map_count (int) -- Number of Virtual Memory Areas a process can own
40
mnt_point (str) -- Directory to mount hugepages on
41
pagesize (str) -- Size of hugepages
42
mount (bool) -- Whether to Mount hugepages
44
group_info = add_group(group)
45
gid = group_info.gr_gid
46
add_user_to_group(user, group)
48
'vm.nr_hugepages': nr_hugepages,
49
'vm.max_map_count': max_map_count,
50
'vm.hugetlb_shm_group': gid,
52
sysctl.create(yaml.dump(sysctl_settings), '/etc/sysctl.d/10-hugepage.conf')
53
mkdir(mnt_point, owner='root', group='root', perms=0o755, force=False)
54
lfstab = fstab.Fstab()
55
fstab_entry = lfstab.get_entry_by_attr('mountpoint', mnt_point)
57
lfstab.remove_entry(fstab_entry)
58
entry = lfstab.Entry('nodev', mnt_point, 'hugetlbfs',
59
'mode=1770,gid={},pagesize={}'.format(gid, pagesize), 0, 0)
60
lfstab.add_entry(entry)
62
fstab_mount(mnt_point)