Difference between revisions of "Swap/de"

Updating to match new version of source page
(Updating to match new version of source page)
Tags: Mobile web edit Mobile edit
(Updating to match new version of source page)
Line 34: Line 34:
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!
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 account all of the above, this brings us to the following table:
(last 3 columns denote swap space)
(last 3 columns denote swap space)


Line 68: Line 68:


The following script will:
The following script will:
* show whether zswap is active or not and if active, give zswap parameters if run with the `sudo` command
* show whether zswap is active or not and if active, give zswap parameters if run with the {{$ic|sudo}} command
* display a list of all applications / services that take up swap and how much they take up in descending order
* display a list of all applications / services that take up swap and how much they take up in descending order


Line 94: Line 94:
==Creating and Enabling a Swap Partition==
==Creating and Enabling a Swap Partition==


To create a swap partition, you need enough unallocated disk space to create an additional partition. If you do not have enough space, skip to the next section [[Special:MyLanguage/#Using_a_swap_file|#Using_a_swap_file]]. A swap partition can be created in any disk management / partition management tool and should be set as type `linuxswap`.
To create a swap partition, you need enough unallocated disk space to create an additional partition. If you do not have enough space, skip to the next section [[Special:MyLanguage/#Using_a_swap_file|#Using_a_swap_file]]. A swap partition can be created in any disk management / partition management tool and should be set as type {{ic|linuxswap}}.


Once you have a swap partition you will need to initialize the swap partition with {{ic|mkswap}}.  For example, if your swap partition is {{ic|/dev/sda3}}, you could use the command:
Once you have a swap partition you will need to initialize the swap partition with {{ic|mkswap}}.  For example, if your swap partition is {{ic|/dev/sda3}}, you could use the command:
Line 114: Line 114:


==Creating and Enabling a Static Swapfile==
==Creating and Enabling a Static Swapfile==
{{tip|There is no reason you can't have both a swap partition and a swapfile.  This is an easy way to add more swap without repartitioning}}
{{tip|There is no reason you can't have both a swap partition and a swapfile.  This is an easy way to add more swap without repartitioning.}}




Line 130: Line 130:




In order to ensure that the swap is enabled at boot we can add an entry to {{ic|/etc/fstab}}.  You can add the line to ftab manually or using the command:
In order to ensure that the swap is enabled at boot we can add an entry to {{ic|/etc/fstab}}.  You can add the line to fstab manually or using the command:
  sudo bash -c "echo /swapfile none swap defaults 0 0 >> /etc/fstab"
  sudo bash -c "echo /swapfile none swap defaults 0 0 >> /etc/fstab"


Line 158: Line 158:
==Installing and Configuring systemd-swap==
==Installing and Configuring systemd-swap==


First, install and enable {{ic|systemd-swap}}
First, install and enable {{ic|systemd-swap}}:
  pamac install systemd-swap
  pamac install systemd-swap
  sudo systemctl enable systemd-swap.service
  sudo systemctl enable systemd-swap.service
Line 174: Line 174:
==Remove Other Swap==
==Remove Other Swap==


In order for systemd_swap to be effective you need to remove any traditional swap devices you have.
In order for systemd-swap to be effective you need to remove any traditional swap devices you have.




Line 199: Line 199:




Next reboot.  After the reboot you should see something similiar to the following when running {{ic|swapon}}
Next reboot.  After the reboot, when running {{ic|swapon}} you should see something similiar to the following:
  NAME                          TYPE SIZE USED PRIO
  NAME                          TYPE SIZE USED PRIO
  /var/lib/systemd-swap/swapfc/1 file 512M  0B  -2
  /var/lib/systemd-swap/swapfc/1 file 512M  0B  -2
Line 212: Line 212:
zswap is compressed swap kept in RAM. zswap keeps the most frequently used pages in RAM and writes less frequently used pages to the swap space on disk.  In many workloads, this will result in increased swap performance and less wear and tear on SSDs.
zswap is compressed swap kept in RAM. zswap keeps the most frequently used pages in RAM and writes less frequently used pages to the swap space on disk.  In many workloads, this will result in increased swap performance and less wear and tear on SSDs.


To enable zswap with systemd-swap, simply alter the instructions above and set {{ic|zswap_enabled to 1}}
To enable zswap with systemd-swap, simply alter the instructions above and set Linux Kernel parameter {{ic|zswap_enabled=1}}
=Tuning & Performance Considerations=
=Tuning & Performance Considerations=


Line 226: Line 226:
* 100 is very aggressive swapping.
* 100 is very aggressive swapping.


For ''most'' desktops/laptops the recommended value is 10: Theoretically, this means to only start swapping when RAM usage reaches around 90 percent.
For ''most'' computers the recommended value is 10: Theoretically, this means to only start swapping when RAM usage reaches around 90 percent.


{{ic|vfs_cache_pressure}} is a percentage value that controls the tendency of the kernel to *reclaim* the memory which is used for caching of directory and inode objects.  The default value is 100.  Increasing this value will increase the rate in which these objects are removed from the RAM cache.  Decreasing it will allow these objects to be cached in memory longer, consuming additional RAM over time.  Depending on your specific workload, increasing or decreasing this value too far can have significant negative impacts on system performance.  Experimentation is needed to find the appropriate balance and the default value is reasonable.  In general, it is more common to optimize swappiness before experimenting with vfs_cache_pressure.
{{ic|vfs_cache_pressure}} is a percentage value that controls the tendency of the kernel to ''reclaim'' the memory which is used for caching of directory and inode objects.  The default value is 100.  Increasing this value will increase the rate in which these objects are removed from the RAM cache.  Decreasing it will allow these objects to be cached in memory longer, consuming additional RAM over time.  Depending on your specific workload, increasing or decreasing this value too far can have significant negative impacts on system performance.  Experimentation is needed to find the appropriate balance and the default value is reasonable.  In general, it is more common to optimize swappiness before experimenting with vfs_cache_pressure.


To set these values you can use the command {{ic|sysctl}}.  For example, to set the swappiness value to 10 you could use:
To set these values you can use the command {{ic|sysctl}}.  For example, to set the swappiness value to 10 you could use:
Line 242: Line 242:
* The Linux kernel documentation on [https://www.kernel.org/doc/Documentation/vm/zswap.txt zswap]
* The Linux kernel documentation on [https://www.kernel.org/doc/Documentation/vm/zswap.txt zswap]
* The Linux kernel documentation on [https://www.kernel.org/doc/Documentation/sysctl/vm.txt swappiness and vfs_cache_pressure]
* The Linux kernel documentation on [https://www.kernel.org/doc/Documentation/sysctl/vm.txt swappiness and vfs_cache_pressure]
* The opensuse guide to [https://doc.opensuse.org/documentation/leap/tuning/html/book.sle.tuning/cha.tuning.memory.html tuning memory]
* The openSUSE guide to [https://doc.opensuse.org/documentation/leap/tuning/html/book.sle.tuning/cha.tuning.memory.html tuning memory]
* The [https://github.com/Nefelim4ag/systemd-swap systemd-swap page]
* The [https://github.com/Nefelim4ag/systemd-swap systemd-swap page]
* The ZFS on Linux guide on [https://github.com/zfsonlinux/pkg-zfs/wiki/HOWTO-use-a-zvol-as-a-swap-device Swap Volumes]
* The ZFS on Linux guide on [https://github.com/zfsonlinux/pkg-zfs/wiki/HOWTO-use-a-zvol-as-a-swap-device Swap Volumes]
8,560

edits