Tag Info

Hot answers tagged

59

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 ...


56

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 ...


54

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 ...


26

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 ...


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 ...


23

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 ...


21

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 ...


21

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. ...


20

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: ...


17

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 ...


16

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: ...


16

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 ...


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 ...


15

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, ...


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

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


12

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 ...


12

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 ...


11

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 ...


10

Some pointers: Don't run so many GUI programs at once. Make sure that any programs running in the background that you don't need e.g. Apache are stopped. Use a distro aimed at low-memory situations (e.g. for a netbook) Buy more memory. Buy a faster HD (or SSD) for your swap partition. :)


10

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


10

That depends on the implementation of hibernation. Even if you restrict the question to Linux, the implementation has evolved over time. First, consider that some of the RAM is used for disk caches. This doesn't need to be moved to the swap as it can be reloaded from the disk after the system resumes. On a system with a good cost/efficiency balance, it's ...


8

Disabling swap won't do what you want. You will still get violent I/O throughput, but it will be of clean pages rather than dirty ones. With no swap, the system will compress the cache of clean (unmodified) pages to near zero, because those are the only pages it can evict from physical memory. It can only evict dirty (modified) pages from memory by writing ...


8

Either you have a long memory or you've been reading obsolete documents. There used to be a 2GB swap size limit (on most 32-bit platforms), but this has not been the case for years. The limitation was removed at some point in the 2.2 kernel series. The maximum useful size of a swap area depends on the architecture and the kernel version. It is roughly ...


8

You can use sar -B 1 to get a realtime view of this information (change 1 to the update interval you want). The output looks like this: 08:11:54 PM pgpgin/s pgpgout/s fault/s majflt/s pgfree/s pgscank/s pgscand/s pgsteal/s %vmeff 08:11:55 PM 0.00 0.00 24.00 0.00 57.00 0.00 0.00 0.00 0.00 08:11:56 PM ...


7

Zram creates a block device backed by compressed ram. You can use that block device for swap. Normally memory pressure first results in the cache being discarded, and only after most of the cache has been freed up and memory is still tight does the system start swapping. CleanCache allows pages from the page cache to be migrated to a back end, such as xen ...


7

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 ...


7

Firstly, using a slow or defective hard drive for swap is not a good idea. It's like having really slow or buggy memory in a way. How your system spreads data across your swap partitions depends on the priority you give them in your /etc/fstab As an example, /dev/hda5 none swap sw,pri=2 0 0 /dev/hdb5 none swap sw,pri=1 0 0 /dev/hdc6 none swap sw,pri=3 0 0 ...


7

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 ...


6

A very "untechnical" explanation: Swap area is hard drive space that is reserved to act as extra RAM for when your computer needs more RAM than what is available. Note that when this happens your computer might slow down noticably. The Ubuntu help website recommends that you have double the ammount of RAM as SWAP. So if you have 1GB of RAM, you should have ...



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