linux native与swap,铜豌豆 Linux

systemd-swap

Script to manage swap on:

zswap - Enable/Configure

zram - Autoconfigurating for swap

files - (sparse files for saving space, supports btrfs)

block devices - auto find and do swapon

14239df9f2fff189690b638235095734.png It is configurable in /etc/systemd/swap.conf.

Additional terms:

SwapFC (File Chunked) - provides a dynamic swap file allocation/deallocation

File location

/etc/systemd/swap.conf

/usr/lib/systemd/system/systemd-swap.service

/usr/bin/systemd-swap

Please don't forget to enable with

sudosystemctl enablesystemd-swap

Install

fe14d7522461abc3d736267983f0819f.png Arch: in the community.

ee5167a6d47059cefb06f41172a3fb87.png Debian: use package.sh in git repo

git clone https://github.com/Nefelim4ag/systemd-swap.git

./systemd-swap/package.sh debian

sudodpkg -i ././systemd-swap/systemd-swap_*_all.deb

6ec7e83f913bfd8b568c66d89ebf6b78.png Fedora: use package.sh

git clone https://github.com/Nefelim4ag/systemd-swap.git

./systemd-swap/package.sh fedora f28

sudodnf install ./systemd-swap/systemd-swap-*noarch.rpm

Manual

git clone https://github.com/Nefelim4ag/systemd-swap.git

sudomake install

About configuration

Q: WTF?! Why do you merge swapFC and swapFU?

A: It simplifies testing of swapFC code and makes the code more generic.

Q: How can I migrate swapFU config from 3.X to 4.X?

A: Most of the switches are the same, to get configuration like swapFU from swapFC, set swapfc_max_count to 1 and swapfc_chunk_size to size of swapFU.

Q: Do we need to activate both zram and zswap?

A: Nope, it's useless, as zram is a compressed RAM DISK, but zswap is a compressed "writeback" CACHE on swap file/disk.

Q: Do I need to use swapfc_force_use_loop on swapFC?

A: Nope, as you wish really, native swapfile should work faster and it's safer in OOM condition in comparison to loop backed scenario.

Q: When would we want a certain configuration?

A: In most cases (Notebook, Desktop, Server) it's enough to enable zswap + swapfc (on server tuning of swapfc can be needed).

If you use SSD and care about flash memory wear, use only ZRam.

Q: Where is the swap file located?

A: Read carefully swap.conf

Q: Can we use this to enable hibernation?

A: Nope as hibernation wants a persistent fs blocks and wants access to swap data directly from disk, this will not work on: zram, swapfu, swapfc (without some magic of course).

Note

14239df9f2fff189690b638235095734.png Zram dependence: util-linux >= 2.26

14239df9f2fff189690b638235095734.png If you use zram not for swap only, use kernel 4.2+ or please add rule for modprobe like:

options zram max_devices=32

Switch On Systemd Swap

Check your configuration:

cat /proc/sys/vm/swappiness

cat /proc/sys/vm/vfs_cache_pressure

Recommended configuration for Desktop:

echovm.swappiness=5 | sudo tee -a /etc/sysctl.d/99-sysctl.conf

echovm.vfs_cache_pressure=50 | sudo tee -a /etc/sysctl.d/99-sysctl.conf

sudosysctl -p /etc/sysctl.d/99-sysctl.conf

Check configuration after Systemd Swap is installed:

nano /etc/systemd/swap.conf

zram_enabled=0

zswap_enabled=1

swapfc_enabled=1

Stop your swap:

sudoswapoff -a

Remove swap entry from fstab:

nano /etc/fstab

Remove your swap

# For Ubuntu

sudo rm -f /swapfile

# For Centos 7

lvremove -Ay /dev/centos/swap

lvextend -l +100%FREE centos/root

Remove swap from Grub:

# For Ubuntu remove resume* in grub

nano /etc/default/grub

# For Centos 7 remove rd.lvm.lv=centos/swap*

nano /etc/default/grub

# For Manjaro remove resume* in grub & mkinitcpio

nano /etc/default/grub

nano /etc/mkinitcpio.conf

# For Ubuntu

update-grub

# For Centos 7

update-grub

# For Manjaro

update-grub

mkinitcpio -P

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值