nefelim4ag / systemd-swap Goto Github PK
View Code? Open in Web Editor NEWScript for creating hybrid swap space from zram swaps, swap files and swap partitions.
License: GNU General Public License v3.0
Script for creating hybrid swap space from zram swaps, swap files and swap partitions.
License: GNU General Public License v3.0
Hi, I'm using systemd-swap with Zswap and Swap File Chunked. Recently after noticing some performance issues I saw that swap was no longer activated (htop showing 0k/0k when normally it would show 0k/256MB if swap was active but not in use). I checked the output of journalctl and found this:
Feb 17 05:55:27 valkyrie systemd-swap[1173]: INFO: Backup config
Feb 17 05:55:27 valkyrie systemd-swap[1173]: INFO: Load config
Feb 17 05:55:27 valkyrie systemd-swap[1173]: INFO: Zswap: backup current configuration: start
Feb 17 05:55:29 valkyrie systemd-swap[1173]: INFO: Zswap: backup current configuration: complete
Feb 17 05:55:29 valkyrie systemd-swap[1173]: INFO: Zswap: set new parameters: start
Feb 17 05:55:29 valkyrie systemd-swap[1173]: INFO: Zswap: set new parameters: complete
Feb 17 05:55:29 valkyrie systemd-swap[1173]: INFO: swapD: searching swap devices
Feb 17 05:55:30 valkyrie systemd-swap[1173]: sleep: missing operand
Feb 17 05:55:30 valkyrie systemd-swap[1173]: Try 'sleep --help' for more information.
It looks like there's just a syntax error preventing it from starting. I am using Arch Linux and I can provide more information if needed. I'd love to get this fixed for my low memory laptop. Thanks for the hard work on this fantastic daemon.
Can't to create more than one /dev/zram0 devices.
no zram devices with uncommented zram[streams]=${sys[cpu_count]} in /etc/systemd-swap.conf
See bug FS#41361 in archlinux bugzilla.
systemd-swap make more complex over time and i think it's time for rewrite in on python to simplify.
I found a small bug in your systemd-swap script.
/usr/bin/systemd-swap: linia 172: (*100)/(+1) : błąd składni: spodziewany argument (błędny znacznik t...
I'm polish Linux Manjaro user.
You have declared statically "free -b | grep Swap:" in 172 script line.
"grep" doesn't return nothing.
$free -b
Result:
razem użyte wolne dzielone buf/cache dostępne
Pamięć: 3387 838 1560 177 988 2130
Wymiana: 2047 0 2047
If you see - grep word "SWAP" is polished -> no "SWAP" but "Wymiana"
....and your script make a new chunks.
I changed the word to Polish counterpart and the script works properly.
cut -d ' ' -f 5-
finished starting up.
systemd-swap[24331]: INFO: Load: /etc/systemd//swap.conf
systemd-swap[24331]: INFO: Zram: check availability
systemd-swap[24331]: INFO: Zram: module already loaded
systemd-swap[24331]: INFO: Zram: trying to initialize free device
systemd-swap[24331]: INFO: Zram: trying to initialize free device
systemd-swap[24331]: INFO: Zram: trying to initialize free device
systemd-swap[24331]: INFO: Zram: trying to initialize free device
systemd-swap[24331]: INFO: Zram: trying to initialize free device
systemd-swap[24331]: INFO: Zram: trying to initialize free device
systemd-swap[24331]: INFO: Zram: trying to initialize free device
systemd-swap[24331]: INFO: Zram: trying to initialize free device
systemd-swap[24331]: INFO: Zram: trying to initialize free device
systemd-swap[24331]: INFO: Zram: trying to initialize free device
systemd-swap[24331]: INFO: Zram: initialized:
systemd-swap[24331]: Too few arguments.
systemd-swap[24331]: INFO: swapD: pickup devices from systemd-gpt-auto-generator
systemd-swap[24331]: INFO: swapD: searching swap devices
I've enabled zram with the following:
cat /etc/systemd/swap.conf.d/zram.conf
zswap_enabled=0
zram_enabled=1
zram_size=1024M # This is 1/4 of ram size by default.
zram_alg=lz4hc # lzo lz4 deflate lz4hc 842 - for Linux 4.8.4%
System:
ArchLinux : Linux losthost 4.15.10-1-ARCH #1 SMP PREEMPT
util-linux 2.31.1-1
Hi,
I noticed you've set the protectHome
flag to true
in the systemd unit file. Is there a reason to do so ?
I assume setting it to read-only
would actually be better since it would allow people to link the config files from their homedir to /etc/systemd/swap.conf.d/ .
Cool project.
Could you add more documentation? There are some unanswered questions in the Arch Wiki about systemd-swap.
https://wiki.archlinux.org/index.php/Talk:Swap#systemd-swap
Here are some of the key questions.
I am getting a losetup error when trying to use swapfu. My configuration is just the default value, and I have tried to execute the commands myself, which works correctly :/
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: INFO: swapF: search free loop
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: INFO: swapF: use
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: losetup: option requires an argument -- 'd'
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: Usage:
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: losetup [options] [<loopdev>]
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: losetup [options] -f | <loopdev> <file>
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: Set up and control loop devices.
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: Options:
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -a, --all list all used devices
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -d, --detach <loopdev>... detach one or more devices
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -D, --detach-all detach all used devices
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -f, --find find first unused device
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -c, --set-capacity <loopdev> resize the device
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -j, --associated <file> list all devices associated with <file>
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -o, --offset <num> start at offset <num> into file
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: --sizelimit <num> device is limited to <num> bytes of the file
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -P, --partscan create a partitioned loop device
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -r, --read-only set up a read-only loop device
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: --direct-io[=<on|off>] open backing file with O_DIRECT
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: --show print device name after setup (with -f)
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -v, --verbose verbose mode
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -l, --list list info about all or specified (default)
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -O, --output <cols> specify columns to output for --list
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -n, --noheadings don't print headings for --list output
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: --raw use raw --list output format
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -J, --json use JSON --list output format
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -h, --help display this help and exit
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: -V, --version output version information and exit
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: Available --list columns:
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: NAME loop device name
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: AUTOCLEAR autoclear flag set
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: BACK-FILE device backing file
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: BACK-INO backing file inode number
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: BACK-MAJ:MIN backing file major:minor device number
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: MAJ:MIN loop device major:minor number
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: OFFSET offset from the beginning
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: PARTSCAN partscan flag set
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: RO read-only device
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: SIZELIMIT size limit of the file in bytes
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: DIO access backing file with direct-io
Oct 27 11:12:53 flygon.felixc.at systemd-swap[2896]: For more details see losetup(8).
I've noticed that ~30% of the time, zram didn't get enabled, and the log:
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: [lzo] lz4
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: /dev/sda2 >> /run/lock/systemd-swap.dev
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: 1 >> /sys/block/zram0/reset
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: lz4 >> /sys/block/zram0/comp_algorithm
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: 13618343K >> /sys/block/zram0/disksize
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: mkswap: error: swap area needs to be at least 40 KiB
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: Usage:
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: mkswap [options] device [size]
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: Options:
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: -c, --check check bad blocks before creating the swap area
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: -f, --force allow swap size area be larger than device
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: -p, --pagesize SIZE specify page size in bytes
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: -L, --label LABEL specify label
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: -v, --swapversion NUM specify swap-space version number
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: -U, --uuid UUID specify the uuid to use
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: -V, --version output version information and exit
Jul 07 23:05:17 flygon.felixc.at systemd-swap.sh[335]: -h, --help display this help and exit
My wild guess would be that mkswap was called too early (before the disksize actually took effect). I'll add some workaround and see if that works.
At one of cheap and "low-end" VPS I got (from about a month). The VPS is 2 core 1GB RAM 30 GB SSD, Arch Linux with up to date kernel 4.13.3-1-ARCH:
oct 02 09:32:13 lowend-vps systemd-swap[188]: INFO: swapFC: free swap: 13 < 15 - allocate chunk: 4
oct 02 09:32:18 lowend-vps kernel: z3fold: No free chunks in unbuddied
oct 02 09:32:18 lowend-vps kernel: z3fold: No free chunks in unbuddied
oct 02 09:32:18 lowend-vps kernel: ------------[ cut here ]------------
oct 02 09:32:18 lowend-vps kernel: WARNING: CPU: 0 PID: 4490 at mm/z3fold.c:421 z3fold_zpool_malloc+0x414/0x430
oct 02 09:32:18 lowend-vps kernel: Modules linked in: tun xt_nat veth ipt_MASQUERADE nf_nat_masquerade_ipv4 nf_conntrack_netlink nfnetlink xfrm_user xfrm_algo iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 7691 kernel messages
oct 02 09:32:18 lowend-vps kernel: ? shrink_node+0xf7/0x2f0
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 2204 kernel messages
oct 02 09:32:18 lowend-vps kernel: ------------[ cut here ]------------
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 213 kernel messages
oct 02 09:32:18 lowend-vps kernel: ---[ end trace f059f47465d27681 ]---
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 181 kernel messages
oct 02 09:32:18 lowend-vps kernel: ------------[ cut here ]------------
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 33 kernel messages
oct 02 09:32:18 lowend-vps kernel: ---[ end trace f059f47465d27687 ]---
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 111 kernel messages
oct 02 09:32:18 lowend-vps kernel: Modules linked in: tun xt_nat veth ipt_MASQUERADE nf_nat_masquerade_ipv4 nf_conntrack_netlink nfnetlink xfrm_user xfrm_algo iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 340 kernel messages
oct 02 09:32:18 lowend-vps kernel: zswap_frontswap_store+0x290/0x4a0
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 36 kernel messages
oct 02 09:32:18 lowend-vps kernel: __frontswap_store+0x6d/0xf0
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 110 kernel messages
oct 02 09:32:18 lowend-vps kernel: shrink_page_list+0xa19/0xb60
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 232 kernel messages
oct 02 09:32:18 lowend-vps kernel: CPU: 1 PID: 36 Comm: kswapd0 Tainted: G W 4.13.3-1-ARCH #1
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 494 kernel messages
oct 02 09:32:18 lowend-vps kernel: CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 23 kernel messages
oct 02 09:32:18 lowend-vps kernel: CPU: 0 PID: 4489 Comm: php-fpm Tainted: G W 4.13.3-1-ARCH #1
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 585 kernel messages
oct 02 09:32:18 lowend-vps kernel: ---[ end trace f059f47465d276bc ]---
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 35 kernel messages
oct 02 09:32:18 lowend-vps kernel: __alloc_pages_nodemask+0x237/0x250
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 32 kernel messages
oct 02 09:32:18 lowend-vps kernel: FS: 00007faf12a8db48(0000) GS:ffff8e177fc00000(0000) knlGS:0000000000000000
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 40 kernel messages
oct 02 09:32:18 lowend-vps kernel: virtio_net virtio_blk serio_raw atkbd libps2 virtio_pci virtio_ring virtio floppy uhci_hcd ehci_pci ehci_hcd i8042 ata_piix usbcore serio libata usb_common scsi_mod
oct 02 09:32:18 lowend-vps kernel: CPU: 0 PID: 4490 Comm: php-fpm Tainted: G W 4.13.3-1-ARCH #1
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 43 kernel messages
oct 02 09:32:18 lowend-vps kernel: Code: b8 e8 91 bd 44 00 48 89 df e8 c9 c2 44 00 48 8b 45 b0 f0 ff 08 74 1b 48 89 df e8 78 bd 44 00 48 c7 c7 f8 f0 94 b5 e8 0d df eb ff <0f> ff e9 1d fe ff ff 48 8b 7d b0 e8 1c fb ff
oct 02 09:32:18 lowend-vps systemd-journald[144]: Missed 581 kernel messages
in my opinion, having swap file enabled by default is a bad choice.
in scenarios, where you want non-ram based swap, you create a dedicated partition (which then gets handled automatically). when you don't want non-ram based swap, you do that mostly because the drive is flash based and you want to minimize writes.
currently, systemd-swap does not find a swap in fstab nor does not find a dedicated partition and therefore creates a loop based swap which sabotages the original intent of not having drive based swap.
please consider having this disabled by default.
Hey,
I use the umask=027, so this error happens:
dpkg-deb: error: control directory has bad permissions 750 (must be >=0755 and <=0775)
After adding line 15:
chmod 755 $DEB_NAME/DEBIAN
the error is gone.
I configured systemd-swap to use zswap by uncommenting these four lines:
zswap[enabled]=1 zswap[compressor]=lz4 zswap[max_pool_percent]=15 zswap[zpool]=zbud
unfortunately dmesg reports a different compressor:
[ 0.296973] zswap: loaded using pool lzo/zbud
If I run dmesg | grep -i zswap
, it says lzo
is being used for compression.
[ 0.724002] zswap: loaded using pool lzo/zbud
However, sudo systemd-swap status
says it's using lz4
Zswap:
. compressor lz4
. enabled Y
. max_pool_percent 80
. zpool z3fold
. . duplicate_entry 0
. . pool_limit_hit 0
. . pool_total_size 0
. . reject_alloc_fail 0
. . reject_compress_poor 0
. . reject_kmemcache_fail 0
. . reject_reclaim_fail 0
. . stored_pages 0
. . written_back_pages 0
. . compress_ratio 0%
SwapFC:
. NAME TYPE SIZE USED PRIO
. /var/lib/systemd-swap/swapfc/1 file 512M 0B -1
SwapD:
. NAME TYPE SIZE USED PRIO
Is lz4
being used actually?
PS: I have lz4
,lz4_compression
added in /etc/initramfs-tools/modules
cat /etc/initramfs-tools/modules
# List of modules that you want to include in your initramfs.
# They will be loaded at boot time in the order below.
#
# Syntax: module_name [args ...]
#
# You must run update-initramfs(8) to effect this change.
#
# Examples:
#
# raid1
# sd_mod
lz4
lz4_compress
Today I did a fresh Arch installation (no GUI) on a VM and then installed systemd-swap (3.5.0-1)
with the following config options:
zswap_enabled=0
swapfc_enabled=1
I checked my system and saw that now swap files where active.
checked the output of htop and saw a process was still running
shred -n1 -z /var/lib/systemd-swap/swapfc//1
While investigating I looked again to htop and saw that the number has changed:
shred -n1 -z /var/lib/systemd-swap/swapfc//8
So I thought that something is wrong with swapfc trying to create(?) ckunks and failing. Then tries again but fails.
I checked sudo systemctl status systemd-swap and the output gave me a hint:
Faild to start var-lib-systemd-swap-swapfc--1.swap: Unit var-lib-systemd-swap-swapfc--1.swap is not loaded properly: Invalid argument. See system logs and systemctl status var-lib-systemd-swap-swapfc--1.swap
And the above was repeated for every chunk
So, I run systemctl status var-lib-systemd-swap-swapfc--1.swap and there was:
Value of What= and unit name do not match, not loading
Any ideas how to investigate this ?
On my main machine I have systemd-swap (3.4.2-1) with the same config options and It is working properly.
Could this be a regression ?
I wonder why always recreating "/var/lib/systemd-swap/swapfc/1" every time when systemd-swap service is restarted.
Related to issue #57. I have a Raspberry Pi and I'd like to set multiple locations for swapfiles in case of fail. If a attached USB hard drive fails try another set location but don't halt the system if no swap can be set up.
Hi, I'm not sure if you're already working on it, but the 4.0.0 release left README.md out of date, it still mentions Swap File Universal in the configuration section even though 4a1706a merged swapfu into swapfc. Also, can you clarify how to update the old swap.conf for those who were making use of the swapfu options?
Hi, I wanted to know, for packaging, if it wasn't a better idea to provide the 90-systemd-swap.conf inside of /usr/lib/modprobe.d instead of /etc/modprobe.d
Maybe also the service file inside /usr/lib, only the config file should need to be inside /etc.
Unless it's a user overriding the package-provided files, then they would all be inside /etc
lsmod | grep zram
zram 28672 0
sudo systemd-swap start
INFO: Load: /etc/systemd//swap.conf
INFO: Zswap: backup current configuration: start
INFO: Zswap: backup current configuration: complete
INFO: Zswap: set new parameters: start
INFO: Zswap: Enable: 1, Comp: lz4, Max pool %: 25, Zpool: zbud
INFO: Zswap: set new parameters: complete
INFO: swapD: pickup devices from systemd-gpt-auto-generator
INFO: swapD: searching swap devices
sudo systemd-swap status
Zswap:
. compressor lz4
. enabled Y
. max_pool_percent 25
. zpool zbud
. . duplicate_entry 0
. . pool_limit_hit 0
. . pool_total_size 0
. . reject_alloc_fail 0
. . reject_compress_poor 0
. . reject_kmemcache_fail 0
. . reject_reclaim_fail 0
. . stored_pages 0
. . written_back_pages 0
. . compress_ratio 0%
. . zswap_store/swap_store 0/186646528 0%
ls /dev/zram*
ls: cannot access '/dev/zram*': No such file or directory
sudo systemd-swap stop
INFO: Zswap: restore configuration: start
INFO: Zswap: restore configuration: complete
sudo bash -x systemd-swap start
+ readonly RUN_SYSD=/run/systemd/
+ RUN_SYSD=/run/systemd/
++ nproc
+ readonly NCPU=8
+ NCPU=8
++ grep MemTotal: /proc/meminfo
++ grep -o '[0-9]*'
+ readonly RAM_SIZE=3147681792
+ RAM_SIZE=3147681792
++ getconf PAGESIZE
+ readonly PAGE_SIZE=4096
+ PAGE_SIZE=4096
+ readonly ETC_SYSD=/etc/systemd/
+ ETC_SYSD=/etc/systemd/
+ readonly CONFIG=/etc/systemd//swap.conf
+ CONFIG=/etc/systemd//swap.conf
+ readonly WORK_DIR=/run/systemd/swap
+ WORK_DIR=/run/systemd/swap
+ readonly LOCK_STARTED=/run/systemd/swap/.started
+ LOCK_STARTED=/run/systemd/swap/.started
+ readonly ZSWAP_M=/sys/module/zswap
+ ZSWAP_M=/sys/module/zswap
+ readonly ZSWAP_M_P=/sys/module/zswap/parameters
+ ZSWAP_M_P=/sys/module/zswap/parameters
+ AMI_ROOT
+ '[' 0 == 0 ']'
+ mkdir -p /run/systemd/swap /run/systemd//system/local-fs.target.wants /run/systemd//system/swap.target.wants
+ case "$1" in
+ '[' -f /run/systemd/swap/.started ']'
+ touch /run/systemd/swap/.started
+ INFO 'Load: /etc/systemd//swap.conf'
+ echo 'INFO: Load: /etc/systemd//swap.conf'
INFO: Load: /etc/systemd//swap.conf
+ . /etc/systemd//swap.conf
++ zswap_enabled=1
++ zswap_compressor=lz4
++ zswap_max_pool_percent=25
++ zswap_zpool=zbud
++ zram_enabled=0
++ zram_size=786920448
++ zram_streams=8
++ zram_alg=lz4
++ zram_prio=32767
++ swapfc_enabled=0
++ swapfc_force_use_loop=0
++ swapfc_frequency=1s
++ swapfc_chunk_size=512M
++ swapfc_max_count=8
++ swapfc_free_swap_perc=15
++ swapfc_path=/var/lib/systemd-swap/swapfc/
++ swapfc_nocow=1
++ swapfc_directio=1
++ swapfc_force_preallocated=0
++ swapd_auto_swapon=1
++ swapd_prio=1024
+ '[' -d /etc/systemd//swap.conf.d ']'
+ for L_CONF in $ETC_SYSD/swap.conf.d/*
+ '[' '!' -f '/etc/systemd//swap.conf.d/*' ']'
+ continue
+ zswap_enabled=1
+ YN 1
+ l=1
+ [[ 1 =~ (yes|y|1|true) ]]
+ return 0
+ '[' '!' -d /sys/module/zswap ']'
+ zswap_compressor=lz4
+ zswap_max_pool_percent=25
+ zswap_zpool=zbud
+ INFO 'Zswap: backup current configuration: start'
+ echo 'INFO: Zswap: backup current configuration: start'
INFO: Zswap: backup current configuration: start
+ mkdir -p /run/systemd/swap/zswap/
+ for file in $ZSWAP_M_P/*
+ read -r VAL
++ basename /sys/module/zswap/parameters/compressor
+ write_l lzo /run/systemd/swap/zswap/compressor
+ '[' -z lzo ']'
+ '[' -z /run/systemd/swap/zswap/compressor ']'
+ DATA=lzo
+ FILE=/run/systemd/swap/zswap/compressor
++ echo lzo
++ base64
+ DATA=bHpvCg==
+ ln -sfr /bHpvCg== /run/systemd/swap/zswap/compressor
+ for file in $ZSWAP_M_P/*
+ read -r VAL
++ basename /sys/module/zswap/parameters/enabled
+ write_l N /run/systemd/swap/zswap/enabled
+ '[' -z N ']'
+ '[' -z /run/systemd/swap/zswap/enabled ']'
+ DATA=N
+ FILE=/run/systemd/swap/zswap/enabled
++ echo N
++ base64
+ DATA=Tgo=
+ ln -sfr /Tgo= /run/systemd/swap/zswap/enabled
+ for file in $ZSWAP_M_P/*
+ read -r VAL
++ basename /sys/module/zswap/parameters/max_pool_percent
+ write_l 20 /run/systemd/swap/zswap/max_pool_percent
+ '[' -z 20 ']'
+ '[' -z /run/systemd/swap/zswap/max_pool_percent ']'
+ DATA=20
+ FILE=/run/systemd/swap/zswap/max_pool_percent
++ echo 20
++ base64
+ DATA=MjAK
+ ln -sfr /MjAK /run/systemd/swap/zswap/max_pool_percent
+ for file in $ZSWAP_M_P/*
+ read -r VAL
++ basename /sys/module/zswap/parameters/zpool
+ write_l zbud /run/systemd/swap/zswap/zpool
+ '[' -z zbud ']'
+ '[' -z /run/systemd/swap/zswap/zpool ']'
+ DATA=zbud
+ FILE=/run/systemd/swap/zswap/zpool
++ echo zbud
++ base64
+ DATA=emJ1ZAo=
+ ln -sfr /emJ1ZAo= /run/systemd/swap/zswap/zpool
+ INFO 'Zswap: backup current configuration: complete'
+ echo 'INFO: Zswap: backup current configuration: complete'
INFO: Zswap: backup current configuration: complete
+ INFO 'Zswap: set new parameters: start'
+ echo 'INFO: Zswap: set new parameters: start'
INFO: Zswap: set new parameters: start
+ INFO 'Zswap: Enable: 1, Comp: lz4, Max pool %: 25, Zpool: zbud'
+ echo 'INFO: Zswap: Enable: 1, Comp: lz4, Max pool %: 25, Zpool: zbud'
INFO: Zswap: Enable: 1, Comp: lz4, Max pool %: 25, Zpool: zbud
+ write 1 /sys/module/zswap/parameters/enabled
+ '[' -z 1 ']'
+ '[' -z /sys/module/zswap/parameters/enabled ']'
+ DATA=1
+ FILE=/sys/module/zswap/parameters/enabled
+ echo 1
+ write lz4 /sys/module/zswap/parameters/compressor
+ '[' -z lz4 ']'
+ '[' -z /sys/module/zswap/parameters/compressor ']'
+ DATA=lz4
+ FILE=/sys/module/zswap/parameters/compressor
+ echo lz4
+ write 25 /sys/module/zswap/parameters/max_pool_percent
+ '[' -z 25 ']'
+ '[' -z /sys/module/zswap/parameters/max_pool_percent ']'
+ DATA=25
+ FILE=/sys/module/zswap/parameters/max_pool_percent
+ echo 25
+ write zbud /sys/module/zswap/parameters/zpool
+ '[' -z zbud ']'
+ '[' -z /sys/module/zswap/parameters/zpool ']'
+ DATA=zbud
+ FILE=/sys/module/zswap/parameters/zpool
+ echo zbud
+ INFO 'Zswap: set new parameters: complete'
+ echo 'INFO: Zswap: set new parameters: complete'
INFO: Zswap: set new parameters: complete
+ zram_enabled=0
+ YN 0
+ l=0
+ [[ 0 =~ (yes|y|1|true) ]]
+ return 1
+ swapfc_enabled=0
+ YN 0
+ l=0
+ [[ 0 =~ (yes|y|1|true) ]]
+ return 1
+ swapd_auto_swapon=1
+ swapd_prio=1024
+ YN 1
+ l=1
+ [[ 1 =~ (yes|y|1|true) ]]
+ return 0
+ INFO 'swapD: pickup devices from systemd-gpt-auto-generator'
+ echo 'INFO: swapD: pickup devices from systemd-gpt-auto-generator'
INFO: swapD: pickup devices from systemd-gpt-auto-generator
+ FIND_SWAP_UNITS
+ find /run/systemd/ -type f -name '*.swap'
+ read -r UNIT_PATH
+ grep -q systemd-gpt-auto-generator /run/systemd/generator/dev-xvdc1.swap
+ read -r UNIT_PATH
+ INFO 'swapD: searching swap devices'
+ echo 'INFO: swapD: searching swap devices'
INFO: swapD: searching swap devices
+ mkdir -p /run/systemd/swap/swapd/
++ blkid -t TYPE=swap -o device
++ grep -vE '(zram|loop)'
+ for device in $(blkid -t TYPE=swap -o device | grep -vE '(zram|loop)')
++ swapon --show=NAME --noheadings
+ for used_device in $(swapon --show=NAME --noheadings)
+ '[' /dev/xvdc1 == /dev/xvdc1 ']'
+ unset device
+ '[' '!' -b '' ']'
+ continue
This appears to create swap files correctly BUT I do see the above error in the unit log. Is it safe to ignore this?
[root@kumo ~]# systemctl status systemd-swap
● systemd-swap.service - Manage swap spaces on zram, files and partitions.
Loaded: loaded (/usr/lib/systemd/system/systemd-swap.service; disabled; vendor preset: disabled)
Active: active (exited) since Tue 2019-01-01 20:10:34 PST; 1min 57s ago
Main PID: 23876 (code=exited, status=0/SUCCESS)
Tasks: 2 (limit: 3922)
Memory: 4.1M
CPU: 8.897s
CGroup: /system.slice/systemd-swap.service
├─23917 /bin/bash /usr/bin/systemd-swap start
└─24772 sleep 1s
Jan 01 20:10:34 kumo systemd-swap[23876]: INFO: Zswap: backup current configuration: complete
Jan 01 20:10:34 kumo systemd-swap[23876]: INFO: Zswap: set new parameters: start
Jan 01 20:10:34 kumo systemd-swap[23876]: INFO: Zswap: Enable: 1, Comp: lz4, Max pool %: 25, Zpool: zbud
Jan 01 20:10:34 kumo systemd-swap[23876]: INFO: Zswap: set new parameters: complete
Jan 01 20:10:34 kumo systemd-swap[23876]: INFO: swapD: pickup devices from systemd-gpt-auto-generator
Jan 01 20:10:34 kumo systemd-swap[23876]: INFO: swapD: searching swap devices
Jan 01 20:10:35 kumo systemd-swap[23876]: INFO: swapFC: free swap: 0 < 15 - allocate chunk: 1
Jan 01 20:10:35 kumo systemd-swap[23876]: chattr: Operation not supported while setting flags on /mnt/750gb/swapfc//1
Jan 01 20:10:46 kumo systemd-swap[23876]: mkswap: Label was truncated.
Jan 01 20:10:46 kumo systemd-swap[23876]: Setting up swapspace version 1, size = 512 MiB (536866816 bytes), LABEL=SWAP_ext2/ext3_, UUID=2b50d92e-5d4c-4c8c-9acc-76bcb59cb831
If you run the package.sh script multiple times, the following error occurs:
dpkg-deb: error: parsing file 'systemd-swap-2.27.2_any/DEBIAN/control' near line 10 package 'systemd-swap':
duplicate value for `Package' field
Change line 16:
echo "Package: systemd-swap" >> $DEB_NAME/DEBIAN/control
to
echo "Package: systemd-swap" > $DEB_NAME/DEBIAN/control
Result: the control file is newly created on each run.
Hello, Linux Manjaro, your script is in error, if I uncomment these two lines:
# $ {Sys [cpu_count]} #
# $ {Sys [ram_size]} # in KB
It gives error that the command does not exist:
[talesam@neit ~]$ systemctl status systemd-swap.service
● systemd-swap.service - Manage swap spaces on zram, files and partitions.
Loaded: loaded (/usr/lib/systemd/system/systemd-swap.service; enabled; vendor preset: disabled)
Active: active (exited) (Result: exit-code) since Sex 2016-05-13 02:31:28 BRT; 6s ago
Process: 2454 ExecStop=/usr/lib/systemd/scripts/systemd-swap.sh stop (code=exited, status=0/SUCCESS)
Process: 2465 ExecStart=/usr/lib/systemd/scripts/systemd-swap.sh start (code=exited, status=127)
Main PID: 2465 (code=exited, status=127)
Mai 13 02:31:28 neit systemd[1]: Started Manage swap spaces on zram, files and partitions..
Mai 13 02:31:28 neit systemd-swap.sh[2465]: /etc/systemd-swap.conf: line 12: 4: comando não encontrado
Mai 13 02:31:28 neit systemd[1]: systemd-swap.service: Main process exited, code=exited, status=127/n/a
I'm getting unstable results when trying to run "reset" in a zram + swap partition setup.
On my first startup, I get 8 zram devices as if running on my previous machine (I run my system in different machines). (This seems to be another request as #7 or maybe could be offered as a command line option, so we can override it using systemd unit snippets)
But when doing an "reset", my swap partition was not successfully enabled, occasionally (only ~30% success rate).
I got some error messages during the "reset" though:
swapon: /dev/sde1: swapon failed: Device or resource busy
I just started looking at the scripting for this cool little project and I noticed you used the following to determine the filesystem type:
get_fs_type(){ stat -f "$1" | grep Type: | tr -s ' ' | cut -d' ' -f7; }
This just happens to be something I looked into a while back and so it immedately jumped out at me as overly complicated. Stat is the right tool, but you can simply make use of the amazing formatting options it gives:
get_fs_type(){stat --file-system --format="%T" "$1"}
...or even shorter:
get_fs_type(){stat -fc "%T" "$1"}
It would be nice if you would tag a commit when making a release, so we know it's time for a new release :)
I've recently updated this package to version 3.4 and saw this error pop-up when checking the status of this service after restarting it.
Aug 21 23:43:24 Ideapad-310 systemd-swap[7901]: /run/systemd/swap/swap.conf: line 30: /4: syntax error: operand expected (error token is "/4")
After some checking, I found out the affecting line of code is as shown below. Should I be concern of the error above? I am currently not using the ZRam function but it is good to know if it will cause any problems.
Can you support *.conf
files in /usr/lib/systemd/swap.conf.d/
? Like other systemd components (coredump.conf
, journald.conf
, etc.). This would allow a package to ship a custom configuration outside of /etc
.
I have an issue on arch linux. The zramctl command flags for zramctl.
Here's modified section that worked for me
manage_zram(){
case $1 in
start)
[ -z ${zram[size]} ] && return 0
# if module not loaded create many zram devices for users needs
[ -f /dev/zram0 ] || modprobe zram num_devices=32
zram[alg]=${zram[alg]:-lz4}
zram[streams]=${zram[streams]:-${sys[cpu_count]}}
# zramctl is a external program -> return name of first free device
zram[dev]=$(zramctl find)
zramctl ${zram[dev]} ${zram[size]} ${zram[alg]} ${zram[streams]}
mkswap /dev/${zram[dev]}
swapon -p 32767 /dev/${zram[dev]}
write "${zram[dev]}" ${lock[zram]}
;;
stop)
# read info from zram lock file
for i in `cat ${lock[zram]}`; do
echo "swapoff /dev/$i"
swapoff /dev/$i
zramctl reset $i
done
rm ${lock[zram]}
;;
esac
}
Here is also help from zramctl:
# zramctl [15:45:11]
Usage: zramctl <name> <size <alg> <threads>
zramctl zram0 1024M lz4 4
zramctl find 1024M lz4 4
zramctl reset zram0 zram1 ...
zramctl status
lzo|lz4 # compress algorithm
*|{K|M|G} # size of zram disk
<name> # zram*|find|status
# if find, print and setup first free device
If you want I can do a pull request for that changes, but this issue seems is only on ArchLinux, because according to manpages your flags are ok.
UPD:
I've tried "long" flags for zramctl and all seems fine. So maybe usage of long flags could solve the problem.
having '-x' set is good for development but not so nice for daily usage.
i suggest removing -x and adding echos to relevant places to make the output more pleasant to human eye.
having to run "reset" on every change is counter-intuitive and leads to confusion.
afaik, there's no performance penalty involved when determining all the relevant data each time.
also, cached config is not "portable" (when using single image for multiple machines).
We must add some logic to understand the system and change our behaviour.
reading the recent change, is not clear at all why should I do those changes.
I'm talking about VM settings of swappiness and overcommit
with the same reason I'd like to better explain the Swap devices part: the little description is not clear...
When shutting down it often/always waits for systemd-swap to exit.
This seems to be caused by sleep $swapfc_frequency
in systemd-swap.
Does this serve any purpose?
It happens occasionally in latest version 2.27:
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: INFO: zswap[enabled]=N >> /run/.systemd-swap.zswap
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: INFO: zswap[compressor]=lzo >> /run/.systemd-swap.zswap
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: INFO: zswap[max_pool_percent]=20 >> /run/.systemd-swap.zswap
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: INFO: zswap[zpool]=zbud >> /run/.systemd-swap.zswap
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: mkswap: only one device argument is currently supported
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: Usage:
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: mkswap [options] device [size]
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: Set up a Linux swap area.
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: Options:
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: -c, --check check bad blocks before creating the swap area
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: -f, --force allow swap size area be larger than device
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: -p, --pagesize SIZE specify page size in bytes
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: -L, --label LABEL specify label
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: -v, --swapversion NUM specify swap-space version number
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: -U, --uuid UUID specify the uuid to use
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: -V, --version output version information and exit
May 13 10:08:26 flygon.felixc.at systemd-swap.sh[671]: -h, --help display this help and exit
Do you think you could upstream this to systemd?
Advantages:
I'm getting this behavior when enabling only zram (other scenarios not tested).
# systemctl start systemd-swap
(works correctly)
# systemctl stop systemd-swap
(below are pasted from journal)
May 21 11:40:00 felix-arch systemd[1]: Stopping Manage swap spaces on zram, files and partitions....
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + cached=/var/tmp/systemd-swap.lock
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + config=/etc/systemd-swap.conf
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + modfile=/etc/modprobe.d/90-systemd-swap.conf
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + '[' -f /var/tmp/systemd-swap.lock ']'
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + . /var/tmp/systemd-swap.lock
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: ++ swapf_path=(/var/swap)
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: ++ export cpu_count=8 zram_size=1702297 swapf_path
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: ++ cpu_count=8
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: ++ zram_size=1702297
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + case $1 in
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + start swapf
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + start zram
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + '[' -f /run/lock/systemd-swap.swapf ']'
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + '[' -f /run/lock/systemd-swap.zram ']'
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + deatach_zram
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + start dev
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + '[' -f /run/lock/systemd-swap.dev ']'
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: ++ cat /run/lock/systemd-swap.zram
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + for n in '`cat /run/lock/systemd-swap.zram`'
May 21 11:40:00 felix-arch systemd-swap.sh[8600]: + swapoff /dev/zram0
May 21 11:40:00 felix-arch systemd[1]: systemd-swap.service: control process exited, code=exited status=1
May 21 11:40:00 felix-arch systemd[1]: Stopped Manage swap spaces on zram, files and partitions..
May 21 11:40:00 felix-arch systemd[1]: Unit systemd-swap.service entered failed state.
And none of the zram swaps were closed.
But if I use
# /usr/lib/systemd/scripts/systemd-swap.sh start/stop
Then all works just fine (stop will clean up all zram devices successfully)
I want to run this on my Arch Linux laptop and other server but I have a couple of questions about the config.
At the top of the swap.conf file it mentions
# You can override any settings by files in:
# /etc/systemd/swap.conf.d/*.conf
Does the file name matter? i.e. /etc/systemd/swap.conf.d/settings.conf would work?
Does format matter? I only include the variables I want to override?
I ask because the ArchWiki here https://wiki.archlinux.org/index.php/Swap#systemd-swap
suggests to edit the swap.conf file directly but your own swap.conf suggests otherwise.
Since the upgrade from version 3.x to 4.x it is no longer possible for me to create a swapfile. Before I used swapFU for that pupose, but that is no longer supported. According to your Q&A I tried the swapFC-way and set swapfc_max_count to 1, but it fails to create the swapfile:
| Mär 12 19:00:05 t400 kernel: zswap: loaded using pool lzo/zbud
| Mär 12 19:00:18 t400 systemd[1]: Started Manage swap spaces on zram, files and partitions..
| Mär 12 19:00:19 t400 systemd-swap[440]: INFO: Load: /etc/systemd//swap.conf
| Mär 12 19:00:19 t400 systemd-swap[440]: INFO: Zswap: backup current configuration: start
| Mär 12 19:00:19 t400 systemd-swap[440]: INFO: Zswap: backup current configuration: complete
| Mär 12 19:00:19 t400 systemd-swap[440]: INFO: Zswap: set new parameters: start
| Mär 12 19:00:19 t400 systemd-swap[440]: INFO: Zswap: Enable: 1, Comp: lz4, Max pool %: 25, Zpool: zbud
| Mär 12 19:00:19 t400 systemd-swap[440]: INFO: Zswap: set new parameters: complete
| Mär 12 19:00:20 t400 systemd-swap[440]: INFO: swapD: pickup devices from systemd-gpt-auto-generator
| Mär 12 19:00:20 t400 systemd-swap[440]: INFO: swapD: searching swap devices
| Mär 12 19:00:21 t400 systemd-swap[440]: INFO: swapFC: free swap: 0 < 15 - allocate chunk: 1
| Mär 12 19:00:21 t400 systemd-swap[440]: chattr: Die Operation wird nicht unterstützt beim Setzen der Flags in /var/lib/systemd-swap/swapfc//1
| Mär 12 19:00:21 t400 systemd-swap[440]: fallocate: fallocate fehlgeschlagen: Die Operation wird nicht unterstützt
| Mär 12 19:00:21 t400 systemd-swap[440]: mkswap: Fehler: der Auslagerungsbereich muss mindestens 40 KiB groß sein
| Mär 12 19:00:21 t400 systemd[1]: Activating swap Swap File...
| Mär 12 19:00:21 t400 swapon[577]: swapon: /var/lib/systemd-swap/swapfc/1: Swap-Header konnte nicht gelesen werden
| Mär 12 19:00:21 t400 systemd[1]: var-lib-systemd\x2dswap-swapfc-1.swap: Swap process exited, code=exited status=255
| Mär 12 19:00:21 t400 systemd[1]: var-lib-systemd\x2dswap-swapfc-1.swap: Failed with result 'exit-code'.
| Mär 12 19:00:21 t400 systemd[1]: Failed to activate swap Swap File.
| Mär 12 19:00:21 t400 systemd-swap[440]: Job for var-lib-systemd\x2dswap-swapfc-1.swap failed.
| Mär 12 19:00:21 t400 systemd-swap[440]: See "systemctl status "var-lib-systemd\x2dswap-swapfc-1.swap"" and "journalctl -xe" for details.
The problem is probably the fallocate usage on a ext3-filesystem.
I am able to create a file "1" using dd, and then it works, but only one time, since the application delete the file while the services stopped, and then I run in the same problem on next start.
How can I get back the old behaviour, or at least prevent to delete a once created swapfile on exit, or how to use a alternate method like dd instead of fallocate?
Hi, I know about the concept of having a swap file/partition.
Looking at Archlinux' BTRFS page, I see it mentions this project can be used with a BTRFS linux for swap.
The readme mentions a number of terms, however, that I have no idea about:
It would be nice if these terms were defined in some sort of short reference table or listing (in the readme) since they seem currently important concepts for however this package implements swapping.
It would also be nice if there was any advice on when one might want to use this package over tools in util-linux
(at least for Arch), or visa versa.
The conf file has these lines on the top:
## !Run this commands:
## sudo /usr/lib/systemd/scripts/systemd-swap.sh reset
## sudo systemctl restart systemd-swap
But after some experiments, I found that they cannot be run in sequence, or the latter will make systemd-swap.service enter 'failed' state.
Actually it seems running either of the two commands, or replace "reset" with "stop" and "restart with "start" (optional) also works like a charm.
Perhaps "Run either of these commands" would be better if I understand it correctly.
Hi,
I'd like to understand if we need to have swapd_auto_swapon=1
even if swap are already mounted by systemd... I have the swap partition entry in the /etc/fstab file...
I have a Raspberry Pi and I'd like to set for multiple locations on my attached hard drives. For example, if drive A has space create swap there but move to the next drive with sufficient space, keep rotating until all locations for swap are full.
Tested on Debian testing and Ubuntu 16.04.4 LTS
# make install
mkdir -p //var/lib/systemd-swap
mkdir -p //etc/systemd/swap.conf.d/
install -Dm755 systemd-swap //usr/bin/systemd-swap
install -Dm644 systemd-swap.service //lib/systemd/system/systemd-swap.service
install -bDm644 -S swap.conf //etc/systemd/swap.conf
install: missing destination file operand after '//etc/systemd/swap.conf'
Try 'install --help' for more information.
Makefile:29: recipe for target '//etc/systemd/swap.conf' failed
make: *** [//etc/systemd/swap.conf] Error 1
Using swapfc and some processes that are high load on both CPU and RAM, the following situation arose:
Result: Memory corruption on running processes, including two virtual machines, their kernels then crashed.
Please see the host journal excerpt.
I configured swapfc with settings:
swapfc_enabled=1
swapfc_force_use_loop=0 # Force usage of swapfile + loop
swapfc_frequency=1s # How often check free swap space
swapfc_chunk_size=1024M # Allocate size of swap chunk
swapfc_max_count=32 # 0 - unlimited, note: 32 is a kernel maximum
swapfc_free_swap_perc=15 # Add new chunk if free < 15%
# Remove chunk if free > 15+40% & chunk count > 2
swapfc_path=/var/lib/systemd-swap/swapfc/
# Only for swapfile + loop
swapfc_nocow=1 # Disable CoW on swapfile
swapfc_directio=1 # Use directio for loop dev
swapfc_force_preallocated=0 # Will preallocate created files
Is this a problem of systemd-swap and/or could it be avoided?
I raised a bug in arch, but this may be easier here.
Here's the bug report:
Description:
Because the chunk generation is triggered by the swap falling below 15% (or whatever is configured in the config), a system with no other swap will always have 0% full, so the first chunks is never created. I worked around this by simply creating a small swap file (~10M), which is trivial from a swapping standpoint, but that way when it is <15% empty, the first chunk is generated. You could easily add a similar function to systemd-swap, to allocate a 10M swapfile, further, it could be a simple config option so folks with an actual swap partition could skip it.
A patch [1] was made to the zramctrl script, to make use of the "lz4" compression algorithm. I think it would be a good idea to make this configurable in systemd-swap as well.
Tried different configurations (swapfu or swapfc) with and without PREALLOC, always with same result.
When used some swap (~1GB) the system hangs on shutdown, needed to turnoff with power button.
If <256MB swap used, the system shutdown without issues, only when using some amount of swap.
Using swapfile the same doesn't happen.
I'm using btrfs
, so my swapfile needs to be loopback mounted.
Is there a way of having a persistent loopback /dev/<DEVICE>
so that I can pass resume=
in my kernel parameters and have it resume from the loopback device?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.