→ If it’s a swap file you’ll usually see an entry like “/swapfile none swap …”.
lsblk (show blk devices + mounts)
bash
$ lsblk -o NAME,TYPE,SIZE,UUID,MOUNTPOINT
NAME TYPE SIZE UUID MOUNTPOINT
sda disk 50G
├─sda1 part 2G a1b2c3d4-… /boot
├─sda2 part 4G e5f6g7h8-… [SWAP]
└─sda3 part 44G i9j0k1l2-… /
→ Partitions marked [SWAP] are in use as swap.
free -h (quick summary)
bash
$ free -h
total used free shared buff/cache available
Mem: 7.8G 2.1G 1.8G 120M 3.9G 5.3G
Swap: 6.0G 0B 6.0G
→ Tells you total swap size but not the path; combine with steps 1–3 to locate it.
——
If you see /swapfile, that’s your swap file; if you only see something like /dev/sda2 (or nvme0n1p3), you’re using a swap partition.
Need help enabling, resizing or removing swap? Just let me know 😊
User
Filename Type Size Used Priority
/swapfile file 2097148 118180 -2
How to make it 16GB?
Assistant
Here’s one of the simplest ways to turn your 2 GB swapfile into a 16 GB one. We’ll:
turn off swap
recreate the file at 16 GB
format it as swap
turn it back on
bash
# 1) Disable the old swapfile
sudo swapoff /swapfile
# 2) Recreate a 16 GB zero-filled file
# Method A: fast with fallocate (if your FS supports it)
sudo fallocate -l 16G /swapfile
# Method B: portable with dd (always works, but slower)
# sudo dd if=/dev/zero of=/swapfile bs=1G count=16 status=progress
# 3) Secure the file (swap must be only user-readable)
sudo chmod 600 /swapfile
# 4) Make it a swap area
sudo mkswap /swapfile
# 5) Re-enable swap
sudo swapon /swapfile
# 6) Verify
swapon --show
free -h
You should now see something like:
code
NAME TYPE SIZE USED PRIO
/swapfile file 16G 0B -2
Notes:
• You don’t need to edit /etc/fstab if you’re keeping the same path (/swapfile).
• If you didn’t use fallocate, the dd approach can take a minute or two, depending on disk speed.
• To make this permanent across reboots, confirm you have an entry in /etc/fstab like:
bash
/swapfile none swap sw 0 0
And that’s it—16 GB of swap at your service! 🚀
User
What does swap priority do? How can I make it so it only starts using it once ram is 80% full?
Assistant
Here’s a two-part answer:
What “swap priority” actually does
How to delay swapping until you’re roughly 80 % RAM‐full
1) Swap priority
When you have more than one swap area (e.g. /swapfile plus /dev/sda2), Linux needs to know which one to fill first. That’s what the swap priority (PRIO) controls:
• Higher numeric PRIO → used first
• Lower numeric PRIO → used once higher-priority space is exhausted
You can see it in action with:
bash
swapon --show
# or
cat /proc/swaps
If you want to adjust it on the fly, you can turn swap off and back on with a -p flag:
bash
sudo swapoff /swapfile
sudo swapon -p 100 /swapfile # give this one priority=100
(Valid range is roughly –1 00 … +1 00; defaults are around –2, –1, 0.)
2) Holding off until ~80 % RAM is used
Linux doesn’t have a hard “only start swapping at exactly 80 % RAM” switch. Instead it uses the swappiness knob, which is a sliding scale of how aggressively to swap:
• vm.swappiness = 0 → only swap as a last resort
• vm.swappiness = 100 → swap very eagerly
• default is usually 60
Lowering swappiness makes the kernel keep things in RAM longer and only touch swap under heavier memory pressure. In practice, if you set it fairly low (say 10–20), you’ll see almost no swap use until your free RAM really starts running out:
bash
# view current
cat /proc/sys/vm/swappiness
# temporarily set to 10
sudo sysctl vm.swappiness=10
# make it permanent: add to /etc/sysctl.conf or /etc/sysctl.d/99-swappiness.conf
echo "vm.swappiness=10" | sudo tee /etc/sysctl.d/99-swappiness.conf
sudo sysctl --system
If you need exactly “start swapping when RAM > 80 %,” you’d have to resort to memory control groups (cgroups) or a custom monitoring script + early swapoff/switch—but 99 % of admins simply tune vm.swappiness to a low value and let the kernel decide.
TL;DR
• Swap priority only orders multiple swap areas.
• To delay swap use until you’re ~80 % RAM-full, lower vm.swappiness (e.g. 10).