Redhat and Centos have the command "tuned-adm" which has various machine profiles with settings like this. It is an official thing supported by the vendor.
This is a very clean approach preventing people from reinventing the wheel. I just found this, although not recently updated, which is tuned ported to Ubuntu: https://github.com/edwardbadboy/tuned-ubuntu
https://access.redhat.com/site/documentation/en-US/Red_Hat_E...
eg when I run it on one of our KVM hosts.