2017-09-27 16:35:23 -04:00
|
|
|
# Copyright (c) 2016 Cisco and/or its affiliates.
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at:
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2018-12-19 02:05:25 -08:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2017-09-27 16:35:23 -04:00
|
|
|
"""VPP Huge Page Utilities"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
from vpplib.VPPUtil import VPPUtil
|
|
|
|
|
|
|
|
# VPP Huge page File
|
|
|
|
DEFAULT_VPP_HUGE_PAGE_CONFIG_FILENAME = "/etc/vpp/80-vpp.conf"
|
|
|
|
VPP_HUGEPAGE_CONFIG = """
|
|
|
|
vm.nr_hugepages={nr_hugepages}
|
|
|
|
vm.max_map_count={max_map_count}
|
|
|
|
vm.hugetlb_shm_group=0
|
|
|
|
kernel.shmmax={shmmax}
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class VppHugePageUtil(object):
|
|
|
|
"""
|
|
|
|
Huge Page Utilities
|
|
|
|
"""
|
2022-04-26 19:02:15 +02:00
|
|
|
|
2017-09-27 16:35:23 -04:00
|
|
|
def hugepages_dryrun_apply(self):
|
|
|
|
"""
|
|
|
|
Apply the huge page configuration
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
node = self._node
|
2022-04-26 19:02:15 +02:00
|
|
|
hugepages = node["hugepages"]
|
2017-09-27 16:35:23 -04:00
|
|
|
|
|
|
|
vpp_hugepage_config = VPP_HUGEPAGE_CONFIG.format(
|
2022-04-26 19:02:15 +02:00
|
|
|
nr_hugepages=hugepages["total"],
|
|
|
|
max_map_count=hugepages["max_map_count"],
|
|
|
|
shmmax=hugepages["shmax"],
|
|
|
|
)
|
2017-09-27 16:35:23 -04:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
rootdir = node["rootdir"]
|
|
|
|
filename = rootdir + node["hugepages"]["hugepage_config_file"]
|
2017-09-27 16:35:23 -04:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
cmd = 'echo "{0}" | sudo tee {1}'.format(vpp_hugepage_config, filename)
|
2017-09-27 16:35:23 -04:00
|
|
|
(ret, stdout, stderr) = VPPUtil.exec_command(cmd)
|
|
|
|
if ret != 0:
|
2022-04-26 19:02:15 +02:00
|
|
|
raise RuntimeError(
|
|
|
|
"{} failed on node {} {} {}".format(cmd, node["host"], stdout, stderr)
|
|
|
|
)
|
2017-09-27 16:35:23 -04:00
|
|
|
|
|
|
|
def get_actual_huge_pages(self):
|
|
|
|
"""
|
|
|
|
Get the current huge page configuration
|
|
|
|
|
|
|
|
:returns the hugepage total, hugepage free, hugepage size,
|
|
|
|
total memory, and total memory free
|
|
|
|
:rtype: tuple
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Get the memory information using /proc/meminfo
|
2022-04-26 19:02:15 +02:00
|
|
|
cmd = "sudo cat /proc/meminfo"
|
2017-09-27 16:35:23 -04:00
|
|
|
(ret, stdout, stderr) = VPPUtil.exec_command(cmd)
|
|
|
|
if ret != 0:
|
|
|
|
raise RuntimeError(
|
2022-04-26 19:02:15 +02:00
|
|
|
"{} failed on node {} {} {}".format(
|
|
|
|
cmd, self._node["host"], stdout, stderr
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
total = re.findall(r"HugePages_Total:\s+\w+", stdout)
|
|
|
|
free = re.findall(r"HugePages_Free:\s+\w+", stdout)
|
|
|
|
size = re.findall(r"Hugepagesize:\s+\w+\s+\w+", stdout)
|
|
|
|
memtotal = re.findall(r"MemTotal:\s+\w+\s+\w+", stdout)
|
|
|
|
memfree = re.findall(r"MemFree:\s+\w+\s+\w+", stdout)
|
|
|
|
|
|
|
|
total = total[0].split(":")[1].lstrip()
|
|
|
|
free = free[0].split(":")[1].lstrip()
|
|
|
|
size = size[0].split(":")[1].lstrip()
|
|
|
|
memtotal = memtotal[0].split(":")[1].lstrip()
|
|
|
|
memfree = memfree[0].split(":")[1].lstrip()
|
2017-09-27 16:35:23 -04:00
|
|
|
return total, free, size, memtotal, memfree
|
|
|
|
|
|
|
|
def show_huge_pages(self):
|
|
|
|
"""
|
|
|
|
Print the current huge page configuration
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
node = self._node
|
2022-04-26 19:02:15 +02:00
|
|
|
hugepages = node["hugepages"]
|
|
|
|
print(" {:30}: {}".format("Total System Memory", hugepages["memtotal"]))
|
|
|
|
print(" {:30}: {}".format("Total Free Memory", hugepages["memfree"]))
|
|
|
|
print(" {:30}: {}".format("Actual Huge Page Total", hugepages["actual_total"]))
|
|
|
|
print(" {:30}: {}".format("Configured Huge Page Total", hugepages["total"]))
|
|
|
|
print(" {:30}: {}".format("Huge Pages Free", hugepages["free"]))
|
|
|
|
print(" {:30}: {}".format("Huge Page Size", hugepages["size"]))
|
2017-09-27 16:35:23 -04:00
|
|
|
|
|
|
|
def get_huge_page_config(self):
|
|
|
|
"""
|
|
|
|
Returns the huge page config.
|
|
|
|
|
|
|
|
:returns: The map max count and shmmax
|
|
|
|
"""
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
total = self._node["hugepages"]["total"]
|
2017-09-27 16:35:23 -04:00
|
|
|
max_map_count = int(total) * 2 + 1024
|
|
|
|
shmmax = int(total) * 2 * 1024 * 1024
|
|
|
|
return max_map_count, shmmax
|
|
|
|
|
|
|
|
def __init__(self, node):
|
|
|
|
self._node = node
|