Great questions! Let's break down the concept of swap, swap paging, and related technologies like zram, and discuss what works best depending on where you put your swap space.
What is Swap and Paging?
- Swap is a space on a storage device (usually a hard drive (HDD) or solid-state drive (SSD)) used as an overflow area when your system's RAM is fully utilized. Instead of running out of memory, the OS moves (pages out) some data from RAM to swap space to free up RAM for active processes.
- Paging is the process of moving data between RAM and swap. When data is needed but currently swapped out, it is paged back into RAM.
Swap on HDD vs SSD
-
Swap on HDD:
- HDDs are mechanical drives, and random I/O (input/output) is relatively slow due to moving parts.
- Using swap on HDD results in slower performance when swapping occurs (because reading/writing swap is slower).
- Swap on HDD can cause noticeable system slowdowns if RAM runs out and paging happens frequently.
-
Swap on SSD:
- SSDs have much faster random read/write speeds than HDDs.
- Swap on SSD is significantly faster than swap on HDD, leading to better overall system responsiveness.
- However, excessive swap can wear down SSDs over time (but modern SSDs have high endurance, and for typical consumer use swapping won’t likely hurt them noticeably).
Conclusion: Swap on SSD is better than HDD swap space from a speed perspective.
What if I Add Another RAM Stick and Put Swap on That?
- Simply adding another RAM stick does not create swap space on that RAM.
- Swap is disk-based (non-volatile) storage, whereas RAM is volatile memory.
- You can't have swap "on RAM" in the traditional sense because RAM is meant for active data, fast access, and is volatile (loses data when turned off).
- However, there are software technologies that create compressed swap-like space inside RAM, which brings us to zram.
What is zram?
- zram is a Linux kernel module that creates a compressed block device (a form of virtual swap) in memory itself.
- Instead of paging out to slow disk, the system compresses infrequently used memory pages and stores them in this compressed RAM area.
- Benefits of zram:
- Speeds up swap performance because you avoid disk I/O latency.
- Compresses data to get effectively more memory.
- Helps in systems with limited RAM and systems without fast storage.
- Downsides:
- Uses some CPU cycles for compression/decompression.
- Limited by the amount of RAM you have because it uses RAM as backing storage.
zram acts like a swap device in RAM, but unlike regular RAM, it stores compressed pages that are not actively used, allowing more effective memory utilization.
Summary / Recommendations:
| Option | Speed | Longevity Impact | Use case / Notes |
|---|
| Swap on HDD | Slow | None | Older systems, not recommended if SSD available |
| Swap on SSD | Fast | Some wear but minimal in practice | Recommended if you need swap |
| Adding more RAM | N/A | Best option | Reduces or eliminates swapping need |
| Using zram (compressed RAM swap) | Very fast (no disk) | Uses more CPU but no disk wear | Great for low-RAM systems or where swap is needed but slow disks |
Additional Notes:
- If you have enough RAM, try to avoid swapping entirely.
- Use SSD swap if you expect swapping but don't want a large RAM upgrade.
- Combine zram + SSD swap as a good strategy: zram handles quick compressible swaps, and SSD swap serves as a fallback for bigger dumps.
- Adding RAM is almost always preferable as it avoids swapping altogether.
If you want, I can help you configure zram or optimize swap on your system!