SWAP

From postmarketOS

In 2020s, devices with 2GB of RAM have been a basic requirement for modern usage with UI, web browsing and video playback.

However some devices are produced as budgets phone with 1GB / 1.5GB, or even 256MB on those ancient devices.

With memory reserved by kernel for something like modem, there is even only 0.8GB /1.3GB available in userspace.

SWAP or SWAP file can be added for additional memory, which enables you to run Phosh or Plasma Mobile with smaller RAM, and even use Firefox to browse the web or playing video, etc.

Partition

Icon WARNING: Setting SWAP on (e)MMC might kill it faster. Try this on an unused SD card instead.
Icon WARNING: Think twice to prevent data loss before wiping out a partition with mkswap.

To add some swap with unused partitions:

postmarketos-msm8916:~# mkswap /dev/disk/by-partlabel/cache 
mkswap: /dev/disk/by-partlabel/cache: warning: wiping old swap signature.
Setting up swapspace version 1, size = 300 MiB (314568704 bytes)
no label, UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
postmarketos-msm8916:~# swapon /dev/disk/by-partlabel/cache
postmarketos-msm8916:~# free -h
              total        used        free      shared  buff/cache   available
Mem:         893.7M      211.7M      421.0M       68.3M      260.9M      591.6M
Swap:        300.0M           0      300.0M

Swapfile

Or files:

postmarketos-msm8916:~# dd if=/dev/zero of=swap bs=4M count=128
128+0 records in
128+0 records out
postmarketos-msm8916:~# chmod 0600 swap
postmarketos-msm8916:~# mkswap swap
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
postmarketos-msm8916:~# swapon swap
postmarketos-msm8916:~# free -h
              total        used        free      shared  buff/cache   available
Mem:         893.7M      212.6M       14.4M       68.2M      666.7M      590.7M
Swap:        812.0M      512.0K      811.5M

Mount swap by default

fstab

And add swap partitions and files into fstab.

postmarketos-msm8916:~# nano /etc/fstab
# This file is *not* used to mount / or /boot.
# More information: https://postmarketos.org/fstab

/dev/disk/by-partlabel/cache    swap    swap    nofail  0 0
/root/swap                      swap    swap    nofail  0 0

OpenRC

Then make swap mounted by default.

postmarketos-msm8916:~# rc-update add swap
 * service swap added to runlevel default
postmarketos-msm8916:~# rc-update add swapfile
 * service swapfile added to runlevel default

See also