Systemd-swap: Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself

Created on 14 Jun 2020  ·  31Comments  ·  Source: Nefelim4ag/systemd-swap

It seems to be caused by 52a468aeea9e00f3f1763e96a05adbe48b0a644d but I didn't bisect. Could it be caused by recent security changes?

/run/systemd/system/var-lib-systemd\x2dswap-swapfc-1.swap:11: Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: -2

Most helpful comment

Ahhh, never mind. I can reproduce this, it's just not logged by systemd-swap but by systemd

All 31 comments

Can you say your linux version (if arch whether zen or normal), distro and filesystem?

(this doesn't happen to me running arch zen 5.7 and f2fs)

ArchLinux 5.7.2 with zen modifications and ext4.

Is the swap file created? (that is, is this just a warning?)

I rebooted :/ Is there a way to quickly fill ram to a specific percentage to trigger the swapping?

You can use stress-ng stress-ng --vm-bytes $(awk '/MemAvailable/{printf "%d\n", $2 * 0.90;}' < /proc/meminfo)k --vm-keep -m 1 (allocates up to 90% of memory).

Another way to fix this issue is to set swapfc_priority=100 or something in /etc/systemd/swap.conf.d/overrides.conf

Ok yup, can still reproduce.
The swap file is still created.
Even though I guess I can fix it by assigning > -1 is this warning normal? If it's the case then it makes no sense to use this default and instead use 0 I guess.

Something weird I notice while testing with stress-ng is that when I use * 0.50 the 1GB swap chunk I configured is indeed created but when I change it to * 0.90 no more swap is added despite having 700MB free memory.

my config:

swapfc_enabled=1
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=1G           # 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_swap_perc=25         # Add new chunk if free < 15%
swapfc_remove_free_swap_perc=55  # Remove chunk if free > 55% && chunk count > 2

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+)

The second swap file is only created when the first one is running low on memory

Ah ok. And why is it not swapping then? I only see 32MB used.

You'll have to ask Linus Torvalds about that one ^^, in short swap is only used when more memory is asked for, so if no application is asking for more memory, you won't see swap being used.
You can tune the swap parameters yourself (swappiness etcetera), but note that the defaults of systemd-swap are tuned for default settings.

Ah I see thanks for the nice explanation :+1:
What do we do about the initial 'problem' ?

I'll see about reproducing it myself in a vm and and if we can quiet the warning (using 2>/dev/null on our swapon command). Since this only produces a warning I won't queue it up for a new release immediately but I'll bundle it with other fixes/updates.

So the warning is wrong and we can create swap with -2 ?

I did cat /proc/swaps and it seems to say it indeed has a -2 priority:

Filename                Type        Size    Used    Priority
/var/lib/systemd-swap/swapfc/1          file        1048572 33024   -2

So maybe it's an upstream bug and needs to be reported?

Ehh, the kernel says that only it can create priorities lower than -1 and that seems to be true (according to the documentation that I've read), it's more a bug with f2fs or something that makes to so that I can't see that warning....
The reasoning for systemd-swap defaulting to -2 is that is the way it's always been configured and I don't wish to break peoples setups.

Alright I see, thanks. I'll let this open until you can reproduce and silence it I guess.

Unable to reproduce on fedora & arch. Can you provide additional information?

Can still reproduce with your latest commits.
What kind of other information do you need ?

I don't know, but I can't really diagnose without being able to reproduce. And since this is only reported by you, I get the feeling that there might be something on your end causing this.

  • My swapfc path is /var/lib/systemd-swap/swapfc/
  • Mount options of the drive: rw,noatime,lazytime
  • Systemd 245.6

My current systemd-swap config:

################################################################################
# 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
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=1
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=1G           # 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_swap_perc=25         # Add new chunk if free < 15%
swapfc_remove_free_swap_perc=55  # Remove chunk if free > 55% && chunk count > 2
swapfc_priority=0               # Priority of swapfiles (decreasing by one for each swapfile). Jumps from 0 to -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

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

Ahhh, never mind. I can reproduce this, it's just not logged by systemd-swap but by systemd

Is there a Solution? - get this on Manjaro testing Branch
Jun 25 10:20:55 Workstation systemd[1]: /run/systemd/system/var-lib-systemd\x2dswap-swapfc-1.swap:11: Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: -2
Jun 25 10:20:56 Workstation systemd[1]: Failed to activate swap Swap File.

on systemd 245.6-3 no issue

Is there a Solution? - get this on Manjaro testing Branch
Jun 25 10:20:55 Workstation systemd[1]: /run/systemd/system/var-lib-systemd\x2dswap-swapfc-1.swap:11: Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: -2
Jun 25 10:20:56 Workstation systemd[1]: Failed to activate swap Swap File.

on systemd 245.6-3 no issue

Yes you can set the priority to something like 100

Is there a Solution? - get this on Manjaro testing Branch
Jun 25 10:20:55 Workstation systemd[1]: /run/systemd/system/var-lib-systemd\x2dswap-swapfc-1.swap:11: Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: -2
Jun 25 10:20:56 Workstation systemd[1]: Failed to activate swap Swap File.
on systemd 245.6-3 no issue

Yes you can set the priority to something like 100

Doesn't fix my issue:
grafik

Oh, I misread you comment. The priority never causes a swap file to fail, it just warns, so your issue is unrelated.
Please open a new issue for this

I don't know when it started happening again but I'm on latest master, arch kernel with zen modifs(linux-tkg) at 5.9.7 and I still reproduce this issue except it's even worse because it keeps increasing the priority:

/var-lib-systemd\x2dswap-swapfc-3.swap:11: Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: -474

Here is my current free -hm :

              total        used        free      shared  buff/cache   available
Mem:           15Gi       4,2Gi       907Mi       668Mi        10Gi       9,2Gi
Swap:         4,0Gi       2,3Gi       1,7Gi

And here is the config I use (no change to /etc/systemd/swap.conf, using a drop-in fil:

################################################################################
# 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
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=1
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=2G           # Size of swap chunk
swapfc_max_count=16              # Note: 32 is a kernel maximum
swapfc_min_count=0               # Minimum amount of chunks to preallocate
swapfc_free_swap_perc=50         # Add new chunk if free < 50%
swapfc_remove_free_swap_perc=55  # Remove chunk if free > 55% && chunk count > 2
#swapfc_priority=0               # Priority of swapfiles (decreasing by one for each swapfile). Jumps from 0 to -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

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

Here is systemd-swap journal log (minus the systemd swap priority errors)
systemd-swap-log.txt

@vilgotf

This is a configuration error on your end (although checks should be made for this).

The issue with your configuration is that a new swap file is created since you use use more than 50% of your swap. This works okay on few swap files but when the next swap file is allocated, the amount of free swap is now larger than 55% so it instantly tries to remove the swap file, then (because we've removed the swap file), the amount of free swap is less than 50% so it tries to create a new swap file (ad infinitum)

Lower the swapfc_free_swap_perc value (recommended, 15 is the default for a reason) or increase the swapfc_remove_free_swap_perc value.

That's it, thanks! Yeah I was trying to play with the values because the new swap file wasn't coming soon enough and the memory killer was getting triggered.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TeslaBargain picture TeslaBargain  ·  7Comments

adrelanos picture adrelanos  ·  3Comments

pheiduck picture pheiduck  ·  16Comments

dou4cc picture dou4cc  ·  7Comments

switchpants picture switchpants  ·  16Comments