I'm facing some confusion regarding how swap works in Linux and how the operating system handles orphan pages. I have a Red Hat Enterprise Linux virtual machine that's running a memory-intensive batch processing application, which uses over 100GB of RAM but only has 1GB of swap memory and a low swappiness setting of 1. After restarting the machine, the swap usage gradually climbs to 100% even though none of the running processes seem to be using it.
From what I understand, Linux is supposed to swap out pages from RAM when it reaches its limit or when many processes are running to make room for those that are actively in use. However, it seems like my swap pages are potentially 'orphaned' since no processes are requesting them, leading me to wonder how and when these pages will be freed. Is Linux designed to overwrite these pages once swap space is needed, or is it true that my swap is genuinely full? Should I consider adding a cron job to periodically clear the swap?
2 Answers
Hey! It sounds like you're not facing any immediate performance issues, which is good. It’s normal for Linux to manage swap space without needing to be overly aggressive about freeing it up unless there are actual performance impacts. You mentioned the idea of orphan pages—it’s true that if there are no processes using the swap, Linux might not prioritize clearing that space.
If everything's running fine, it's often okay to just let Linux manage it as it sees fit. Adding more swap wouldn’t hurt, especially since you have a heavy application, but turning swap off isn’t necessarily a bad idea either if it's bothering you.
Just keep an eye on performance and usage stats to ensure everything stays smooth!
It's pretty typical these days for Linux systems to maintain some swap space. About your query on managing orphan pages, Linux is tuned to prioritize keeping active and useful data in RAM, mainly for performance reasons. If you find that your swap is constantly full—even with a heavy application—consider increasing your swap space.
One gigabyte for a system with more than 100GB RAM is quite limited and might not align with modern best practices. Running swapoff can flush it, but make sure to assess whether that’s genuinely necessary!
Thanks for the clarity! I guess I need to evaluate whether my swap size is impacting performance or not before making adjustments. Having a better understanding of how Linux handles this gives me more confidence.

Yeah, I get your point about not having active processes using swap. It's logical to expect that the OS should clear old pages to make room for current data. But, in more recent versions of Linux, freeing swap space happens in a more sophisticated way. It won't necessarily overwrite until it absolutely needs space, especially since swap is rarely accessed unless absolutely required. Just monitoring the system should help you understand its behavior better!