Swap configured but not used

Is there a recent guide to configuring swap on openwrt? The guide I've seen is on the archive site and I'm have difficulty ascertaining if my swap is misconfigured or just never needed. Is there a way to monitor swap file usage to a file/graph?

When I run htop i see the swap:

but I never see the swap being used, even when the ram utilisation is extreme, as when I run dd to do a disk to disk image:

free returns:

root@routeserve:~# free
              total        used        free      shared  buff/cache   available
Mem:        8009888       78672     7874020        6928       57196     7823228
Swap:      31166972           0    31166972

My /etc/config/fstab looks like this as i used gdisk to call the swap partition 'SWAP':

root@routeserve:~# cat /etc/config/fstab

config global
	option anon_swap '0'
	option anon_mount '0'
	option auto_swap '1'
	option auto_mount '1'
	option delay_root '5'
	option check_fs '0'

config mount
	option target '/boot'
	option uuid 'A29C-8EC0'
	option enabled '0'

config mount
	option target '/'
	option uuid 'ff313567-e9f1-5a5d-9895-3ba130b4a864'
	option enabled '0'

config mount
	option target '/mnt/sdb1'
	option uuid 'A29C-8EC0'
	option enabled '0'

config mount
	option target '/mnt/sdb2'
	option uuid 'ff313567-e9f1-5a5d-9895-3ba130b4a864'
	option enabled '0'

config swap
	option enabled '1'
	option label 'SDCARD'

There's a disturbing entry when I run swapon -s:

root@routeserve:~# swapon -s
Filename				Type		Size	Used	Priority
/dev/sdc\040(deleted)                   partition	31166972	0	-2

and when i try swapon /dev/sda1 (where I created a Linux Swap using gdisk):

root@routeserve:~# swapon /dev/sda1
block: failed to swapon /dev/sda1 (-1)

But I see it coming up in Luci:

I don't see anything in top:

Mem: 5596880K used, 2413008K free, 7288K shrd, 5388944K buff, 46972K cached
CPU:   0% usr   7% sys   0% nic  79% idle  11% io   0% irq   0% sirq
Load average: 1.99 0.59 0.21 3/136 6798

Also nothing in luci app statistics graphing:

So you have 8 GB of RAM, and an SD card allocated as swap. A typical consumer router has anywhere between 32 MB or 1 GB RAM, and no swap at all. And you got 8 GB and you're worried about swap? What's your use case here?

Linux won't swap unless it needs to. And using slow, wear sensitive flash storage like an SD card (which is a sure way to kill it) is a bad idea.


I also set the if field in dd to the device mmcblk where the system lives, which ordinarily would be a terrible idea, but I'm just trying to max out the RAM, because the use case is learning to configure swap on the only openwrt instance I have available to me.

Where am I going wrong with my configuration? Answering a question with another question can be an example of the socratic method, but I don't see to which insights into my misconfiguration your questions lead.

@Bill I'm not sure why you deleted your post, I learnt from it. I liked the "ubus call system board" command.

root@routeserve:~# ubus call system board
	"kernel": "5.4.179",
	"hostname": "routeserve",
	"system": "ARMv8 Processor rev 3",
	"model": "Raspberry Pi 4 Model B Rev 1.4",
	"board_name": "raspberrypi,4-model-b",
	"release": {
		"distribution": "OpenWrt",
		"version": "21.02.2",
		"revision": "r16495-bf0c965af0",
		"target": "bcm27xx/bcm2711",
		"description": "OpenWrt 21.02.2 r16495-bf0c965af0"

I had nothing of value to your use case. These benchmark test you want to preform are reliant on wiki article's written by @trendy and @Borromini .

I wanted and did the same exact thing trying to push a system beyond the initial config. I too enabled and tested swap but my system never needed it and I to use DD. The system is also used for
wbAdmin start backup -backupTarget:\\ doing Block Level Backup, and streams my Kodi Library. This in one system I don't play with or log into.. It works despite the SD Card I burnt out years ago and never replaced.

so .. wait and see if you find your bug. I cant help with that, all I managed to do was divert with Socratic method too; the way I see it.


1 Like

I don't see anything wrong with your configuration. Htop sees an empty swap partition. Working as intended.

Try increasing swappines on your system and see if that gets you any closer. Way easier would just be to use an old router with limited memory and set up swap there.

1 Like

courtesy of @Borromini https://openwrt.org/docs/guide-user/storage/fstab#the_right_amount_of_swap

My nick just happens to be at the bottom of the page because I was the last person to modify it. But I did not write the article :blush:.

Thanks @RuralRoots, however your post answers the question of what is, as the title of the article in the link you posted reads, "The right amount of SWAP".

Do you have any links relevant to the context of my "just never needed" (whilst running dd, disk to disk)?

I'm trying to find out why my openWRT never uses SWAP, even when it clearly could be doing so.

Your testing method is wrong. buff/cache RAM is never swapped out --- doing so will defeat the purpose of caching.


I got my original idea about using dd from this post: https://www.linux.org/threads/how-to-testing-swap-performance.7624/

So what kind of application can i use to test the performance of my swap if not dd?

You can resize the tmpfs directory /tmp and dd to it. tmpfs resides in virtual memory and can be swapped out to disk.

See the documentation here:


Adjust the swappiness value. The default swappiness value is 60. The smaller this value, the more of your RAM will be used.

cat /proc/sys/vm/swappiness

Your Linux kernel will use less RAM and move toward enabling swap.

True but I would deduce you concur with the content by putting your name to it. :wink:

1 Like

Maybe this would be easier to test with a larger/full linux distro (such as RaspberryPi OS) which takes more resources in general and has apps that can easily fill the full amount of RAM available.

OpenWrt is designed to be really lightweight in terms of storage and RAM requirements (relative to the bigger distros), and therefore you should probably never need swap in normal operation when you have so much RAM available to you.

In fact, I'd argue that if you have 8GB of RAM and need swap while running OpenWrt (any version for the foreseeable future starting in 2022), you're probably doing it wrong. If you are ever actually running such a heavily loaded system in the context of OpenWrt (or routing), you probably need a to consider beefier hardware in general (x86) and/or reconsider the use of a lightweight OS and maybe move to a full OS.

That said, as an academic exercise, measuring your swap performance is fine and you're getting some good advice about how to do it. Remember it is highly dependent on the card you are using, too.


I haven't been able to consume more than half of my memory (4GB) and I have loaded the router with quite a lot of services.

Moreover when you get to use the swap, it will become so slow that it's better if you let it die and restart, than crawling and affecting the overall performance.


I'm probably doing something wrong (despite running quite beefy adblock lists):

…it's a router, not a general purpose server.

Thanks, this seems like it would work. I've adjusted the swapiness value to 100 and will work on resizing tempfs later today.

Yeah :sweat_smile: I work for a company that engineers and administers tests for other companies software. I don't have an 'off' button :grin:

Oh, this is [possibly] commercial...