+def deallocate_hugepages():
+ """De-allocate hugepages that were allocated on the fly
+ """
+ # pylint: disable=global-statement
+ global _ALLOCATED_HUGEPAGES
+ if _ALLOCATED_HUGEPAGES:
+ nr_hugepages = 'vm.nr_hugepages= 0'
+ try:
+ tasks.run_task(['sudo', 'sysctl', nr_hugepages],
+ _LOGGER, 'Trying to de-allocate hugepages..', True)
+ except subprocess.CalledProcessError:
+ _LOGGER.error('Unable to de-allocate hugepages.')
+ return False
+ _ALLOCATED_HUGEPAGES = False
+ return True
+