Tag Info

Hot answers tagged

71

This behaviour can be configured by setting the value of /proc/sys/vm/swappiness. The default value is 60, setting it to 0 means “never use swap when there is still RAM left“ and 100 is swapping out memory as soon as possible. To change the value temporarily (lost on reboot): sudo sysctl vm.swappiness=10 To change the value permanently: Edit the file ...


65

Yes. You should most definitively always have swap enabled, except if there is a very compelling, forbidding reason (like, no disk at all, or only network disk present). The reason is that swap is not only useful when your applications consume more memory than there is physical RAM (actually, in that case, swap is not very useful at all because it ...


64

It is normal for Linux systems to use some swap even if there is still RAM free. The Linux kernel will move to swap memory pages that are very seldom used (e.g., the getty instances when you only use X11, and some other inactive daemon). Swap space usage becomes an issue only when there is not enough RAM available, and the kernel is forced to continuously ...


64

If you worry about write cycles, you won't get anywhere. You will have data on your SSD that changes frequently; your home, your configs, your browser caches, maybe even databases (if you use any). They all should be on SSD: why else would you have one, if not to gain speed for the things you do frequently? The number of writes may be limited, but a modern ...


50

Since kernel 2.6.28, Linux uses a Split Least Recently Used (LRU) page replacement strategy. Pages with a filesystem source, such as program text or shared libraries belong to the file cache. Pages without filesystem backing are called anonymous pages, and consist of runtime data such as the stack space reserved for applications etc. Typically pages ...


49

I'm going to disagree with a few of the opinions that I see stated here. I'd still be creating a SWAP partition especially in a production environment. I do it for my home machines and VMs as well. These days I'm sizing them around 1-1.5 times memory. 2 times memory used to be the rule of thumb. The swap disk is "cheap" in that it does not need to be ...


43

in linux, you can use cat /proc/meminfo to see total swap, and free swap (all linux) cat /proc/swaps to see which swap devices are being used (all linux) swapon -s to see swap devices and sizes (where swapon is installed) vmstat for current virtual memory statistics in Mac OS X, you can use vm_stat to see information about virtual memory (swap) ls ...


34

Linux starts swapping before the RAM is filled up. This is done to improve performance and responsiveness: Performance is increased because sometimes RAM is better used for disk cache than to store program memory. So it's better to swap out a program that's been inactive for a while, and instead keep often-used files in cache. Responsiveness is improved by ...


29

What might be happening if a process is "killed due to low RAM"? It's sometimes said that linux by default never denies requests for more memory from application code -- e.g. malloc().1 This is not in fact true; the default uses a heuristic whereby Obvious overcommits of address space are refused. Used for a typical system. It ...


26

First, let's look at what you can expect from your hard drive. Your hard drive can do 200 MB/s sequentially. When you factor seek times in, it can be much slower. To pick an arbitrary example, take a look at the specs for one of Seagate's modern 3TB disks, the ST3000DM001: Max sustained data rate: 210 MB/s Seek average read: <8.5 ms Bytes per sector: ...


23

A swap file is more flexible but also more fallible than a swap partition. A filesystem error could damage the swap file. A swap file can be a pain for the administrator, since the file can't be moved or deleted. A swap file is also slightly slower. The advantage of a swap file is not having to decide the size in advance. However, under Linux, you still ...


22

It's possible. In fact, you can share the swap space between completely different operating systems, as long as you initialize the swap space when you boot. It used to be relatively common to share swap space between Linux and Windows, back when it represented a significant portion of your hard disk. Two restrictions come to mind: The OSes cannot be ...


22

A swap partition is preferred because it avoids the overhead of the file system when all you need is an addressable pool. But nothing prevents you from using a swap file instead of a swap partition, or in addition to a swap partition. Create the file: dd if=/dev/zero of=/extraswap bs=1M count=512 Initialize file contents's: mkswap /extraswap Use it: ...


22

Ok, so the goal is to get as much bang for the buck as possible - Speed vs. the price of replacement hardware (assuming a single large harddisk and medium-size SSD, which seems to be the norm). To simplify you can to weigh how much you notice the speed increase from moving a file to the SSD against the number of sectors written to move that file to the SSD. ...


21

There are oh so many reasons to have multiple swap areas (they don't need to be files), even if you only have a single spindle. 20-20 hindsight: You deployed a machine with a single swap area, then eventually realised it's not enough. You can't redeploy the machine at will, but you can make another swap area (probably a file) until redoing the partition ...


18

Is this linux? If so you could try the following: # sysctl vm.swappiness=100 And then either use a program(s) that uses lots of RAM or write a small application that just eats up ram. The following will do that (source: http://www.linuxatemyram.com/play.html): #include <stdlib.h> #include <stdio.h> #include <string.h> int main(int ...


18

Don't confuse swap (as a disk area) and swap (as a method to move memory pages from RAM to disk and reciprocally). Excessive swapping is something to be avoided for performance reasons but having a swap area isn't necessarily a problem. On systems, like Linux, that overcommit memory, i.e. that allow processes to allocate more memory than available, ...


17

You can configure swappiness per cgroup: http://www.kernel.org/doc/Documentation/cgroups/cgroups.txt http://www.kernel.org/doc/Documentation/cgroups/memory.txt For an easier introduction to cgroups, with examples, see https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/ch01.html


17

Maybe: I've given a lot of thought to this topic and seen opinions landing on both sides of the argument more times than I can count. My approach was to develop a way to find out. Start with an active swap partition of what you think is a sufficient size. Then, open a terminal in a workspace and issue the command free -hs 1 which will report usage once ...


16

Is this not how to set up a swap file? I think you missed a step in between chmod and swapon: mkswap /mnt/sda2/swapfile As for the oxymoromic error... swapon: /mnt/sda2/swapfile: read swap header failed: Success What this literally means is there's a bug in the swapon code, but not necessarily one related to its primary functioning. C library ...


14

This won't happen to you if you only ever load 1G of data into memory. What if you load much much more? For example, I often work with huge files containing millions of probabilities which need to be loaded into R. This takes about 16GB of RAM. Running the above process on my laptop will cause it to start swapping like crazy as soon as my 8GB of RAM have ...


13

One side effect I can think of is: Hibernate system1 (using the swap partition for hibernation). Boot system2. You could lose data.


13

I think you were hit by the limitations of OpenVZ. OpenVZ does not allow what they call "user defined swap": Swap is only available "as a whole" for the whole system, not for individual VPSes, see http://forums.vpslink.com/linux/621-swap-space.html#post3915


13

A swap partition has significant value above and beyond simply acting as some extra RAM when you run out. For one, Linux uses as much memory as possible to cache files and IO operations, if you have some swap you may find that more memory goes into caching IO and making it faster (by minimizing disk access and also lowering wear on SSDs) as opposed to ...


12

I suggest reading SwapFAQ , in particular the swapiness parameter.


12

If you really have enough RAM available again you can use this sequence (as root): $ swapoff -a $ swapon -a (to force the explicit swap-in of all your applications) (assuming that you are using linux)


12

A better solution than turning off swap, which will at best cause random processes to be killed when memory runs low, is to set the per process data segment limit for processes that pull stuff off the net. This way a runaway browser will hit the limit and die, rather than cause the whole system to become unusable. Example, from the shell (ulimit -d ...


12

Since kernel version 2.6.28, Linux uses a Split Least Recently Used (LRU) page replacement strategy. Pages with a filesystem source, such as program text or shared libraries belong to the file cache. Pages without filesystem backing are called anonymous pages, and consist of runtime data such as the stack space reserved for applications etc. Typically pages ...


12

Everything is well explained in the Wikipedia page you gave. # Set the swappiness value as root echo 10 > /proc/sys/vm/swappiness # Alternatively, run this as a non-root user # This does the same as the previous command sudo sysctl -w vm.swappiness=10 # Verify the change cat /proc/sys/vm/swappiness 10 At this point, the system will manage the swap ...


11

It might help to up /proc/sys/vm/page-cluster (default: 3). From the kernel documentation (sysctl/vm.txt): page-cluster page-cluster controls the number of pages up to which consecutive pages are read in from swap in a single attempt. This is the swap counterpart to page cache readahead. The mentioned consecutivity is not in terms of ...



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