Hot answers tagged swap
48
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 ...
47
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 ...
24
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 ...
22
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 ...
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:
...
15
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: ...
14
in linux, you can use
cat /proc/meminfoto 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 ...
12
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 ...
12
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, ...
11
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 ...
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
You can configure swappiness per cgroup:
http://www.kernel.org/doc/Documentation/cgroups/cgroups.txt
http://www.kernel.org/doc/Documentation/cgroups/memory.txt
9
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 ...
7
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
7
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 ...
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
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 ...
6
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 ...
6
From this Ask Ubuntu question:
You can also clear your swap by running swapoff -a and then swapon -a as root instead of rebooting to achieve the same effect.
Thus:
$ free -tm
...
Swap: 6439 196 6243
...
$ sudo swapoff -a
$ sudo swapon -a
$ free -tm
...
Swap: 6439 0 6439
...
As noted in a comment, if you ...
6
Try this:
Create a partition or RAID array or logical volume... (or use an existing one) for swap
mkswap that partition
Run blkid that-block-device
Add an entry to /etc/fstab in the form UUID=7321174b-e4d8-4d9d-b223-113a1b8e9c9f swap swap sw 0 0 (see step 3 for actual UUID)
swapon -a or reboot
5
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 ...
5
From Ubuntu Swap F.A.Q. that Marcel linked to
As a base minimum, it is highly recommended that the swap space should be equal to the amount of physical memory (RAM). Also, it is recommended that the swap space is twice the amount of physical memory (RAM) depending upon the amount of hard disk
I think you should increase your swap space in your system. ...
5
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 ...
5
You can dynamically add or remove swap spaces with swapon and swapoff. If you remove to much memory, running processes could be killed. You can also give priorities between the swap spaces using the -p option.
To format a new partition/lvm volume as swap, use mkswap.
5
You are likely running a 32 bit kernel. You can just create 2 x 1 GB swap files and add them separately.
# rm /swap.file
# /usr/sbin/mkfile 1024m /swap1
# /usr/sbin/mkfile 1024m /swap2
# /usr/sbin/swap -a /swap1
# /usr/sbin/swap -a /swap2
Also, for this setting to survive a reboot, you'll also need to add lines to the /etc/vfstab file, eg:
/swap1 - - ...
5
Your mysqld is configured to use 1,8 GB of RAM - propably due to your settings in /etc/my.cnf. This is much more than is physically available.
Now in some point of time (you might install sysstat and ask sar about that) you seem to get memory requests (might be PHP, too) that use more RAM than is available - so the systems starts to swap.
At the end of ...
5
Indeed, the page describes setting up a partition, but it's similar for a swapfile:
dd if=/dev/urandom of=swapfile.crypt bs=1M count=64
loop=$(losetup -f)
losetup ${loop} swapfile.crypt
cryptsetup open --type plain --key-file /dev/urandom ${loop} swapfile
mkswap /dev/mapper/swapfile
swapon /dev/mapper/swapfile
The result:
# swapon -s
Filename ...
4
Purchase more memory? :)
If you are running applications that are using more memory than you have present in the
system, there's nothing that any operating system can do about this other then to
swap to the swap partition. If this is a situation you find yourself in often, stop
running some of the programs that you do not need, or, really, buy more ...
4
Having more available memory
Like everyone said, yes swap will help you get rid of unused memory, so it can help you having more memory available.
Hibernating
But swap can also be used for hibernating which can be really useful when you have a laptop or want to save energy and put your computer and work in hibernation before leaving work. So you can have ...
4
As far as I understand your question it happens usually in such way:
If you allocate memory:
Mark memory as allocated but don't allocate physical memory (hence on access there will be page fault). In Linux it stops at this stage but it is possible that system may allocate physical space immediately - then it performs similar algorithm at the end as on ...
Only top voted, non community-wiki answers of a minimum length are eligible