Difference between revisions of "Swap"

108 bytes added ,  3 years ago
m
Improved readability
(Professionalised the entire document)
m (Improved readability)
Line 29: Line 29:
The amount of swap you need is highly variable based on ''your'' specific applications and workload.  There is no universal formula on swap size without monitoring usage over a period of time.  A reasonable place to start would be:
The amount of swap you need is highly variable based on ''your'' specific applications and workload.  There is no universal formula on swap size without monitoring usage over a period of time.  A reasonable place to start would be:
* For less then 4GB of physical memory (RAM), it's highly recommended that the swap space should, as a base minimum, be equal to the amount of RAM. Also, it's recommended that the swap space is maximum twice the amount of RAM depending upon the amount of disk space available for the system because of diminishing returns.  
* For less then 4GB of physical memory (RAM), it's highly recommended that the swap space should, as a base minimum, be equal to the amount of RAM. Also, it's recommended that the swap space is maximum twice the amount of RAM depending upon the amount of disk space available for the system because of diminishing returns.  
* For more modern systems (>=4GB), your swap space should be at a minimum be equal to your physical memory (RAM) size '''if you use hibernation''', otherwise you need a minimum of ROUND(SQRT(RAM)) and a maximum of twice the amount of RAM (this maximum again because of diminishing returns). The only downside to having more swap space than you will actually use, is the disk space you will be reserving for it cannot be used for application data.
* For more modern systems (>4GB), your swap space should be at a minimum be equal to your physical memory (RAM) size '''if you use hibernation''', otherwise you need a minimum of ROUNDUP(SQRT(RAM)) I.E. the square root of your RAM size rounded up to the next GB. The maximum, is again twice the amount of RAM, again because of diminishing returns.  
* The only downside to having more swap space than you will actually use, is the disk space you will be reserving for it cannot be used for application or system data.


The "diminishing returns" means that if you need more swap space than twice your RAM size, you'd better add more RAM as Hard Disk Drive (HDD) access is about 10³ slower then RAM access, so something that would take 1 second, suddenly takes more then 15 minutes! And on a Solid State Drive (SSD) the same operation that took 1 second in RAM will still take about 1 minute on an SSD!
The "diminishing returns" means that if you need more swap space than twice your RAM size, you would be better off adding more RAM as Hard Disk Drive (HDD) access is about 10³ slower then RAM access, so something that would take 1 second, suddenly takes more then 15 minutes! And on a Solid State Drive (SSD) the same operation that took 1 second in RAM will still take about 1 minute on that SSD!


Taking into accound all of the above, this brings us to the following table:
Taking into accound all of the above, this brings us to the following table:
Line 58: Line 59:
         4TB            64GB              4160GB      8TB
         4TB            64GB              4160GB      8TB
         8TB            91GB              8283GB    16TB
         8TB            91GB              8283GB    16TB
{{note|The largest server this author has ever installed had, indeed, 8TB of RAM}}
{{note|The largest server one of the authors of this wiki has ever installed had, indeed, 8TB of RAM}}


=Displaying Swap Information=
=Displaying Swap Information=
Line 84: Line 85:
   fi
   fi
  else
  else
  echo "[warning] Not running as root: skipping zswap info"
  echo "[warning] Not running as root: skipping zswap info"
  fi
  fi
  for szFile in /proc/*/status ; do
  for szFile in /proc/*/status ; do
  awk '/VmSwap|Name/{printf $2 "\t" $3}END{ print "" }' "$szFile"
  awk '/VmSwap|Name/{printf $2 "\t" $3}END{ print "" }' "$szFile"
  done | sort --key 2 --numeric --reverse | more
  done | sort --key 2 --numeric --reverse | more


Moderators, translator
286

edits