Is Installing a Swapfile ok?

Hello again,
When installing Manjaro XFCE I chose to create a swap file. That was an option over a partition. I’m now asking whether this is enough for my notebook or what I should do better next time or just now?

swapon
NAME      TYPE SIZE USED PRIO
/swapfile file 512M   0B   -2

My notebook:

~]$ LC_ALL=C inxi --full --admin --filter --width
System:
  Kernel: 6.6.8-2-MANJARO arch: x86_64 bits: 64 compiler: gcc v: 13.2.1
    clocksource: tsc available: acpi_pm
    parameters: BOOT_IMAGE=/boot/vmlinuz-6.6-x86_64
    root=UUID=d8ff5d2f-cd13-4534-b598-7ae3f9f4950e rw quiet splash apparmor=1
    security=apparmor udev.log_priority=3
  Desktop: Xfce v: 4.18.1 tk: Gtk v: 3.24.36 info: xfce4-panel, plank
    wm: xfwm v: 4.18.0 vt: 7 dm: LightDM v: 1.32.0 Distro: Manjaro Linux
    base: Arch Linux
Machine:
  Type: Laptop System: LENOVO product: 20KGS9SA0J v: ThinkPad X1 Carbon 6th
    serial: <superuser required> Chassis: type: 10 serial: <superuser required>
  Mobo: LENOVO model: 20KGS9SA0J serial: <superuser required> UEFI: LENOVO
    v: N23ET83W (1.58 ) date: 09/28/2022
Battery:
  ID-1: BAT0 charge: 50.2 Wh (96.5%) condition: 52.0/56.2 Wh (92.5%)
    volts: 12.8 min: 11.6 model: LGC 01AV430 type: Li-poly serial: <filter>
    status: not charging cycles: 2
CPU:
  Info: model: Intel Core i7-8650U bits: 64 type: MT MCP arch: Coffee Lake
    gen: core 8 level: v3 note: check built: 2017 process: Intel 14nm family: 6
    model-id: 0x8E (142) stepping: 0xA (10) microcode: 0xF4
  Topology: cpus: 1x cores: 4 tpc: 2 threads: 8 smt: enabled cache:
    L1: 256 KiB desc: d-4x32 KiB; i-4x32 KiB L2: 1024 KiB desc: 4x256 KiB
    L3: 8 MiB desc: 1x8 MiB
  Speed (MHz): avg: 647 high: 800 min/max: 400/4200 scaling:
    driver: intel_pstate governor: powersave cores: 1: 800 2: 800 3: 782 4: 800
    5: 400 6: 400 7: 800 8: 400 bogomips: 33615
  Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
  Vulnerabilities:
  Type: gather_data_sampling mitigation: Microcode
  Type: itlb_multihit status: KVM: VMX disabled
  Type: l1tf mitigation: PTE Inversion; VMX: conditional cache flushes, SMT
    vulnerable
  Type: mds mitigation: Clear CPU buffers; SMT vulnerable
  Type: meltdown mitigation: PTI
  Type: mmio_stale_data mitigation: Clear CPU buffers; SMT vulnerable
  Type: retbleed mitigation: IBRS
  Type: spec_rstack_overflow status: Not affected
  Type: spec_store_bypass mitigation: Speculative Store Bypass disabled via
    prctl
  Type: spectre_v1 mitigation: usercopy/swapgs barriers and __user pointer
    sanitization
  Type: spectre_v2 mitigation: IBRS, IBPB: conditional, STIBP: conditional,
    RSB filling, PBRSB-eIBRS: Not affected
  Type: srbds mitigation: Microcode
  Type: tsx_async_abort mitigation: TSX disabled
Graphics:
  Device-1: Intel UHD Graphics 620 vendor: Lenovo driver: i915 v: kernel
    arch: Gen-9.5 process: Intel 14nm built: 2016-20 ports:
    active: DP-2,DP-4,eDP-1 empty: DP-1, DP-5, DP-6, HDMI-A-1, HDMI-A-2
    bus-ID: 00:02.0 chip-ID: 8086:5917 class-ID: 0300
  Device-2: Chicony Integrated IR Camera driver: uvcvideo type: USB rev: 2.0
    speed: 480 Mb/s lanes: 1 mode: 2.0 bus-ID: 1-5:4 chip-ID: 04f2:b615
    class-ID: 0e02
  Device-3: Chicony Integrated Camera driver: uvcvideo type: USB rev: 2.0
    speed: 480 Mb/s lanes: 1 mode: 2.0 bus-ID: 1-8:7 chip-ID: 04f2:b614
    class-ID: 0e02
  Display: x11 server: X.org v: 1.21.1.10 compositor: xfwm v: 4.18.0 driver:
    X: loaded: modesetting alternate: fbdev,vesa dri: iris gpu: i915
    display-ID: :0.0 note: <missing: xdpyinfo/xrandr>
  Monitor-1: DP-2 model: BenQ GW2760 serial: <filter> built: 2013
    res: 1920x1080 dpi: 82 gamma: 1.2 size: 598x336mm (23.54x13.23")
    diag: 686mm (27") ratio: 16:9 modes: max: 1920x1080 min: 720x400
  Monitor-2: DP-4 model: BenQ GL2760 serial: <filter> built: 2017
    res: 1920x1080 dpi: 82 gamma: 1.2 size: 598x336mm (23.54x13.23")
    diag: 686mm (27") ratio: 16:9 modes: max: 1920x1080 min: 720x400
  Monitor-3: eDP-1 model: AU Optronics 0x233d built: 2017 res: 1920x1080
    dpi: 158 gamma: 1.2 size: 309x174mm (12.17x6.85") diag: 355mm (14")
    ratio: 16:9 modes: 1920x1080
  API: EGL v: 1.5 hw: drv: intel iris platforms: device: 0 drv: iris
    device: 1 drv: swrast surfaceless: drv: iris x11: drv: iris
    inactive: gbm,wayland
  API: OpenGL v: 4.6 compat-v: 4.5 vendor: intel mesa v: 23.1.9-manjaro1.1
    glx-v: 1.4 direct-render: yes renderer: Mesa Intel UHD Graphics 620 (KBL GT2)
    device-ID: 8086:5917 memory: 15.14 GiB unified: yes
Audio:
  Device-1: Intel Sunrise Point-LP HD Audio vendor: Lenovo
    driver: snd_hda_intel v: kernel alternate: snd_soc_skl,snd_soc_avs
    bus-ID: 00:1f.3 chip-ID: 8086:9d71 class-ID: 0403
  Device-2: GN Netcom Jabra SPEAK 410 driver: jabra,snd-usb-audio,usbhid
    type: USB rev: 2.0 speed: 12 Mb/s lanes: 1 mode: 1.1 bus-ID: 1-4.2.1:19
    chip-ID: 0b0e:0410 class-ID: 0300 serial: <filter>
  Device-3: Lenovo ThinkPad Dock USB Audio
    driver: hid-generic,snd-usb-audio,usbhid type: USB rev: 2.0 speed: 480 Mb/s
    lanes: 1 mode: 2.0 bus-ID: 1-4.2.4:22 chip-ID: 17ef:306f class-ID: 0300
  API: ALSA v: k6.6.8-2-MANJARO status: kernel-api with: aoss
    type: oss-emulator tools: alsactl,alsamixer,amixer
  Server-1: JACK v: 1.9.22 status: off tools: N/A
  Server-2: PipeWire v: 1.0.0 status: active with: 1: pipewire-pulse
    status: active 2: wireplumber status: active 3: pipewire-alsa type: plugin
    tools: pactl,pw-cat,pw-cli,wpctl
Network:
  Device-1: Intel Ethernet I219-LM vendor: Lenovo driver: e1000e v: kernel
    port: N/A bus-ID: 00:1f.6 chip-ID: 8086:15d7 class-ID: 0200
  IF: enp0s31f6 state: up speed: 10 Mbps duplex: full mac: <filter>
  Device-2: Intel Wireless 8265 / 8275 driver: iwlwifi v: kernel pcie: gen: 1
    speed: 2.5 GT/s lanes: 1 bus-ID: 02:00.0 chip-ID: 8086:24fd class-ID: 0280
  IF: wlp2s0 state: down mac: <filter>
Bluetooth:
  Device-1: Intel Bluetooth wireless interface driver: btusb v: 0.8 type: USB
    rev: 2.0 speed: 12 Mb/s lanes: 1 mode: 1.1 bus-ID: 1-7:5 chip-ID: 8087:0a2b
    class-ID: e001
  Report: rfkill ID: hci0 rfk-id: 2 state: up address: see --recommends
Drives:
  Local Storage: total: 238.47 GiB used: 287.4 GiB (120.5%)
  SMART Message: Required tool smartctl not installed. Check --recommends
  ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Lenovo
    model: LENSE30256GMSP34MEAT3TA size: 238.47 GiB block-size: physical: 512 B
    logical: 512 B speed: 31.6 Gb/s lanes: 4 tech: SSD serial: <filter>
    fw-rev: 2.5.0412 temp: 43.9 C scheme: GPT
Partition:
  ID-1: / raw-size: 238.17 GiB size: 233.38 GiB (97.99%)
    used: 42.86 GiB (18.4%) fs: ext4 dev: /dev/nvme0n1p2 maj-min: 259:2
  ID-2: /boot/efi raw-size: 300 MiB size: 299.4 MiB (99.80%)
    used: 296 KiB (0.1%) fs: vfat dev: /dev/nvme0n1p1 maj-min: 259:1
Swap:
  Kernel: swappiness: 60 (default) cache-pressure: 100 (default) zswap: yes
    compressor: zstd max-pool: 20%
  ID-1: swap-1 type: file size: 512 MiB used: 0 KiB (0.0%) priority: -2
    file: /swapfile
Sensors:
  System Temperatures: cpu: 47.0 C pch: 51.5 C mobo: N/A
  Fan Speeds (rpm): fan-1: 0
Info:
  Processes: 268 Uptime: 2h 2m wakeups: 0 Memory: total: 16 GiB
  available: 15.5 GiB used: 3.08 GiB (19.9%) Init: systemd v: 254
  default: graphical tool: systemctl Compilers: gcc: 13.2.1 clang: 16.0.6
  Packages: 1244 pm: pacman pkgs: 1238 libs: 381 tools: octopi,pamac,yay
  pm: flatpak pkgs: 6 Shell: Bash v: 5.2.21 running-in: xfce4-terminal
  inxi: 3.3.31

Hi again @Tut_tut

How much RAM do you have?

OK, I see it’s 16 GiB. Thanks for posting the info.

A SWAP partition of at least 16GiB (and a bit more, if possible), will be sufficient to allow for hibernation, and most other needs.

If you plan on adding more RAM in the the near future, you might also want to allow for that as well.

I notice you’re using zswap as suggested by @cscs in another thread. I only mention this in case it’s relevant to others reading along.

To switch to using an adequately sized SWAP partition would require resizing the root (/) partition to create the extra space needed. This can (potentially) be a cumbersome task, sometimes with unexpected difficulties.

Although this would ultimately be more performant, the easiest for you is probably to reconfigure the size of the swap file using zswap. Were you given any reference information for that?

I hope this helps.

Prost!

A swap partition is faster than a swap file.
You have 16GB RAM and should add 16GB swap.

1 Like

Thank you!
I did read here but I didn´t understand all: swap.
Should I reinstall Manjaro to create a 16GB swap partition? Or is that not absolutely necessary? I don’t actually have any programs running in standby mode, I don’t think.

Yes, given the situation, a fresh install allowing a 16Gib (maybe 17Gib), would be the easiest for a performant swap partition. :slight_smile:
Increasing the swap file would probably be easier still, but my opinion is a full swap partition will be better.

Ultimately it’s up to you.

Whether you use a swap partition or a swap file, it still must be able to accommodate whatever data is in RAM, if hibernation is desired at any time.

Oh dear! I’ve now spent three days learning and setting up the system and now I’m doing it all over again! :joy:

Arguably there is very little upside to running a swap file if you are using nvme drives. See:

https://askubuntu.com/questions/652337/why-are-swap-partitions-discouraged-on-ssd-drives-are-they-harmful

Personally, I do not use swap files/ partitions on machines with modern ssd/ nvmes. I have seen no problems. When I use swap is with older devices for speed boost.

Basically it boils down to your use-case.

1 Like

While I agree in essence, your reasoning is flawed.

If one wishes to hibernate a system, whatever is in RAM must be written to disk – to the swap partition (or file). Therefore there must be sufficient swap space for that to occur.

If you don’t care about hibernation then you should just use zram and be done with it. Also there is nothing wrong with swap file.

1 Like

@Tut_tut

Create a new Swap File

OK. I’ve written this procedure for you to follow; simple copy/paste instructions. This should create the new swap file needed.

Note: Some of these commands may take a while to complete, so try not to cancel them prematurely.

  1. Remove the existing swap file:
sudo swapoff /swapfile
sudo rm -f /swapfile
  1. Create and initialize a new 16 GiB swap file:
  • The formula to calculate the count= value is 1024 x RAM;
    Example: 1024 x 16 = 16384.
sudo dd if=/dev/zero of=/swapfile bs=1M count=16384 status=progress
  • OR a 20 GiB swap file, instead:
sudo dd if=/dev/zero of=/swapfile bs=1M count=20480 status=progress
  1. Set permissions and format the swap file:
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
  1. Add a reference to the swap file in /etc/fstab:
  • First check if the swap file line exists;
  • If it does, then skip to Step 5:
cat /etc/fstab
  • If it’s not there, add it with:
sudo bash -c "echo /swapfile none swap defaults 0 0 >> /etc/fstab"
  1. Reboot

Done.

I hope this helps. Cheers.

1 Like

The good thing of having a swap file instead of a swap partition is that you can always easily adapt it’s size to your needs.

@soundofthunder gave you step by step instructions to get to a larger one

But you don’t really need to do this unless you want to set up hibernation or are otherwise sure that your current 512 MB swap file is not big enough.

If I where you, I’d opt for a swap file as big as my RAM.
But with the size of solid state drives, that much swap seems like a waste of disk space.

I have got 8 GB of RAM, 4 GB of swap (file)
Swap rarely gets used with what I do and hibernation works just fine with this size
even though it is only half the recommended size.

Systems on nvme solid state drives are booting so fast that hibernation isn’t really needed.

I still have a rotating disk. Plenty of space (1TB) - but speed matters here and does make a difference.

The argument is sound, up to the point when you have 5-6 GB ISO file, or Video file being edited (or, whatever) that happens to be in RAM when you decide to hibernate the machine…

Oops! :scream_cat:

I don’t hibernate, either. I have 64GiB RAM and a 32GiB swap partition, but I carefully calculated and anticipated my needs beforehand.

I’ll add this here for the OP to find, if he also has no desire to use hibernation, and wishes a smaller swap file:

sudo dd if=/dev/zero of=/swapfile bs=1M count=8192 status=progress

This command creates only an 8GiB swap file (and replaces the respective command in my previous instructions (if needed).

… I know.

And that’s the point.
I know. You know. But he doesn’t.

… and I did not intend to persuade him to do as I did

Apparently I never tried to hibernate with too much of my RAM being used so that it would fail.
I don’t know what would happen then - probably an fsck on the next reboot and perhaps some of the more recent changes lost due to it.

To be very honest - there is not that much (time) difference between coming out of hibernation and a clean boot - the reading back of 4 GB from swap takes it’s sweet time.

I appreciate you taking the time and effort to guide him to change what he has got now.
Very nice of you!

I already like this forum! You are really nice and knowledgeable helpers! I now have a 16 GB swap file using the instructions written especially for me! Many many thanks! :pray:

LC_ALL=C cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a device; this may
# be used with UUID= as a more robust way to name devices that works even if
# disks are added and removed. See fstab(5).
#
# <file system>             <mount point>  <type>  <options>  <dump>  <pass>
UUID=22F4-54A6                            /boot/efi      vfat    umask=0077 0 2
UUID=d8ff5d2f-cd13-4534-b598-7ae3f9f4950e /              ext4    defaults,noatime 0 1
/swapfile                                 swap           swap    defaults,noatime 0 0
tmpfs                                     /tmp           tmpfs   defaults,noatime,mode=1777 0 0
1 Like

You’re very welcome.
Don’t forget to tick my post (the one with the instructions). :slight_smile:

Yes, it’s OK to install a swap file but it feels old-school to me

I don’t understand why people don’t use zram instead, it’s more dynamic and costs less hdd space.

    Install zram-generator using one of the methods listed above.
    Create a zram-generator.conf config file.
    Run systemctl daemon-reload to create new device units.
    Run systemctl start /dev/zram0 (adjust the name as appropriate to match the config).
    Call zramctl or swapon to confirm that the device has been created and is in use.

Once installed and configured, the generator will be invoked by systemd early at boot, there is no need to do anything else.

source: GitHub - systemd/zram-generator: Systemd unit generator for zram devices

other sources:

https://wiki.archlinux.org/title/Zram

I want hibernation - can’t be done with dynamic swap files/zram. :man_shrugging:

It’s probably good for the OP though …

Did I ?
Usually I suggest zram which should be coupled with disabling zswap, as the two together creates problems.

ex:

Continuing the discussion from Extremely weird issue involving RTX 3060:

If you decide to use zram instead of a swap file & don’t want to have to fiddle around with a configuration file (as required with zram-generator), then a good alternative in the AUR is systemd-zram (and there are plenty of other zram enablers available in the AUR repository too). I recently installed systemd-zram with its default settings (lzo compression, cache size 75% of RAM size) & it works just as it should.

After I installed systemd-zram all I had to do was run (as root) systemctl enable --now systemd-zram to start it immediately and also have it run automatically at boot.

https://aur.archlinux.org/packages/systemd-zram

Edit: Make sure that you also follow @cscs’s previous instruction to disable zswap in the boot options.

But its from the AUR and has not been maintained in 5 years.

Which doesnt mean it does not work. But you might keep it in mind in case something slips.