Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Memory paging
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===={{Anchor|LINUX}}Linux==== {{See also|zswap|zram}} The Linux kernel supports a virtually unlimited number of swap backends (devices or files), and also supports assignment of backend priorities. When the kernel swaps pages out of physical memory, it uses the highest-priority backend with available free space. If multiple swap backends are assigned the same priority, they are used in a [[Round-robin scheduling|round-robin]] fashion (which is somewhat similar to [[RAID 0]] storage layouts), providing improved performance as long as the underlying devices can be efficiently accessed in parallel.<ref>{{cite web |url = http://linux.die.net/man/2/swapon |title = swapon(2) – Linux man page |access-date = 2014-09-08 |website = Linux.Die.net |url-status = live |archive-url = https://web.archive.org/web/20140228161303/http://linux.die.net/man/2/swapon |archive-date = 2014-02-28 }}</ref> =====Swap files and partitions===== From the end-user perspective, swap files in versions 2.6.x and later of the Linux kernel are virtually as fast as swap partitions; the limitation is that swap files should be contiguously allocated on their underlying file systems. To increase performance of swap files, the kernel keeps a map of where they are placed on underlying devices and accesses them directly, thus bypassing the cache and avoiding filesystem overhead.<ref>{{cite web |url=https://lkml.org/lkml/2006/5/29/3 |title="Jesper Juhl": Re: How to send a break? - dump from frozen 64bit linux |publisher=LKML |date=2006-05-29 |access-date=2010-10-28 |url-status=live |archive-url=https://web.archive.org/web/20101124235412/http://lkml.org/lkml/2006/5/29/3 |archive-date=2010-11-24 }}</ref><ref>{{cite web |url=https://lkml.org/lkml/2005/7/7/326 |title=Andrew Morton: Re: Swap partition vs swap file |publisher=LKML |access-date=2010-10-28 |url-status=live |archive-url=https://web.archive.org/web/20101124235448/http://lkml.org/lkml/2005/7/7/326 |archive-date=2010-11-24 }}</ref> When residing on HDDs, which are rotational magnetic media devices, one benefit of using swap partitions is the ability to place them on contiguous HDD areas that provide higher data throughput or faster seek time. However, the administrative flexibility of swap files can outweigh certain advantages of swap partitions. For example, a swap file can be placed on any mounted file system, can be set to any desired size, and can be added or changed as needed. Swap partitions are not as flexible; they cannot be enlarged without using partitioning or [[Logical volume management|volume management]] tools, which introduce various complexities and potential downtimes. =====Swappiness===== ''Swappiness'' is a [[Linux kernel]] parameter that controls the relative weight given to [[Virtual memory#Address space swapping|swapping out]] of [[Memory footprint|runtime memory]], as opposed to dropping [[Page (computer memory)|pages]] from the system [[page cache]], whenever a memory allocation request cannot be met from free memory. Swappiness can be set to a value from 0 to 200.<ref>{{cite web|url=https://www.kernel.org/doc/html/latest/admin-guide/sysctl/vm.html#swappiness|title=The Linux Kernel Documentation for /proc/sys/vm/}}</ref> A low value causes the kernel to prefer to evict pages from the page cache while a higher value causes the kernel to prefer to swap out "cold" memory pages. The [[Default (computer science)|default value]] is <code>60</code>; setting it higher can cause high latency if cold pages need to be swapped back in (when interacting with a program that had been idle for example), while setting it lower (even 0) may cause high latency when files that had been evicted from the cache need to be read again, but will make interactive programs more responsive as they will be less likely to need to swap back cold pages. Swapping can also slow down [[Hard disk drive|HDDs]] further because it involves a lot of random writes, while [[Solid-state drive|SSDs]] do not have this problem. Certainly the default values work well in most workloads, but desktops and interactive systems for any expected task may want to lower the setting while batch processing and less interactive systems may want to increase it.<ref name="kerneltrap">{{cite web |url=http://kerneltrap.org/node/3000 |title=Linux: Tuning Swappiness |first=Jeremy |last=Andrews |date=2004-04-29 |work=kerneltrap.org |archive-url=https://web.archive.org/web/20130524085654/http://kerneltrap.org/node/3000 |archive-date=2013-05-24 |url-status=dead |access-date=2018-01-03}} </ref> =====Swap death===== When the system memory is highly insufficient for the current tasks and a large portion of memory activity goes through a slow swap, the system can become practically unable to execute any task, even if the CPU is idle. When every process is waiting on the swap, the system is considered to be in ''swap death''.<ref>{{cite web |url=http://lkml.iu.edu/hypermail//linux/kernel/9805.2/0707.html |title=swap death (as in 2.1.91) and page tables |author=Rik van Riel |date=1998-05-20 |url-status=live |archive-url=https://web.archive.org/web/20171229195527/http://lkml.iu.edu/hypermail//linux/kernel/9805.2/0707.html |archive-date=2017-12-29 }}</ref><ref>{{cite book|author=Kyle Rankin|title=DevOps Troubleshooting: Linux Server Best Practices|url=https://books.google.com/books?id=icPyQDU3xD4C&pg=PT159|year=2012|publisher=Addison-Wesley|isbn=978-0-13-303550-6|page=159|url-status=live|archive-url=https://web.archive.org/web/20171229195527/https://books.google.com/books?id=icPyQDU3xD4C&pg=PT159|archive-date=2017-12-29}}</ref> Swap death can happen due to incorrectly configured [[memory overcommitment]].<ref>{{cite web|url=https://www.win.tue.nl/%7Eaeb/linux/lk/lk-9.html|author=Andries Brouwer|title=The Linux kernel: Memory|url-status=live|archive-url=https://web.archive.org/web/20170813052950/http://www.win.tue.nl/~aeb/linux/lk/lk-9.html|archive-date=2017-08-13}}</ref><ref>{{cite web|url=https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Performance_Tuning_Guide/s-memory-captun.html|title=Capacity Tuning|author=Red Hat|url-status=live|archive-url=https://web.archive.org/web/20170723214620/https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Performance_Tuning_Guide/s-memory-captun.html|archive-date=2017-07-23}}</ref><ref>{{cite web|url=https://iainvlinux.wordpress.com/2014/02/16/memory-overcommit-settings/|title=Memory overcommit settings|date=16 February 2014|url-status=live|archive-url=https://web.archive.org/web/20170531182419/https://iainvlinux.wordpress.com/2014/02/16/memory-overcommit-settings/|archive-date=2017-05-31}}</ref> The original description of the "swapping to death" problem relates to the [[X Window System protocols and architecture#Client–server model and network transparency|X server]]. If code or data used by the X server to respond to a keystroke is not in main memory, then if the user enters a keystroke, the server will take one or more page faults, requiring those pages to read from swap before the keystroke can be processed, slowing the response to it. If those pages do not remain in memory, they will have to be faulted in again to handle the next keystroke, making the system practically unresponsive even if it's actually executing other tasks normally.<ref>{{cite web|url=http://tech-insider.org/linux/research/1993/0210.html|title=swapping to death|date=1993-02-10|author=Peter MacDonald|url-status=live|archive-url=https://web.archive.org/web/20170328080649/http://tech-insider.org/linux/research/1993/0210.html|archive-date=2017-03-28}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)