What file system is swap on Linux
Solution 1
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.
Solution 2
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.
Solution 3
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.
Related videos on Youtube
Elaheh
Updated on September 17, 2022Comments
-
Elaheh over 1 year
My question is about linking the files in g++ compiler.
I have a
.cpp
file namedA.cpp
containing a parent class and its children, each class uses an instance of another class defined inB.cpp
, and in the class defined inB.cpp
, we use an instance of all the classes defined in A!How should I link these files? Is this a very poor programming style? I have tried including
A.cpp
in oneB.cpp
andB.cpp
inA.cpp
but it is incorrect.-
Varvarigos Emmanouil almost 11 yearsYou can include them using #ifndef #define #endif in header files to prevent the collision.
-
-
user3660103 almost 14 yearsThe 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/…
-
tony_sid almost 14 yearsI know what swap is.
-
matthias krull almost 14 yearsit is not the virtual ram place exactly. it is (like ram) memory that can be mapped to the virtual memory of a process.
-
tony_sid almost 14 yearsDoesn't there have to be some kind of file system in order to read and write anything meaningful to a partition?
-
matthias krull almost 14 yearsNo. 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 almost 14 yearsYou can still address blocks if you do not have a filesystem.
-
mirabilos over 9 years“Today however this argument doesn't really hold. With evolution of how fast disk access is these days, device swap does not buy you much more time than filesystem swap.” – this is not the reason. The idea here is that swap space may be in immediate demand. Going through a file system involves directories, blocks, inodes, the buffer cache, etc. which are codepaths that themselves can need more memory, leading to a loop. That’s why swap is best done on a raw block device. It also avoids swapfile fragmentation.
-
MrCalvin about 6 years...didn't know about the swap-file option
-
Samuel Li over 4 yearsThis answer may touch on a few interesting points, but it doesn't answer the question...