modified on 16 March 2016 at 20:23 ••• 3,565 views

Adding swap space

From Manuals

Jump to: navigation, search

You can create a file on a microSD card as swap space to extend system memory. Swap is significantly slower than RAM so performance will be affected, but you will reduce the chance of running out of memory .

These steps allow you to create and mount a 64 MB swap file when booting from a microSD card.

 # dd if=/dev/zero of=/swapfile bs=1024 count=65536
 65536+0 records in
 65536+0 records out
 67108864 bytes (67 MB) copied, 15.0498 s, 4.5 MB/s
 # chmod 600 /mnt/swapfile
 # mkswap /mnt/swapfile
 Setting up swapspace version 1, size = 65532 KiB
 no label, UUID=961c7861-e5fe-46c4-97b5-374b28e6adb2
 # swapon /swapfile
 [ 1567.710000] Adding 65532k swap on /mnt/swapfile.  Priority:-1 extents:90 across:86764k SS
 # free
              total       used       free     shared    buffers     cached
 Mem:         61192      59736       1456       8660        116      40488
 -/+ buffers/cache:      19132      42060
 Swap:        65532          0      65532

To mount the swap file automatically after reboot add the following line to /etc/fstab

 /swapfile none swap sw 0 0

NOTE: swap files are not supported on compressed file systems like the JFFS2 used in NAND