<p>安装后 systemd-swap 失败。</p>

创建于 2020-10-26  ·  11评论  ·  资料来源: Nefelim4ag/systemd-swap

系统信息:

$ uname -ra
Linux ubuntu 5.4.0-1022-raspi #25-Ubuntu SMP PREEMPT Thu Oct 15 13:31:49 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux

$ neofetch
            .-/+oossssoo+/-.               ubuntu<strong i="6">@ubuntu</strong>
        `:+ssssssssssssssssss+:`           -------------
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 20.04.1 LTS aarch64
    .ossssssssssssssssssdMMMNysssso.       Host: Raspberry Pi 3 Model B Rev 1.2
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Kernel: 5.4.0-1022-raspi
  +ssssssssshmydMMMMMMMNddddyssssssss+     Uptime: 21 mins
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Packages: 2276 (dpkg), 4 (snap)
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Shell: zsh 5.8
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Terminal: /dev/pts/0
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   CPU: BCM2835 (4) @ 1.200GHz
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   Memory: 273MiB / 908MiB
+sssshhhyNMMNyssssssssssssyNMMMysssssss+
.ssssssssdMMMNhsssssssssshNMMMdssssssss.
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/
  +sssssssssdmydMMMMMMMMddddyssssssss+
   /ssssssssssshdmNNNNmyNMMMMhssssss/
    .ossssssssssssssssssdMMMNysssso.
      -+sssssssssssssssssyyyssss+-
        `:+ssssssssssssssssss+:`
            .-/+oossssoo+/-.

$ sudo systemctl status systemd-swap
● systemd-swap.service - Manage swap spaces on zram, files and partitions.
     Loaded: loaded (/lib/systemd/system/systemd-swap.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2020-10-26 14:44:11 IST; 1min 28s ago
    Process: 4422 ExecStart=/usr/bin/systemd-swap start (code=exited, status=1/FAILURE)
   Main PID: 4422 (code=exited, status=1/FAILURE)

Oct 26 14:44:09 ubuntu systemd[1]: Starting Manage swap spaces on zram, files and partitions....
Oct 26 14:44:11 ubuntu systemd-swap[4422]:   File "/usr/bin/systemd-swap", line 689
Oct 26 14:44:11 ubuntu systemd-swap[4422]:     continue
Oct 26 14:44:11 ubuntu systemd-swap[4422]:     ^
Oct 26 14:44:11 ubuntu systemd-swap[4422]: SyntaxError: 'continue' not properly in loop
Oct 26 14:44:11 ubuntu systemd[1]: systemd-swap.service: Main process exited, code=exited, status=1/FAILURE
Oct 26 14:44:11 ubuntu systemd[1]: systemd-swap.service: Failed with result 'exit-code'.
Oct 26 14:44:11 ubuntu systemd[1]: Failed to start Manage swap spaces on zram, files and partitions..

最有用的评论

好像你的 conf 文件是新的(顶部)和旧的(底部)的混合,我建议删除文件并重新安装包(重新安装 conf 文件)。

默认情况下,zram 和 swapfc 都是禁用的,因此您需要启用它们才能正常工作;)

所有11条评论

Ty 报告此事!

拉取新更改后,它按预期工作。 感谢您快速修复@vilgotf。

❯ sudo systemctl status systemd-swap.service
● systemd-swap.service - Manage swap spaces on zram, files and partitions.
     Loaded: loaded (/lib/systemd/system/systemd-swap.service; enabled; vendor preset: enabled)
     Active: active (exited) since Mon 2020-10-26 15:32:11 IST; 17s ago
    Process: 2976 ExecStart=/usr/bin/systemd-swap start (code=exited, status=0/SUCCESS)
   Main PID: 2976 (code=exited, status=0/SUCCESS)
     Status: "Swap unit activation finished"

Oct 26 15:32:10 ubuntu systemd-swap[2976]: INFO: Removing files in /var/lib/systemd-swap/swapfc/...
Oct 26 15:32:11 ubuntu systemd-swap[2976]: INFO: Zswap: backup current configuration: start
Oct 26 15:32:11 ubuntu systemd-swap[2976]: INFO: Zswap: backup current configuration: complete
Oct 26 15:32:11 ubuntu systemd-swap[2976]: INFO: Zswap: set new parameters: start
Oct 26 15:32:11 ubuntu systemd-swap[2976]: INFO: Zswap: Enable: 1, Comp: zstd, Max pool %: 25, Zpool: z3fold
Oct 26 15:32:11 ubuntu systemd-swap[2976]: INFO: Zswap: set new parameters: complete
Oct 26 15:32:11 ubuntu systemd-swap[2976]: INFO: Writing destroy info...
Oct 26 15:32:11 ubuntu systemd-swap[2976]: INFO: swapD: pick up devices from systemd-gpt-auto-generator
Oct 26 15:32:11 ubuntu systemd-swap[2976]: INFO: swapD: searching swap devices
Oct 26 15:32:11 ubuntu systemd[1]: Started Manage swap spaces on zram, files and partitions..

@vilgotf

❯ free -m
              total        used        free      shared  buff/cache   available
Mem:            908         355          21           9         530         534
Swap:             0           0           0
❯ sudo systemctl status systemd-swap.service
● systemd-swap.service - Manage swap spaces on zram, files and partitions.
     Loaded: loaded (/lib/systemd/system/systemd-swap.service; enabled; vendor preset: enabled)
     Active: active (exited) since Mon 2020-10-26 15:40:45 IST; 11min ago
    Process: 1841 ExecStart=/usr/bin/systemd-swap start (code=exited, status=0/SUCCESS)
   Main PID: 1841 (code=exited, status=0/SUCCESS)
     Status: "Swap unit activation finished"

Oct 26 15:40:44 ubuntu systemd-swap[1841]: INFO: Removing files in /var/lib/systemd-swap/swapfc/...
Oct 26 15:40:44 ubuntu systemd-swap[1841]: INFO: Zswap: backup current configuration: start
Oct 26 15:40:44 ubuntu systemd-swap[1841]: INFO: Zswap: backup current configuration: complete
Oct 26 15:40:44 ubuntu systemd-swap[1841]: INFO: Zswap: set new parameters: start
Oct 26 15:40:44 ubuntu systemd-swap[1841]: INFO: Zswap: Enable: 1, Comp: zstd, Max pool %: 25, Zpool: z3fold
Oct 26 15:40:44 ubuntu systemd-swap[1841]: INFO: Zswap: set new parameters: complete
Oct 26 15:40:44 ubuntu systemd-swap[1841]: INFO: Writing destroy info...
Oct 26 15:40:44 ubuntu systemd-swap[1841]: INFO: swapD: pick up devices from systemd-gpt-auto-generator
Oct 26 15:40:45 ubuntu systemd-swap[1841]: INFO: swapD: searching swap devices
Oct 26 15:40:45 ubuntu systemd[1]: Started Manage swap spaces on zram, files and partitions..
❯ zramctl
~ ❯                                                                                               

如果我使用 zram-tools 包,我可以毫无问题地启动和运行 zram。

systemd-swap status和您的配置文件的输出是什么?

我正在使用默认配置文件。

❯ sudo cat /etc/systemd/swap.conf
#  This file is part of systemd-swap.
#
# Entries in this file show the systemd-swap defaults as
# specified in /usr/share/systemd-swap/swap-default.conf
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See swap.conf(5) and /usr/share/systemd-swap/swap-default.conf for details.

#zswap_enabled=1
#zswap_compressor=zstd
#zswap_max_pool_percent=25
#zswap_zpool=z3fold
#zram_enabled=0
#zram_size=$(( RAM_SIZE / 4 ))
#zram_count=${NCPU}
#zram_streams=${NCPU}
#zram_alg=zstd
#zram_prio=32767
#swapfc_enabled=0
#swapfc_force_use_loop=0
#swapfc_frequency=1
#swapfc_chunk_size=256M
#swapfc_max_count=32
#swapfc_min_count=0
#swapfc_free_ram_perc=35
#swapfc_free_swap_perc=15
#swapfc_remove_free_swap_perc=55
#swapfc_priority=50
#swapfc_path=/var/lib/systemd-swap/swapfc/
#swapfc_nocow=1
#swapfc_directio=1
#swapfc_force_preallocated=0
#swapd_auto_swapon=1
#swapd_prio=1024


################################################################################
# Defaults are optimized for general usage
################################################################################

################################################################################
# You can override any settings with files in:
# /etc/systemd/swap.conf.d/*.conf
################################################################################

################################################################################
# Zswap
#
# Kernel >= 3.11
# Zswap create compress cache between swap and memory to reduce IO
# https://www.kernel.org/doc/Documentation/vm/zswap.txt

zswap_enabled=1
zswap_compressor=zstd     # lzo lz4 zstd lzo-rle lz4hc
zswap_max_pool_percent=25 # 1-99
zswap_zpool=z3fold        # zbud z3fold (note z3fold requires kernel 4.8+)

################################################################################
# ZRam
#
# Kernel >= 3.15
# Zram compression streams count for additional information see:
# https://www.kernel.org/doc/Documentation/blockdev/zram.txt

zram_enabled=0
zram_size=$(( RAM_SIZE / 4 ))    # This is 1/4 of ram size by default.
zram_count=${NCPU}               # Device count (only for kernels < 4.8)
zram_streams=${NCPU}             # Compress streams
zram_alg=zstd                    # See $zswap_compressor
zram_prio=32767                  # 1 - 32767

################################################################################
# Swap File Chunked
# Allocate swap files dynamically
# For btrfs fallback to swapfile + loop will be used
# ex. Min swap size 256M, Max 32*256M
swapfc_enabled=0
swapfc_force_use_loop=0          # Force usage of swapfile + loop
swapfc_frequency=1               # How often to check free swap space in seconds
swapfc_chunk_size=256M           # Size of swap chunk
swapfc_max_count=32              # Note: 32 is a kernel maximum
swapfc_min_count=0               # Minimum amount of chunks to preallocate
swapfc_free_ram_perc=35          # Add first chunk if free ram < 35%
swapfc_free_swap_perc=15         # Add new chunk if free swap < 15%
swapfc_remove_free_swap_perc=55  # Remove chunk if free swap > 55% && chunk count > 2
swapfc_priority=50               # Priority of swapfiles (decreasing by one for each swapfile).
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

################################################################################
# Swap devices
# Find and auto swapon all available swap devices
swapd_auto_swapon=1
swapd_prio=1024

❯ sudo systemd-swap status
.  compressor                 zstd
.  enabled                    Y
.  max_pool_percent           25
.  same_filled_pages_enabled  Y
.  zpool                      z3fold
Zswap:
.  .  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
.  .  same_filled_pages      0
.  .  stored_pages           0
.  .  written_back_pages     0
.  .  compress_ratio         0%
swapD:
~ ❯                                   

我的 fstab 看起来像这样。

❯ cat /etc/fstab
LABEL=writable  /        ext4   defaults        0 0
LABEL=system-boot       /boot/firmware  vfat    defaults        0       1
tmpfs   /var/log                tmpfs   size=200M,defaults,noatime,mode=0755 0 0
tmpfs   /var/cache/apt/archives tmpfs   size=500M,defaults,noexec,nosuid,nodev,mode=0755 0 0
#tmpfs   /var/spool/cups         tmpfs   size=100M,defaults,noatime,mode=0755 0 0
#tmpfs   /var/spool/cups/tmp     tmpfs   defaults,noatime,mode=0755 0 0

好像你的 conf 文件是新的(顶部)和旧的(底部)的混合,我建议删除文件并重新安装包(重新安装 conf 文件)。

默认情况下,zram 和 swapfc 都是禁用的,因此您需要启用它们才能正常工作;)

因为systemd-swap status的输出没有提到 zram 和 swapfc 意味着它们被禁用

哦好的,知道了。

好的现在工作!

❯ sudo systemctl status systemd-swap.service
● systemd-swap.service - Manage swap spaces on zram, files and partitions.
     Loaded: loaded (/lib/systemd/system/systemd-swap.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2020-10-26 16:09:13 IST; 40s ago
   Main PID: 2771 (systemd-swap)
     Status: "Monitoring memory status..."
      Tasks: 1 (limit: 974)
     CGroup: /system.slice/systemd-swap.service
             └─2771 /usr/bin/python3 -u /usr/bin/systemd-swap start

Oct 26 16:09:07 ubuntu systemd-swap[2771]: INFO: Zram: not part of kernel, trying to find zram module
Oct 26 16:09:07 ubuntu systemd-swap[2771]: INFO: Zram: module successfully loaded
Oct 26 16:09:10 ubuntu systemd-swap[2771]: INFO: Zram: trying to initialize free device
Oct 26 16:09:10 ubuntu systemd-swap[2771]: INFO: Zram: initialized: /dev/zram0
Oct 26 16:09:13 ubuntu systemd-swap[2771]: INFO: Writing destroy info...
Oct 26 16:09:13 ubuntu systemd-swap[2771]: INFO: swapD: pick up devices from systemd-gpt-auto-generator
Oct 26 16:09:13 ubuntu systemd-swap[2771]: INFO: swapD: searching swap devices
Oct 26 16:09:13 ubuntu systemd-swap[2771]: INFO: swapFC: on-demand swap activation at >590 MiB memory usage
Oct 26 16:09:13 ubuntu systemd[1]: Started Manage swap spaces on zram, files and partitions..
Oct 26 16:09:14 ubuntu systemd-swap[2771]: INFO: swapFC: free ram: 3 < 35 - allocate chunk:  1
❯ zramctl
NAME       ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 zstd        227.1M   4K   57B    4K       4 [SWAP]
❯ free -m
              total        used        free      shared  buff/cache   available
Mem:            908         369          22           7         515         509
Swap:           483          15         467

我的配置

❯ sudo cat /etc/systemd/swap.conf
#  This file is part of systemd-swap.
#
# Entries in this file show the systemd-swap defaults as
# specified in /usr/share/systemd-swap/swap-default.conf
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See swap.conf(5) and /usr/share/systemd-swap/swap-default.conf for details.

zswap_enabled=1
zswap_compressor=zstd
zswap_max_pool_percent=25
zswap_zpool=z3fold
zram_enabled=1
zram_size=$(( RAM_SIZE / 4 ))
zram_count=${NCPU}
zram_streams=${NCPU}
zram_alg=zstd
zram_prio=32767
swapfc_enabled=1
swapfc_force_use_loop=0
swapfc_frequency=1
swapfc_chunk_size=256M
swapfc_max_count=32
swapfc_min_count=0
swapfc_free_ram_perc=35
swapfc_free_swap_perc=15
swapfc_remove_free_swap_perc=55
swapfc_priority=50
swapfc_path=/var/lib/systemd-swap/swapfc/
swapfc_nocow=1
#swapfc_directio=1
#swapfc_force_preallocated=0
swapd_auto_swapon=1
swapd_prio=1024
此页面是否有帮助?
0 / 5 - 0 等级