The below settings need to be applied whenever the system is booted.
NON_RT_CORES=f
# Try to move ALL kernel threads to the first 4 cores
pgrep -P 2 | xargs -i sudo taskset -p $NON_RT_CORES {}
# Assign CPU mask for all workqueues.
find /sys/devices/virtual/workqueue -name cpumask -exec sh -c "echo $NON_RT_CORES > {}" ';'
# Disable transparent hugepages, can cause page faults
echo never > /sys/kernel/mm/transparent_hugepage/enabled
# kernel memory merging, can cause page faults
echo 0 > /sys/kernel/mm/ksm/run
# and timer migrations
echo 0 > /proc/sys/kernel/timer_migration
# Lengthen the virtual memory update interval, only relevant for older kernels
echo 60 > /proc/sys/vm/stat_interval
# Set the scaling governor to *performance*
echo "performance" | sudo tee -a /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
# Make sure turbo boost is disabled
echo 1 | sudo tee -a /sys/devices/system/cpu/intel_pstate/no_turbo