Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Linux you can choose things like ext3 and reiserfs for partitions. For the swap partition, you just choose "swap." What file system is this, actually? Can you just create an ext3 partition and make it a swap partition? How would that be different?

share|improve this question
Swap filesystem on Linux appears to be called Linux Swap filesystem. If I manage to find some real information about it, I'll post an answer. So far, I've read from en.wikipedia.org/wiki/Paging that kernel bypasses filesystem on swap files. Same may be true with swap partitions. – AndrejaKo Aug 6 '10 at 10:50

4 Answers

Swap is no actual file system. It is just a reserved part of the disk that is raw addressable memory with no special structure.

mkswap creates a header for the swap area with some additional information. From swapheader.h of the util-linux-ng package:

struct swap_header_v1 {
    char         bootbits[1024];    /* Space for disklabel etc. */
    unsigned int version;
    unsigned int last_page;
    unsigned int nr_badpages;
    unsigned int padding[125];
    unsigned int badpages[1];
};

Header version 1 is the currently used one. Thats about all the magic behind the raw structure of swap.

share|improve this answer
Doesn't there have to be some kind of file system in order to read and write anything meaningful to a partition? – OSX NINJA Aug 6 '10 at 13:46
2  
No. You just have to address chunks of memory. That is exactly what pages are. Thats because you do not store the data with a complex structure or additional information like in real filesystems where permissions and dates are stored alongside with the data. – matthias krull Aug 6 '10 at 13:53
3  
You can still address blocks if you do not have a filesystem. – matthias krull Aug 6 '10 at 13:53

The incredible people at Gentoo forums provided me with this link! Everything seems to be nicely explained. Oh and thanks to John R. Graham.

share|improve this answer
2  
+1 for that link. – matthias krull Aug 6 '10 at 12:58

I think that the swap partition doesn't need a filesystem because there are no files and directories in it. Swap partition is the virtual RAM place.

share|improve this answer
1  
it is not the virtual ram place exactly. it is (like ram) memory that can be mapped to the virtual memory of a process. – matthias krull Aug 6 '10 at 12:19

Linux has two forms of swap space: the swap partition and the swap file. The swap partition is an independent section of the hard disk used solely for swapping; no other files can reside there. The swap file is a special file in the filesystem that resides amongst your system and data files.

Swapping is necessary for two important reasons. First, when the system requires more memory than is physically available, the kernel swaps out less used pages and gives memory to the current application (process) that needs the memory immediately. Second, a significant number of the pages used by an application during its startup phase may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other applications or even for the disk cache.

share|improve this answer
The answer is really nice and explains the core of the problem, but it's an answer to question "What is swap on GNU/Linux?" So what is it doing here? Also, link related linux.com/news/software/applications/… – AndrejaKo Aug 6 '10 at 10:40
I know what swap is. – OSX NINJA Aug 6 '10 at 11:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.