Add function to adjust temp. swapiness
This commit is contained in:
parent
68b2a8074c
commit
2d22f15f22
@ -13,7 +13,7 @@ class SwapModule(AbstractModule):
|
||||
|
||||
actions = ["Create/Resize temp. swap", "Create/Resize persistent swap", "Delete swap",
|
||||
"Make temp. swap persistent", "Get swap location", "Get swap size",
|
||||
"Show swapiness"]
|
||||
"Show swapiness", "Adjust temp. swapiness"]
|
||||
menu = [
|
||||
{
|
||||
'type': 'list',
|
||||
@ -38,6 +38,8 @@ class SwapModule(AbstractModule):
|
||||
self.swap_location_check()
|
||||
elif selected_action == "Get swap size":
|
||||
self.get_swap_size()
|
||||
elif selected_action == "Adjust temp. swapiness":
|
||||
self.adjust_swapiness_temp()
|
||||
|
||||
def swap_location_check(self) -> None:
|
||||
output_swaps = subprocess.check_output(['cat', '/proc/swaps']).decode("UTF-8")
|
||||
@ -101,6 +103,31 @@ class SwapModule(AbstractModule):
|
||||
|
||||
subprocess.call(get_swapiness, shell=True)
|
||||
|
||||
def adjust_swapiness_temp(self):
|
||||
actions = ["Light", "Default", "Aggressive"]
|
||||
menu = [
|
||||
{
|
||||
'type': 'list',
|
||||
'message': 'Select action',
|
||||
'name': 'action',
|
||||
'choices': list(map(lambda x: {"name": x}, actions))
|
||||
}
|
||||
]
|
||||
selected_swapiness = prompt(menu)['action']
|
||||
|
||||
if selected_swapiness == "Light":
|
||||
adjust = "sudo sysctl vm.swappiness=25"
|
||||
subprocess.call(adjust, shell=True)
|
||||
print("Temporary swapiness is 25")
|
||||
elif selected_swapiness == "Default":
|
||||
adjust = "sudo sysctl vm.swappiness=60"
|
||||
subprocess.call(adjust, shell=True)
|
||||
print("Temporary swapiness is 60")
|
||||
elif selected_swapiness == "Aggressive":
|
||||
adjust = "sudo sysctl vm.swappiness=100"
|
||||
subprocess.call(adjust, shell=True)
|
||||
print("Temporary swapiness is 100")
|
||||
|
||||
def delete_swap(self):
|
||||
self.swap_location_check()
|
||||
disable_swapfile = """sudo swapoff {0} &&
|
||||
|
Loading…
Reference in New Issue
Block a user