High‑Performance Computing (HPC) clusters squeeze every ounce of performance out of the underlying hardware. While powerful CPUs, fast interconnects, and optimized libraries are essential, the Linux kernel itself often becomes the hidden bottleneck. By carefully tuning kernel parameters you can reduce latency, improve memory throughput, and keep the scheduler happy during massive parallel workloads. This guide walks you through the most impactful tweaks, provides exact commands, highlights common mistakes, and equips you with the confidence to benchmark and persist your changes.
What You’ll Need
- A Linux distribution commonly used in HPC (CentOS, Rocky, Ubuntu Server, or openSUSE).
- Root or sudo privileges on each node you intend to tune.
- Basic familiarity with sysctl, sysfs, and kernel modules.
- Performance‑monitoring tools such as
perf,htop,numactl, andmpibenchmarks (e.g.,OSU Micro‑Benchmarks). - A backup of the original
/etc/sysctl.confand any custommodprobe.dfiles.
Step 1: Assess Your Current Baseline
Before you start changing anything, capture a performance baseline. Run a representative MPI benchmark (e.g., osu_latency) and record CPU, memory, and network metrics.
# Example baseline collection
mpirun -np 64 ./osu_latency -x 10 -i 1000 > baseline.txt
vmstat 5 12
sar -n DEV 5 12
Save the output in a directory named hpc_tuning_baseline. You will compare post‑tuning results against these numbers to quantify gains.
Step 2: Adjust the CPU Scheduler
The default CFS scheduler works well for general workloads but HPC jobs often benefit from a more deterministic scheduler. Two common approaches are:
- Switch to the
deadlinescheduler for low‑latency tasks. - Fine‑tune CFS parameters such as
sched_min_granularity_nsandsched_wakeup_granularity_ns.
To view the current scheduler for a device (e.g., eth0):
# cat /sys/block/sda/queue/scheduler Set the deadline scheduler globally (requires a reboot) by adding the following line to /etc/default/grub:
GRUB_CMDLINE_LINUX="elevator=deadline" Then rebuild the grub config and reboot:
# grub2-mkconfig -o /boot/grub2/grub.cfg # RHEL‑based
# update-grub # Debian‑based
# reboot If you prefer to stay with CFS but want tighter granularity, edit /etc/sysctl.conf:
kernel.sched_min_granularity_ns = 1000000 # 1 ms
kernel.sched_wakeup_granularity_ns = 1500000 # 1.5 ms Apply instantly with sysctl -p. These values reduce the time slice, allowing HPC threads to get CPU time more predictably.
Step 3: Tune Virtual Memory Settings
Memory pressure is a frequent source of jitter in scientific codes. The kernel’s virtual memory defaults are conservative for desktop use; HPC nodes usually have abundant RAM and can tolerate aggressive settings.
- vm.swappiness: Controls how eagerly the kernel swaps. Set to
1(or0on kernels that support it) to keep pages in RAM. - vm.dirty_ratio and vm.dirty_background_ratio: Define when the kernel starts flushing dirty pages to disk. Lower them to avoid I/O stalls during checkpointing.
- vm.overcommit_memory: For workloads that allocate large buffers, set to
1to allow overcommit without the OOM killer.
Add the following to /etc/sysctl.conf:
vm.swappiness = 1
vm.dirty_ratio = 10
vm.dirty_background_ratio = 5
vm.overcommit_memory = 1
vm.max_map_count = 262144 # useful for large MPI shared‑memory windows Reload:
# sysctl -p For NUMA‑aware systems, you may also want to enable transparent_hugepage=never (see Step 5) because automatic THP can interfere with explicit hugepage allocation.
Step 4: Optimize the Network Stack
Most HPC clusters rely on low‑latency fabrics like InfiniBand or high‑speed Ethernet. Kernel‑level TCP tweaks still matter for fallback paths and for MPI implementations that use sockets.
- Increase the size of the receive and send buffers.
- Enable
tcp_tw_reuseto recycle TIME_WAIT sockets faster. - Turn off
generic‑segmentation‑offload (GSO)if your NIC driver already handles segmentation efficiently.
Insert the following into /etc/sysctl.conf:
net.core.rmem_max = 134217728 # 128 MiB
net.core.wmem_max = 134217728
net.ipv4.tcp_rmem = 4096 87380 134217728
net.ipv4.tcp_wmem = 4096 65536 134217728
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1 Apply and verify:
# sysctl -p
# sysctl -a | grep -E 'rmem_max|wmem_max|tcp_tw_reuse' For InfiniBand, most of the tuning happens in the mlx4_core or mlx5_core driver via /sys/module/mlx5_core/parameters/*. Typical adjustments include:
# echo 0 > /sys/module/mlx5_core/parameters/disable_mad
# echo 0 > /sys/module/mlx5_core/parameters/disable_mad_ifc These commands turn off optional management datagrams that are rarely needed in pure compute workloads.
Step 5: Configure HugePages for Memory‑Intensive Applications
HugePages (2 MiB or 1 GiB) dramatically reduce TLB misses for large arrays common in CFD, molecular dynamics, or deep‑learning workloads.
First, decide on the page size. 2 MiB pages are the easiest to allocate; 1 GiB pages give the best reduction but require CPU support and careful alignment.
Check support:
# grep -i huge /proc/cpuinfo | wc -l # non‑zero means support Reserve a static pool of 2 MiB pages (example for a node with 256 GiB RAM, dedicating 64 GiB to HugePages):
# echo 32768 > /proc/sys/vm/nr_hugepages # 32768 × 2 MiB = 64 GiB To make it persistent, add to /etc/sysctl.conf:
vm.nr_hugepages = 32768 For 1 GiB pages, you need to load the hugepages module with a custom size:
# echo "options hugepagesz=1G nr_hugepages=64" > /etc/modprobe.d/hugepages.conf
# modprobe -r hugepages && modprobe hugepages Applications must be compiled with -DHUGETLB or use numactl --pages=1G to bind to the pool.
Validate allocation:
# cat /proc/meminfo | grep Huge Typical output:
HugePages_Total: 32768
HugePages_Free: 32768
HugePages_Rsvd: 0
HugePages_Surp: 0 Step 6: Persist Settings, Verify, and Benchmark
After applying all tweaks, reboot the nodes to ensure early‑boot parameters (GRUB, module options) take effect. Then run the same benchmark suite you used in Step 1.
# mpirun -np 64 ./osu_latency -x 10 -i 1000 > after_tuning.txt
# diff baseline.txt after_tuning.txt || true Look for reductions in latency (microseconds) and improvements in bandwidth (Gb/s). If results are not as expected, revert one change at a time to isolate the culprit.
For long‑term maintenance, store the custom configuration files in a version‑controlled repository (e.g., Git) and automate deployment with Ansible or SaltStack. This guarantees reproducibility across future hardware refreshes.
Common Mistakes to Avoid
1. Changing a single parameter without a baseline. Always benchmark before and after; otherwise you cannot prove the benefit.
2. Setting vm.swappiness to 0 on systems with insufficient RAM. The kernel will then stall when memory runs out, leading to OOM kills.
3. Over‑allocating HugePages. Reserving more memory than physically available can prevent the system from booting or cause other services to fail.
4. Forgetting to reload sysctl or reboot. Some settings (e.g., elevator=deadline) only take effect at boot time.
5. Disabling transparent hugepages globally. While explicit HugePages are preferred for HPC, leaving THP on for regular user workloads can cause page‑compaction pauses.
Tips and Tricks
• Use numactl --interleave=all for initial runs to verify that NUMA placement is not the bottleneck before pinning threads.
• Combine kernel tuning with application‑level environment variables, such as OMP_NUM_THREADS and MPI_IB_DISABLE_RDMA=0, for a holistic performance boost.
• Automate the collection of /proc/sys/kernel/* values before each deployment; this helps you spot drift over time.
• When using 1 GiB HugePages, align your data structures on 1 GiB boundaries to avoid fallback to regular pages.
• Keep an eye on the kernel log (dmesg) after each change; warnings about “unable to allocate hugepages” are early signs of mis‑configuration.
Frequently Asked Questions
Do I need to reboot after every sysctl change?
No. Most sysctl values take effect immediately with sysctl -p. However, parameters passed via the kernel command line (e.g., elevator=deadline) or module options require a reboot.
Can I use these tweaks on a virtualized HPC environment?
Yes, but with caution. Virtual machines often share the host’s scheduler and memory subsystem, so aggressive HugePage reservations may conflict with other guests. Prefer using virtio‑fs or SR‑IOV for network‑heavy workloads.
How often should I revisit kernel parameters?
Whenever you upgrade the kernel, add new hardware, or change your primary workload. A quarterly review combined with automated regression benchmarks is a good practice.
Conclusion
Optimizing Linux kernel parameters is not a one‑size‑fits‑all exercise; it requires measurement, iteration, and an understanding of how each knob influences CPU, memory, and network behavior. By following the six steps above—baseline measurement, scheduler tuning, virtual‑memory tweaks, network stack optimization, HugePage configuration, and rigorous verification—you’ll unlock measurable latency reductions and throughput gains for your HPC workloads. Remember to document every change, test methodically, and keep an eye on system logs. With these practices in place, your cluster will run closer to the hardware’s theoretical peak, giving researchers and engineers the computational edge they need.




