Think of Linux memory management as a careful balance between speed, stability, and space. The kernel constantly decides what to keep in RAM, what to write to disk, and how aggressively to clean up memory.
When you want maximum performance — especially for gaming, compiling, or benchmarking — you can tune these knobs to reduce latency and ensure your most important data never leaves fast memory.
Let’s go parameter by parameter.
1.vm.swappiness = 0
Default: 60
Meaning: Controls how aggressively Linux uses swap space.
- 0 tells the kernel: “Never swap unless absolutely out of memory.”
- 100 means: “Use swap freely.”
Why it matters:
Swapping moves data from RAM to the disk, which is millions of times slower. Setting it to 0 keeps all active data in RAM, improving performance — especially for gaming or low-latency tasks.
However, on systems with very little memory, setting this too low can cause out-of-memory (OOM) crashes.
2. vm.vfs_cache_pressure = 50
Default: 100
Meaning: Balances the reclaiming of inode and dentry caches (metadata that helps the system find files quickly).
- Lower = keep file system metadata cached longer.
- Higher = reclaim it aggressively to free memory.
Why it matters:
Keeping these caches longer speeds up file access. Setting it to 50 gives a nice performance boost, especially when you frequently open and close many files — like during game loading or compiling.
3. vm.dirty_background_ratio = 2
Default: 10
Meaning: Percentage of system memory filled with “dirty” (modified) pages before the kernel starts writing them to disk in the background.
Why it matters:
A smaller value like 2 means Linux starts flushing data earlier, keeping I/O operations smoother and preventing sudden lags or write spikes. It’s great for gaming systems that need consistent performance.
4. vm.dirty_ratio = 5
Default: 20
Meaning: The maximum percentage of “dirty” pages before the kernel forces processes to stop and write them out.
Why it matters:
Lowering this to 5 helps maintain system responsiveness and prevents massive disk writes from freezing your machine.
5. vm.dirty_writeback_centisecs = 500
Default: 500 (5 seconds)
Meaning: How often (in hundredths of a second) the kernel’s background flusher thread wakes up to write dirty data to disk.
Why it matters:
Keeping it at 500 balances latency and disk wear. Lowering it further can reduce latency slightly but increases disk activity.
6. vm.pagecache_limit_mb = 0
Default: 0 (unlimited)
Meaning: Limits the total size of the page cache.
Why it matters:
You usually don’t need to touch this unless you’re on a very low-memory system. Leaving it at 0 ensures Linux can freely use available RAM for caching.
7. vm.overcommit_memory = 1
Default: 0
Meaning: Controls how Linux handles memory allocations beyond physical RAM.
- 0 = heuristic mode (kernel guesses how much memory it can safely allocate)
- 1 = always allow allocations beyond physical memory (risk of OOM)
- 2 = strict mode (don’t overcommit beyond limits)
Why it matters:
Setting 1 allows applications to allocate more memory than physically available — beneficial for certain workloads and large games that pre-allocate memory.
8. vm.overcommit_ratio = 100
Default: 50
Meaning: Used when overcommit_memory=2, defining how much swap + RAM can be allocated.
Even though it doesn’t apply directly when overcommit is 1, keeping it at 100 ensures flexibility in case of future changes.
9. vm.max_map_count = 262144
Default: 65530
Meaning: Defines the maximum number of memory map areas a process may have.
Why it matters:
Some modern games (especially those using Vulkan or large textures), databases, and browsers need more mappings. Raising this value prevents “out of memory” or “cannot allocate memory map” errors.
10. vm.min_free_kbytes = 65536
Default: ~67584 (depends on kernel and RAM size)
Meaning: Minimum free memory the kernel keeps available for critical system tasks.
Why it matters:
Setting it too low can cause instability under heavy load; too high wastes memory. Around 64MB is a safe and performance-oriented choice for most modern systems.
11. vm.nr_hugepages = 1024
Default: 0
Meaning: Pre-allocates 1024 huge pages (each 2MB).
Why it matters:
Some games, emulators, and databases benefit from using huge pages because they reduce TLB (Translation Lookaside Buffer) misses — making memory access faster and more predictable.
If you have plenty of RAM, setting this gives a small but measurable boost in performance.
12. vm.transparent_hugepage.enabled = always
Default: madvise
Meaning: Controls automatic use of Transparent Huge Pages (THP).
Why it matters:
Setting it to always forces the kernel to use THP for all eligible memory areas, improving memory throughput in gaming, rendering, or other large-memory workloads.
Note: May slightly increase latency for tiny allocations.
13. vm.transparent_hugepage.defrag = always
Default: defer
Meaning: Controls how aggressively the kernel defragments memory to create huge pages.
Why it matters:
Setting it to always ensures huge pages are created eagerly — ideal for benchmarks or gaming sessions where you want performance now and don’t care about CPU overhead from defragmentation.
14. vm.zone_reclaim_mode = 0
Default: 0
Meaning: Controls how NUMA (Non-Uniform Memory Access) nodes reclaim memory from other zones.
Why it matters:
Leave it 0 unless you’re on a multi-socket server. It prevents unnecessary latency and keeps memory allocation simple and fast on desktop and gaming systems.
Summary: A Formula for “Insane” Linux Memory Performance
| Setting | Purpose | Performance Effect |
|---|---|---|
vm.swappiness=0 |
Avoid swap | Keeps apps in RAM |
vm.vfs_cache_pressure=50 |
Retain FS cache | Faster file access |
vm.dirty_* |
Manage I/O writeback | Smoother performance |
vm.nr_hugepages=1024 |
Preload huge pages | Faster memory access |
vm.transparent_hugepage.* |
Use THP aggressively | Boosts large memory workloads |
vm.max_map_count=262144 |
Raise map limit | Prevents app crashes |
vm.overcommit_memory=1 |
Allow more allocations | Improves flexibility |
Final Thoughts
These tweaks transform your Linux or Ubuntu system into a high-performance machine — trading a bit of safety for speed.
For most power users, gamers, and benchmark enthusiasts, this configuration ensures smoother frame rates, faster app launches, and lower latency.
Just remember: these are not meant for servers or mission-critical machines — they’re for when you want your desktop to run like it’s powered by caffeine and rocket fuel.