nefelim4ag / systemd-swap

Script for creating hybrid swap space from zram swaps, swap files and swap partitions.
GNU General Public License v3.0
546 stars 81 forks source link

No swapfile ! #172

Closed nam1962 closed 4 years ago

nam1962 commented 4 years ago

Hi, and thank you for this excellent script that improved all my installs.

I have an issue, I thought was similar to #165 ; I removed the s from swapfc_frequency, now systemd-swap seems to start:

$ 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 (running) since Tue 2020-08-04 17:50:40 CEST; 8min ago
   Main PID: 735 (bash)
     Status: "Monitoring memory status..."
      Tasks: 1 (limit: 14087)
     Memory: 4.9M
     CGroup: /system.slice/systemd-swap.service
             └─735 bash /usr/bin/systemd-swap start

août 04 17:50:40 ordi1 systemd-swap[735]: INFO: Load: /etc/systemd/swap.conf
août 04 17:50:40 ordi1 systemd[1]: Started Manage swap spaces on zram, files and partitions..
août 04 17:50:40 ordi1 systemd-swap[735]: INFO: Zswap: backup current configuration: start
août 04 17:50:41 ordi1 systemd-swap[735]: INFO: Zswap: backup current configuration: complete
août 04 17:50:41 ordi1 systemd-swap[735]: INFO: Zswap: set new parameters: start
août 04 17:50:41 ordi1 systemd-swap[735]: INFO: Zswap: Enable: 1, Comp: lz4,  Max pool %: 25, Zpool: zbud
août 04 17:50:41 ordi1 systemd-swap[735]: INFO: Zswap: set new parameters: complete
août 04 17:50:41 ordi1 systemd-swap[735]: INFO: swapD: pickup devices from systemd-gpt-auto-generator
août 04 17:50:41 ordi1 systemd-swap[735]: INFO: swapD: searching swap devices
août 04 17:50:42 ordi1 systemd-swap[735]: INFO: swapFC: on-demand swap activation at >7643 MiB memory usage

But in fact, no file seem to exist :

[me@ordi1 ~]$ swapon -s
[me@ordi1 ~]$ free
              total       utilisé      libre     partagé tamp/cache   disponible
Mem:          11758        1611        8858         234        1289        9646
Partition d'échange:           0           0           0

Here my .conf :

$ cat /etc/systemd/swap.conf
################################################################################
# Defaults are optimized for general usage
################################################################################

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

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

zswap_enabled=1
zswap_compressor=lz4      # lzo lz4
zswap_max_pool_percent=25 # 1-99
zswap_zpool=zbud          # zbud z3fold

################################################################################
# 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_streams=$NCPU
zram_alg=lz4                    # lzo lz4 deflate lz4hc 842 - for Linux 4.8.4
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 512M, Max 8*512M
swapfc_enabled=1
swapfc_force_use_loop=0     # Force usage of swapfile + loop
swapfc_frequency=1         # How often check free swap space
swapfc_chunk_size=512M      # Allocate size of swap chunk
swapfc_max_count=8          # 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

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

My install :

$ inxi -Fxxxz
System:    Host: ordi1 Kernel: 5.7.9-1-MANJARO x86_64 bits: 64 compiler: gcc v: 10.1.0 Desktop: Xfce 4.14.2 tk: Gtk 3.24.20 
           info: xfce4-panel, plank wm: xfwm4 dm: LightDM 1.30.0 Distro: Manjaro Linux 
Machine:   Type: Laptop System: ASUSTeK product: K53SD v: 1.0 serial: <filter> 
           Mobo: ASUSTeK model: K53SD v: 1.0 serial: <filter> UEFI: American Megatrends v: K53SD.208 date: 08/10/2012 
Battery:   ID-1: BAT0 charge: 17.3 Wh condition: 17.6/57.2 Wh (31%) volts: 12.4/11.1 model: ASUSTek K53--52 type: Li-ion 
           serial: <filter> status: Unknown 
CPU:       Topology: Dual Core model: Intel Core i3-2350M bits: 64 type: MT MCP arch: Sandy Bridge rev: 7 L2 cache: 3072 KiB 
           flags: avx lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx bogomips: 18367 
           Speed: 798 MHz min/max: 800/2300 MHz Core speeds (MHz): 1: 798 2: 798 3: 798 4: 798 
Graphics:  Device-1: Intel 2nd Generation Core Processor Family Integrated Graphics vendor: ASUSTeK driver: i915 v: kernel 
           bus ID: 00:02.0 chip ID: 8086:0116 
           Device-2: NVIDIA GF119M [GeForce 610M] vendor: ASUSTeK driver: nouveau v: kernel bus ID: 01:00.0 chip ID: 10de:1058 
           Display: x11 server: X.Org 1.20.8 driver: intel,nouveau unloaded: modesetting alternate: fbdev,nv,vesa 
           resolution: 1366x768~60Hz, 1680x1050~60Hz 
           OpenGL: renderer: Mesa DRI Intel HD Graphics 3000 (SNB GT2) v: 3.3 Mesa 20.1.3 compat-v: 3.0 direct render: Yes 
Audio:     Device-1: Intel 6 Series/C200 Series Family High Definition Audio vendor: ASUSTeK driver: snd_hda_intel v: kernel 
           bus ID: 00:1b.0 chip ID: 8086:1c20 
           Sound Server: ALSA v: k5.7.9-1-MANJARO 
Network:   Device-1: Intel Centrino Wireless-N 100 driver: iwlwifi v: kernel port: d000 bus ID: 03:00.0 chip ID: 8086:08ae 
           IF: wlp3s0 state: up mac: <filter> 
           Device-2: Qualcomm Atheros AR8151 v2.0 Gigabit Ethernet vendor: ASUSTeK driver: atl1c v: kernel port: 9000 
           bus ID: 05:00.0 chip ID: 1969:1083 
           IF: enp5s0 state: down mac: <filter> 
Drives:    Local Storage: total: 931.51 GiB used: 347.26 GiB (37.3%) 
           ID-1: /dev/sda vendor: Seagate model: ST1000LM024 HN-M101MBB size: 931.51 GiB speed: 3.0 Gb/s rotation: 5400 rpm 
           serial: <filter> rev: 0001 scheme: MBR 
Partition: ID-1: / size: 95.62 GiB used: 21.75 GiB (22.7%) fs: ext4 dev: /dev/sda2 
           ID-2: /home size: 819.53 GiB used: 325.51 GiB (39.7%) fs: ext4 dev: /dev/sda3 
Sensors:   System Temperatures: cpu: 58.0 C mobo: N/A gpu: nouveau temp: 58 C 
           Fan Speeds (RPM): cpu: 2500 
Info:      Processes: 206 Uptime: 16m Memory: 11.48 GiB used: 2.06 GiB (18.0%) Init: systemd v: 245 Compilers: gcc: 10.1.0 
           Shell: bash v: 5.0.18 running in: xfce4-terminal inxi: 3.0.37 

Thank you in advance for your advice !

vilgotf commented 4 years ago

You're using an old swap.conf file, I'd remove the file and then reinstall systemd-swap to get a new one (or copy the default one from /usr/share/systemd-swap/swap-default.conf).

As you can see in the log: août 04 17:50:42 ordi1 systemd-swap[735]: INFO: swapFC: on-demand swap activation at >7643 MiB memory usage swapFC will only create the first swapfile when atleast 7643MiB of RAM is used (cached or else), if you wish to create a swapfile at startup regardless you can set swapfc_min_count to 1.

nam1962 commented 4 years ago

Thank you for this efficient answer. I created the /etc/systemd/swap.conf.d directory, then the overrides.conf file and with swapfc personal settings I now get :

[me@ordi1 ~]$ 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 (running) since Tue 2020-08-04 19:46:57 CEST; 1h 11min ago
   Main PID: 6024 (bash)
     Status: "Monitoring memory status..."
      Tasks: 1 (limit: 14087)
     Memory: 266.3M
     CGroup: /system.slice/systemd-swap.service
             └─6024 bash /usr/bin/systemd-swap start

août 04 19:46:57 ordi1 systemd-swap[6024]: INFO: Load: /etc/systemd/swap.conf.d/overrides.conf
août 04 19:46:57 ordi1 systemd[1]: Started Manage swap spaces on zram, files and partitions..
août 04 19:46:57 ordi1 systemd-swap[6024]: INFO: Zswap: backup current configuration: start
août 04 19:46:57 ordi1 systemd-swap[6024]: INFO: Zswap: backup current configuration: complete
août 04 19:46:57 ordi1 systemd-swap[6024]: INFO: Zswap: set new parameters: start
août 04 19:46:57 ordi1 systemd-swap[6024]: INFO: Zswap: Enable: 1, Comp: zstd,  Max pool %: 25, Zpool: z3fold
août 04 19:46:57 ordi1 systemd-swap[6024]: INFO: Zswap: set new parameters: complete
août 04 19:46:57 ordi1 systemd-swap[6024]: INFO: swapD: pickup devices from systemd-gpt-auto-generator
août 04 19:46:57 ordi1 systemd-swap[6024]: INFO: swapD: searching swap devices
août 04 19:46:57 ordi1 systemd-swap[6024]: INFO: swapFC: allocate chunk:  1
[me@ordi1 ~]$ swapon -s
Nom de fichier              Type        Taille  Utilisé Priorité
/var/lib/systemd-swap/swapfc/1          file        262140  0   50
[me@ordi1 ~]$ free
              total       utilisé      libre     partagé tamp/cache   disponible
Mem:          11758        1629        8451         242        1677        9614
Partition d'échange:         255           0         255
[me@ordi1 ~]$ 

You might ask, why force a swapfile at startup ? It's for the newbees I do convert to Linux to visualize what happened ;)

Now, I'll have to amend my tuto : https://dolys.fr/forums/topic/optimiser-gestion-ram-swap-linux/

Bonus question : how could one be notified that the script improvements render the .conf obsolete ?

vilgotf commented 4 years ago

Your package manager should inform you with a .pacnew .rpmnew or something alike. Otherwise a new feature should bump the minor version (4.x).