I'm wondering what actually happens to a Linux-swap partition reboot. I've been taking a course in computer organization and while installing/partitioning a new drive I became rather curious about this.As I understand it, Linux-swap partitions are more-or-less unallocated space within a partitioning scheme on a hard-drive that acts as a stack of memory in similar fasion to ram but had a larger databus waiting time (since it is a HDD/SSD managed in part by the drive itself rather than true ram managed directly by the CPU). Is this model correct?Is information persistent until a Linux-swap tool cleans it, unlike RAM which is erased by a lapse in power?Can you address it directly? Or in C/C++ by the assistance of the kernel (so as to not mess stuff up)?
Linux-swap on reboot
partition;memory;swap
Your course probably covered the differences between L1/L2 cache and registers; with a hierarchy of registers, L1, L2, L3, RAM. Similarly, as you note, you can consider the swap as unallocated space that RAM is swapped out to.Swap may be persistent, depending on the system configuration. Some Linux distributions deliberately erase/zero swap on boot or shutdown for security or performance reasons. If you run swap on SSD, it may be benefical to issue TRIM/DISCARD on a block of swap space when the contents are copied back to RAM. There is no specific tool to clean swap, other than letting the kernel reuse the space (if it's unallocated, and only writes to it, it doesn't care what was there before). Another common paradigm is to encrypt swap with a new key on each boot, and then just discard the key at shutdown.You cannot access the contents of swap directly from the kernel. You could bypass the normal memory process and try to read it as disk, but you normally have no knowledge of where or even if any part of your process is in swap.