Skip to content

Instantly share code, notes, and snippets.

@Terrariadlc
Last active May 15, 2025 15:19
Show Gist options
  • Save Terrariadlc/ddf5fc7e39da8a133d73b3111c1cb1b1 to your computer and use it in GitHub Desktop.
Save Terrariadlc/ddf5fc7e39da8a133d73b3111c1cb1b1 to your computer and use it in GitHub Desktop.
SWAP on Android using termux

Requirements: Termux, Root (preferably Magisk).

Open termux and give it root permissions

Type su to escalate the permissions

Now enter the command dd if=/dev/zero of=swapfile bs=1024 count=6144k replacing 6144k with as much swap as you need, in this case 6GB

Once its done, enter mkswap swapfile to create the sawp file and swapon swapfile to enable the swap file

@LeoRudra
Copy link

what about non-rooted phones ??

@DEV-197
Copy link

DEV-197 commented Oct 21, 2024

@LeoRudra You could use Shizuku with termux on non rooted devices

@FEMADOX
Copy link

FEMADOX commented Nov 4, 2024

How? I had already installed, what should I do?

@ASDownloadingAccount
Copy link

Does this last until a reboot?

@irian-codes
Copy link

Thank you!

To enable this across reboots I had to create a script inside Magisk boot script service.d path. But with a delay of 2 minutes, otherwise the script would run before zRAM allocation and the performance was terrible. It needs to run after it, because zRAM is faster storage and needs to be used before the swap file in the SSD.

#!/system/bin/sh
# Delay ensures zRAM is loaded first so swap priority if this swap file is lower.
sleep 120
swapon /data/swapfile

This has effectively solved all lagging issues on my phone 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment