Questions tagged [swap]

Linux divides its physical RAM (random access memory) into chucks of memory called pages. Swapping is the process whereby a page of memory is copied to the preconfigured space on the hard disk, called swap space, to free up that page of memory. The combined sizes of the physical memory(RAM) and the swap space is the amount of virtual memory available. Linux has two forms of swap space: the swap partition and the swap file.

From linux.com All about swap space:

Linux divides its physical RAM (random access memory) into chucks of memory called pages. Swapping is the process whereby a page of memory is copied to the preconfigured space on the hard disk, called swap space, to free up that page of memory. The combined sizes of the physical memory and the swap space is the amount of virtual memory available.

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. However, swapping does have a downside. Compared to memory, disks are very slow.

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.

Swap space size should be either similar to system RAM or double it's size.

340 questions
17
votes
8 answers

kswapd often uses 100% CPU when swap is in use

Most of the time when my computer starts to need swap, I see a massive spike in CPU usage (kswapd0 is consistently using 99%-100% CPU). According to top, the time is spent in sy (system/kernel) not wa (IO wait). I am running Linux 4.0.4-2-ARCH on a…
Zaz
  • 783
  • 1
  • 6
  • 17
17
votes
5 answers

How do I change swap partition in Linux?

How do I change swap partition in Linux? If I currently use /dev/hda3 for swap, and I rather would like to use /dev/hda4, which steps should I go through?
Martin Bøgelund
  • 388
  • 1
  • 5
  • 12
15
votes
2 answers

Avoiding swap on ElastiCache Redis

We have been having ongoing trouble with our ElastiCache Redis instance swapping. Amazon seems to have some crude internal monitoring in place which notices swap usage spikes and simply restarts the ElastiCache instance (thereby losing all our…
Josh Kupershmidt
  • 826
  • 1
  • 9
  • 9
14
votes
2 answers

Ubuntu Server hanging on adding swap

A fresh install of Ubuntu Server is refusing to boot and hanging on "Adding 524284k swap on /dev/mapper/test--vg-swap_1. Priority:-1 extents:1 across:524284k I can get around this by dropping onto recovery mode and just resuming to a normal boot.
Guest1857238673896
  • 141
  • 1
  • 1
  • 3
14
votes
1 answer

How do I enable swap file on my server?

I've followed this but when I run:- #swapon /swapfile1 I get::- swapon: /swapfile1: swapon failed: Operation not permitted The system is extremely slow with 1GB of RAM trying to run GUI + applications + FreeNX server. Any help is highly…
wajed
  • 177
  • 1
  • 1
  • 5
14
votes
3 answers

Ubuntu Linux: Process swap memory and memory usage

My Ubuntu eats more memory than the task manager is showing: sudo ps -e --format rss | awk 'BEGIN{c=0} {c+=$1} END{print c/1024}' 2750.29 free -m total used free shared buffers cached Mem: 3860 …
David Halter
  • 271
  • 1
  • 2
  • 8
14
votes
2 answers

How to free swap without rebooting (to avoid hourly alert emails)?

I get alert emails whenever swap usage is at 100%. In my case, swap usage doesn't reduce later on (even though memory is free) so I get an alert email every hour. How can I reduce swap usage without rebooting my Linux server?
Christian Siegert
  • 241
  • 1
  • 2
  • 3
14
votes
7 answers

How to create a randomly keyed, encrypted swap partition, referring to it "by-uuid", on Debian?

It is sensible that if you have any sort of block device encryption implemented on your GNU/Linux system, to encrypt your swap partition too, as any decrypted data may be written in cleartext at any time to the swap. Looking at the debian man page…
Geeb
  • 241
  • 1
  • 2
  • 5
14
votes
1 answer

Linux goes to swap while plenty of RAM installed

I have a linux box that is used as SAN storage. It is equipped with 14 SATA HDDs and the only software it run is iscsi target and zabbix agent. This is physical box, not VM. The RAM size installed is 128 GB, swap was arranged of 4 GB and no-one ever…
Kevin M
  • 299
  • 3
  • 10
13
votes
4 answers

Linux: Where to put the swap file

Are there any conventions on where to put swap files on Linux? I usually just create them in /var/swapfile, but that seems a bit too high up in the hierarchy.
Jo Liss
  • 2,818
  • 1
  • 22
  • 23
13
votes
11 answers

How big should the swap partition be?

for some years, I've read that it's a good idea to create a swap partition having the double space of my RAM. does it still apply today? or this isn't needed anymore? I have a server with 8 GiB of RAM and I need to create a swap partition, and I was…
cd1
  • 1,434
  • 4
  • 12
  • 17
12
votes
3 answers

Swap being used when RAM is almost half free

Today I noticed that I found the following thing: As you can see the RAM is almost half-free and the usage of swap space is very high. From my textbook knowledge, I used to think that Linux OS tries to make best usage of RAM and when it gets short…
pradeepchhetri
  • 2,518
  • 6
  • 33
  • 45
12
votes
2 answers

How to find what is using linux swap or what is in the swap?

I have virtual linux (Fedora 17) server with 28GB RAM and 2GB swap. The server is running a MySQL DB that is set up to use most of the RAM. After some time running the server starts to use swap to swap out unsued pages. That is fine as my swappiness…
Radek Hladík
  • 600
  • 1
  • 3
  • 14
12
votes
11 answers

Linux server is only using 60% of memory, then swapping

I've got a Linux server that's running our bacula backup system. The machine is grinding like mad because it's going heavy in to swap. The problem is, it's only using 60% of its physical memory! Here's the output from free -m: free -m …
Kamil Kisiel
  • 11,946
  • 7
  • 46
  • 68
11
votes
3 answers

Background discard on swap partitions on Linux + SSD

Problem I want to enable background TRIM operations on a swap partition within a SSD disk on Linux. According to several articles, e.g. this one, the kernel detects this configuration and automatically performs discard operations, but on my tests…
santisaez
  • 201
  • 1
  • 3
  • 10
1
2
3
22 23