For working with storage devices we need a file system, what about the swap space?
If it doesn't have a file system how does operating system work with it? How is the data (from RAM) written to disk, and how is it accessed again?
For working with storage devices we need a file system, what about the swap space?
If it doesn't have a file system how does operating system work with it? How is the data (from RAM) written to disk, and how is it accessed again?
Swap technically doesn't have specific filesystem. The whole purpose of filesystem is to structure data in certain way. Swap partition in particular doesn't have structure, but it does have a specific header, which is created by
mkswap
program. In particular , this (taken from kernel.org):Each partition has specific code associated with it, and according to TLDP:
When swap file is involved, that's a slightly different story. The kernel must respect the fact that the filesystem may have their own way of structuring data. From the same kernel.org link:
In conclusion, technically you could call swap space a filesystem of its own type, but it's not quite comparable with filesystems like NTFS or ext4
You've also asked
Strictly speaking, there's no need for RAM to be structured. However, portions of RAM can be structured as tmpfs under Unix-like OSes. There's also ramfs, and initramfs , which is what gets loaded during boot process. But the RAM data technically is supposed to be just raw 1s and 0s, so there's no need to structure them in anyway.
Swap space is used by the kernel to temporarily store pages of system memory (RAM) as it becomes full. The kernel uses it's own internal tables to "remember" exactly where within the swap disk it put the page. As a result, swap disks do not contain a proper filesystem and are usually just blank partitions on the disk.
What you may be interested in, is a RAM-disk, which is a small filesystem stored in the system's memory. If more memory is needed, the kernel will push it (and other contents) out to the swap space. See here for instructions on setting one up.
Swap space is divided into blocks the same size as memory pages (usually 4kB), and a record of the mapping of these pages to application memory forms an extension of the virtual memory subsystem in the CPU and OS.
That is, there is already a mapping system between application memory spaces and the actual physical memory address. An application is given a large memory address space which they can use as much or as little of as they can. As more of this memory address space is actually used, physical memory is mapped to that application to serve as the storage medium.
When memory is swapped to disk, a related system maintains that mapping of an application's memory space to the block on disk.
The mapping table itself is not stored on disk, and the data remaining on the disk is useless after a reboot.