Difference between revisions of "Swap/en"

3,505 bytes removed ,  1 year ago
Updating to match new version of source page
(Updating to match new version of source page)
(Updating to match new version of source page)
 
Line 164: Line 164:


Detailed instructions on how to accomplish this can be found in this [https://github.com/zfsonlinux/pkg-zfs/wiki/HOWTO-use-a-zvol-as-a-swap-device ZoL guide].
Detailed instructions on how to accomplish this can be found in this [https://github.com/zfsonlinux/pkg-zfs/wiki/HOWTO-use-a-zvol-as-a-swap-device ZoL guide].
=Automated Swap Management with systemd-swap=
{{note|Using systemd-swap with on btrfs/zfs or with hibernation support requires special handling beyond the scope of this article}}
It is possible to automatically manage the size of your swapfile using {{ic|systemd-swap}}.  It can create swap files dynamically based on memory needs.  It is also an easy way to enable/manage [[#Using_zswap_with_systemd-swap|zswap]]
==Installing and Configuring systemd-swap==
First, install and enable {{ic|systemd-swap}}:
pamac install systemd-swap
sudo systemctl enable systemd-swap.service
Next enable dynamic swap management by creating a file {{ic|/etc/systemd/swap.conf.d/myswap.conf}} with the following parameters:
zswap_enabled=0
zram_enabled=0
swapfc_enabled=1
If you would prefer a single command to create this file you could use:
sudo bash -c 'echo -e "zswap_enabled=0\nzram_enabled=0\nswapfc_enabled=1" > /etc/systemd/swap.conf.d/myswap.conf'
==Remove Other Swap==
In order for systemd-swap to be effective you need to remove any traditional swap devices you have.
To display your current swap devices you can use the command {{ic|swapon}}.  For example, my test machine displays the following:
swapon
NAME      TYPE      SIZE USED PRIO
/swapfile file        4G  0B  -2
/dev/sda3 partition 8.4G  0B  -3
In this example there are two swap devices.  A swapfile and a swap partition.  To turn them off we can use the command {{ic|swapoff}}.
sudo swapoff /swapfile
sudo swapoff /dev/sda3
Next we need to remove them. 
The swap partition will need to be deleted using your favorite partitioning tool.  You can remove the swapfile by simply deleting it.
sudo rm /swapfile
We need to also remove any lines related to swap from {{ic|/etc/fstab}}.  Edit the file with an [[Special:MyLanguage/Viewing_and_editing_configuration_files|appropriate text editor]] and remove or comment out the lines for the swap space.  In the example above, we would remove these lines:
UUID=c2430cf1-8ea9-4422-a5c5-5a38779194c3 swap          swap    defaults,noatime 0 2
/swapfile none swap defaults 0 0
With hibernation configured it will also be necessary to edit {{ic|/etc/default/grub}}. Find and remove option {{ic|<nowiki>resume=UUID=...</nowiki>}} or replace the UUID with a new proper value.  In the example above, we would remove this text:
resume=UUID=c2430cf1-8ea9-4422-a5c5-5a38779194c3
Then run:
sudo update-grub
If removing hibernation entirely then also delete {{ic|resume}} from the {{ic|HOOKS}} line in {{ic|/etc/mkinitcpio.conf}} and run:
sudo mkinitcpio -P
Next reboot.  After the reboot, when running {{ic|swapon}} you should see something similiar to the following:
NAME                          TYPE SIZE USED PRIO
/var/lib/systemd-swap/swapfc/1 file 512M  0B  -2
systemd-swap will add and remove swapfiles as your memory usage dictates.
{{note|If you don't delete your existing swap partition it will be automatically activated by systemd even though you have removed it from fstab}}
==Using zswap with systemd-swap==
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 Linux Kernel parameter  zswap_enabled=1
=Tuning & Performance Considerations=
=Tuning & Performance Considerations=


Line 264: Line 193:
* 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 [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]




[[Category:Contents Page{{#translation:}}]]
[[Category:Contents Page{{#translation:}}]]
8,560

edits