Skip to main content
124 votes
Accepted

I can't enable Swap space on CentOS 7

The problem with fallocate(1) is that it uses filesystem ioctls to make the allocation fast and effective, the disadvantage is that it does not physically allocate the space but swapon(2) syscall ...
Rahul's user avatar
  • 13.7k
63 votes
Accepted

What specifically can swap do that RAM can't?

Hibernation (or suspend to disk). Real hibernation powers off the system completely, so contents of RAM are lost, and you have to save the state to some persistent storage. AKA Swap. Unlike Windows ...
muru's user avatar
  • 73.3k
51 votes
Accepted

Docker -- WARNING: No swap limit support

Swap limit support allows you to limit the swap the container uses, see https://docs.docker.com/engine/admin/resource_constraints According to https://docs.docker.com/engine/installation/linux/linux-...
Samizdis's user avatar
  • 658
38 votes

How can I check if swap is active from the command line?

swapon --show This is a bit better than swapon -s as it provides human friendly size units. E.g. if swap is active you could see: NAME TYPE SIZE USED PRIO /dev/dm-1 partition 7.5G 563.8M ...
Ciro Santilli OurBigBook.com's user avatar
36 votes
Accepted

Is the "page-to-disk" feature Linus talks about in his autobiography essentially the concept of swapping we use today?

Yes, this is effectively swapping. Quoting the release notes for 0.12: Virtual memory. In addition to the "mkfs" program, there is now a "mkswap" program on the root disk. The ...
Stephen Kitt's user avatar
34 votes

When is swap file harmful?

Swap can be bad in that it may make some failure cases last longer. Consider a situation where some process starts using excessive amounts of memory, due to a bug or a misconfiguration or other such ...
ilkkachu's user avatar
  • 141k
31 votes

How can swapoff be that slow?

Yup, the swapoff mechanism is horrendously inefficient. The workaround is easy: iterate over processes, instead iterating over the swapped pages. Use this python script (I am not affiliated): git ...
kubanczyk's user avatar
  • 1,258
30 votes

Is the "page-to-disk" feature Linus talks about in his autobiography essentially the concept of swapping we use today?

Yes, that's exactly the concept known as paging or swapping. (A long time ago these terms had slightly different meanings, but in the 21st century, they're synonymous except perhaps in the context of ...
Gilles 'SO- stop being evil''s user avatar
29 votes

How do I use swap space for emergencies only?

One fix is to make sure the memory cgroup controller is enabled (I think it is by default in even half-recent kernels, otherwise you'll need to add cgroup_enable=memory to the kernel command line). ...
derobert's user avatar
  • 110k
26 votes
Accepted

Arch Linux thinks I have about 16 gigs of ram when I only have 8

What this is telling you is that you have 16GB of virtual memory. Virtual memory is the total of physical RAM and swap space added up. It's a way of letting your system run more programs than it ...
Stephen Harris's user avatar
24 votes
Accepted

How does Linux know where its swap partition is?

Statically configured swap space (the type that pretty much every distribution uses) is configured in /etc/fstab just like filesystems are. A typical entry looks something like: UUID=21618415-7989-...
Austin Hemmelgarn's user avatar
23 votes

I can't enable Swap space on CentOS 7

Follow these steps, it works on DigitalOcean's droplets. I tested. Change the amount 4096 according to your need yum install nano -y sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB sudo chmod ...
Dylan B's user avatar
  • 331
22 votes

Why use swap when there is more than enough free space in RAM?

This is an old post, however, I would still take the liberty of putting up my thoughts here. Starting from down under, Linux would first divide the memory into pages (usually 4K per page on x86_64 ...
Anugraha Sinha's user avatar
21 votes

How does Linux know where its swap partition is?

let's say Fedora and Ubuntu? … both of which are nowadays systemd operating systems. What happens in systemd operating systems the native mechanism Systemd employs various kinds of units. ....
JdeBP's user avatar
  • 69.3k
21 votes
Accepted

Out of memory, but swap available

In /proc/meminfo you find: CommitLimit: 1551056920 kB Committed_AS: 1549560424 kB So you are at the commit limit. If you have disabled overcommiting of memory (to avoid the OOM-killer) by: echo ...
Ole Tange's user avatar
  • 35.7k
20 votes
Accepted

How do I use swap space for emergencies only?

Having such a huge swap nowadays is often a bad idea. By the time the OS swapped just a few GB of memory to swap, your system had already crawled to death (like what you saw) It's better to use zram ...
phuclv's user avatar
  • 2,095
19 votes
Accepted

What 'sw' means in the fstab swap entry for 'mount options' column

From the fstab manual on my system: The fourth field, fs_mntops, describes the mount options associated with the filesystem. It is formatted as a comma separated list of options. It contains at ...
Kusalananda's user avatar
  • 338k
18 votes
Accepted

Does Linux perform "opportunistic swapping", or is it a myth?

Linux does not do "opportunistic swapping" as defined in this question. The following primary references do not mention the concept at all: Understanding the Linux Virtual Memory Manager. An ...
sourcejedi's user avatar
18 votes

When is swap file harmful?

Technically, a swap partition is more efficient than a swap file. Practically, if the swap file is contiguous, there should not be a lot of difference, and current versions of linux, no performance ...
user10489's user avatar
  • 7,132
17 votes
Accepted

What are the holes in files created with fallocate?

Holes in a file don’t have any block associated with them at all. A file created with fallocate can end up with no blocks associated with it, only a size. Reads from unallocated blocks always return ...
Stephen Kitt's user avatar
17 votes
Accepted

Why swap space doesn't get filesystem check at boot time?

At boot time, swap doesn’t contain any data which would need to be recovered, so there’s no point in writing a tool to repair swap. If a swap partition or file is corrupted in such a way that swapon ...
Stephen Kitt's user avatar
17 votes

What specifically can swap do that RAM can't?

What can be done with swap which would not also be done by adding RAM? This question could actually be reworded into What can be done with non-volatile RAM which would not also be done by adding more ...
NetIceCat's user avatar
  • 2,314
16 votes

fstab entry for swap file

There is no UUID for a file. Simply enter it as: /swapfile none swap defaults 0 0 Since it's directly on the root filesystem, there's no worry about the mounting order.
Julie Pelletier's user avatar
16 votes

What 'sw' means in the fstab swap entry for 'mount options' column

For Linux, at least, based on a look at the net, this appears to be an example of "cargo culting", which means including code or words in this case for ritualistic or superstitions reasons, ...
Faheem Mitha's user avatar
  • 35.3k
16 votes
Accepted

What is swap priority and why does it matter

man 2 swapon describes priorities thus: Each swap area has a priority, either high or low. The default priority is low. Within the low-priority areas, newer areas are even lower priority than older ...
Stephen Kitt's user avatar
15 votes
Accepted

How can I zerofill the /swapfile without wiping out what makes it a swapfile?

This won’t clear the swap file as thoroughly as re-creating it, but if you clear it after skipping the first 4KiB (strictly speaking, the first page, which depends on your architecture), you won’t ...
Stephen Kitt's user avatar
15 votes

How do I use swap space for emergencies only?

It seems that after a day of inactivity the kernel believes the entire GUI is no longer needed and wipes it from RAM (swaps it to disk). The kernel is doing The Right Thing™ believing it. Why would ...
jlliagre's user avatar
  • 61.5k
15 votes

What specifically can swap do that RAM can't?

For a given total, it's always better to have it as RAM than swap. There is a difference in behaviour between a noswap system and a swapping system, which may or may not be useful: thrashing. As the ...
pjc50's user avatar
  • 3,034

Only top scored, non community-wiki answers of a minimum length are eligible