Jump to content

SWAP: Difference between revisions

From postmarketOS Wiki
Susurrus (talk | contribs)
m Replace deprecated <source> tags with <syntaxhighlight>
 
(One intermediate revision by one other user not shown)
Line 8: Line 8:


=== Partition ===
=== Partition ===
{{Warning|Setting SWAP on (e)MMC might kill it faster. Try this on an unused SD card instead.}}
{{Warning|Think twice to prevent data loss before wiping out a partition with <code>mkswap</code>.}}
{{Warning|Think twice to prevent data loss before wiping out a partition with <code>mkswap</code>.}}


To add some swap with unused partitions:
To add some swap with unused partitions:
<source lang="shell-session">
<syntaxhighlight lang="shell-session">
postmarketos-msm8916:~# mkswap /dev/disk/by-partlabel/cache  
postmarketos-msm8916:~# mkswap /dev/disk/by-partlabel/cache  
mkswap: /dev/disk/by-partlabel/cache: warning: wiping old swap signature.
mkswap: /dev/disk/by-partlabel/cache: warning: wiping old swap signature.
Line 21: Line 22:
Mem:        893.7M      211.7M      421.0M      68.3M      260.9M      591.6M
Mem:        893.7M      211.7M      421.0M      68.3M      260.9M      591.6M
Swap:        300.0M          0      300.0M
Swap:        300.0M          0      300.0M
</source>
</syntaxhighlight>


=== Swapfile ===
=== Swapfile ===
Or files:
Or files:
<source lang="shell-session">
<syntaxhighlight lang="shell-session">
postmarketos-msm8916:~# dd if=/dev/zero of=swap bs=4M count=128
postmarketos-msm8916:~# dd if=/dev/zero of=swap bs=4M count=128
128+0 records in
128+0 records in
Line 38: Line 39:
Mem:        893.7M      212.6M      14.4M      68.2M      666.7M      590.7M
Mem:        893.7M      212.6M      14.4M      68.2M      666.7M      590.7M
Swap:        812.0M      512.0K      811.5M
Swap:        812.0M      512.0K      811.5M
</source>
</syntaxhighlight>


== Mount swap by default ==
== Mount swap by default ==
Line 44: Line 45:
=== fstab ===
=== fstab ===
And add swap partitions and files into <code>fstab</code>.
And add swap partitions and files into <code>fstab</code>.
<source lang="shell-session">
<syntaxhighlight lang="shell-session">
postmarketos-msm8916:~# nano /etc/fstab
postmarketos-msm8916:~# nano /etc/fstab
# This file is *not* used to mount / or /boot.
# This file is *not* used to mount / or /boot.
Line 51: Line 52:
/dev/disk/by-partlabel/cache    swap    swap    nofail  0 0
/dev/disk/by-partlabel/cache    swap    swap    nofail  0 0
/root/swap                      swap    swap    nofail  0 0
/root/swap                      swap    swap    nofail  0 0
</source>
</syntaxhighlight>


=== OpenRC ===
=== OpenRC ===
Then make swap mounted by default.
Then make swap mounted by default.
<source lang="shell-session">
<syntaxhighlight lang="shell-session">
postmarketos-msm8916:~# rc-update add swap
postmarketos-msm8916:~# rc-update add swap
  * service swap added to runlevel default
  * service swap added to runlevel default
postmarketos-msm8916:~# rc-update add swapfile
postmarketos-msm8916:~# rc-update add swapfile
  * service swapfile added to runlevel default
  * service swapfile added to runlevel default
</source>
</syntaxhighlight>


== See also ==
== See also ==

Latest revision as of 06:30, 14 April 2024

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

Warning WARNING: Setting SWAP on (e)MMC might kill it faster. Try this on an unused SD card instead.
Warning 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