FeralInteractive / gamemode

Optimise Linux system performance on demand
BSD 3-Clause "New" or "Revised" License
4.67k stars 184 forks source link

Enable Transparent Hugepages when Gaming #465

Open sockusminimus opened 6 months ago

sockusminimus commented 6 months ago

Transparent Hugepages (THP) have the kernel allocate memory pages in 2MiB or 2GiB units instead of 4KiB units as is the platform default on X86. This has been shown to measurably improve gaming performance in many cases. The risk for enabling this is low, as some distros do this by default (such as OpenSUSE). It is also a kernel tunable that can be set at runtime using sysctl.

I propose we enable THP and disable proactive compaction for gaming sessions and set these back to default when the session ends (as some workloads such as databases can be negatively impacted by memory fragmentation that this can cause).

My proposal is to enable the following when gaming and restore when game ends: echo always | sudo tee /sys/kernel/mm/transparent_hugepage/enabled echo advise | sudo tee /sys/kernel/mm/transparent_hugepage/shmem_enabled echo 0 | sudo tee /proc/sys/vm/compaction_proactiveness echo 0 | sudo tee /sys/kernel/mm/transparent_hugepage/khugepaged/defrag

See e.g. https://github.com/CryoByte33/steam-deck-utilities/blob/main/docs/tweak-explanation.md See also https://blog.patshead.com/2023/02/enabling-transparent-hugepages-can-provide-huge-gaming-performance-improvements.html See also https://alexandrnikitin.github.io/blog/transparent-hugepages-measuring-the-performance-impact/