configure-swap: Always use dd and limit swap size to 1024MB

A recent kernel update in Fedora has highlighted that fallocate produced
swap files on ext4 partions are no longer accepted by swapon:

swapon failed if the swap file is created by fallocate in ext4 partition
https://bugzilla.redhat.com/show_bug.cgi?id=1827115

This change assumes that all distros will eventually encounter this and
removes the fallocate task from the role and defaults to using dd. As
this is considerably slower the overall size of the swap file is reduced
to 1024MB.

Change-Id: I5ce9064a5546d85ab6f41c4e60aa56fa56ff47c1
This commit is contained in:
Lee Yarwood
2020-09-10 10:50:44 +01:00
parent 24d196ec35
commit 45f555fdf0
2 changed files with 2 additions and 11 deletions

View File

@@ -1,2 +1,2 @@
# Default swap partition/file size, in MiB
configure_swap_size: 8192
configure_swap_size: 1024

View File

@@ -20,21 +20,12 @@
# Note, we don't use a sparse device to avoid wedging when disk space
# and memory are both unavailable.
# Cannot fallocate on filesystems like XFS, so use slower dd
- name: Create swap backing file for non-EXT fs
when: '"ext" not in root_filesystem'
- name: Create swap backing file
become: yes
command: dd if=/dev/zero of=/root/swapfile bs=1M count={{ swap_required }}
args:
creates: /root/swapfile
- name: Create sparse swap backing file for EXT fs
when: '"ext" in root_filesystem'
become: yes
command: fallocate -l {{ swap_required }}M /root/swapfile
args:
creates: /root/swapfile
- name: Ensure swapfile perms
become: yes
file: