Advertisements

Raspberry Pi Swap File Size

As part of some protracted flailing around while trying to get GNU Radio running on a Raspberry Pi 3, I discovered Raspbian defaults to a 100 MB swap file, rather than a swap partition, and everything I thought I knew about swap management seems inoperative. The key hint came from some notes on gr-gsm installation.

Tweak the /etc/dphys-swapfile config file to set CONF_SWAPFACTOR=2 for a 2 GB swap file = twice the size of the Pi’s 1 GB memory.

Start it up:

sudo dphys-swapfile swapoff
sudo dphys-swapfile setup
sudo dphys-swapfile swapon

And verify it worked:

cat /proc/meminfo 
MemTotal:         949580 kB
MemFree:          194560 kB
MemAvailable:     594460 kB
Buffers:           85684 kB
Cached:           377276 kB
SwapCached:            0 kB
Active:           600332 kB
Inactive:         104668 kB
Active(anon):     250408 kB
Inactive(anon):    20688 kB
Active(file):     349924 kB
Inactive(file):    83980 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       1918972 kB
SwapFree:        1918972 kB
Dirty:                40 kB
Writeback:             0 kB
AnonPages:        242072 kB
Mapped:           136072 kB
Shmem:             29060 kB
Slab:              33992 kB
SReclaimable:      22104 kB
SUnreclaim:        11888 kB
KernelStack:        1728 kB
PageTables:         3488 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     2393760 kB
Committed_AS:     947048 kB
VmallocTotal:    1114112 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
CmaTotal:           8192 kB
CmaFree:            6796 kB

Then it became possible to continue flailing …

Advertisements

, ,

  1. #1 by scruss2 on 2017-11-25 - 00:33

    Raspbian kernel sets vm.swappiness to 1, so it will do everything to avoid swapping unless it’s about to fall over from lack of available memory.

    Swapping to flash is painfully slow, as it’s not optimized for random access. Using a partition would just wear out that part of your SD card. You really will get faster swap by swapping to a USB (mechanical) disk

    I see that the gr-gsm instructions recommend rpi-update. This is likely unnecessary these days, and may even be detrimental.

    • #2 by Ed on 2017-11-25 - 09:55

      Aye!

      If the (Micro)SD Card does wear leveling, then there shouldn’t be any difference between a “swap file” and a “swap partition”, because the leveling happens below the file system. AFAICT, none of the reputable cards I’ve wrecked in the helmet cameras did any wear leveling, so it’s probably moot.

      The only motivation for bumping the swap size was to shove a program through its compile step; if it took the rest of the afternoon, I had other stuff to do … and did! [grin]

Spam comments vanish. Comment moderation may cause a delay.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s