Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a swapfile #5

Closed
brianthelion opened this issue Mar 20, 2019 · 6 comments
Closed

Adding a swapfile #5

brianthelion opened this issue Mar 20, 2019 · 6 comments
Labels
DevBoard Related to the dev board Tutorial Linux stuff that you can do to have a better Coral experience.

Comments

@brianthelion
Copy link
Contributor

Due to lack of device RAM (see #3 ), it's important to be able to use the non-volatile memory (ie, the "disk space") for storing RAM overruns. This is what swap space is for.

Older *nix systems tended to have an entire partition dedicated to this. Modern systems tend to use a file instead.

This tutorial describes how to add a swap file to the Coral dev board.

@brianthelion brianthelion added DevBoard Related to the dev board Tutorial Linux stuff that you can do to have a better Coral experience. labels Mar 20, 2019
@brianthelion
Copy link
Contributor Author

brianthelion commented Mar 20, 2019

There's a standard package that will handle all the mechanics of setting up the swap file for you:

$ sudo apt-get install phys-swapfile

Note that if the swap file grows unbounded, it can eat up all the free space on the disk that's mounting the root partition. This is the 16GB eMMC by default. If you bound the size of the swap file, though, you may be back in "out of memory" land. Picking the right size for the swap file is a bit fuzzy.

All the settings related to the swap file can be controlled by editing /etc/dphys-swapfile. Don't forget to restart the swap file service so the changes will take effect:

$ sudoedit /etc/phys-swapfile
$ sudo service dphys-swapfile restart

@lleonid
Copy link

lleonid commented Mar 28, 2019

This is going to quickly exhaust write cycles of emmc device.

@brianthelion
Copy link
Contributor Author

@lleonid I'll talk about moving the swapfiled to a filesystem location that's mounted on the SD card in #6 . Working on that today.

@jtgans
Copy link

jtgans commented Mar 29, 2019

Should just be a matter of doing the following:

$ sudo mkswap -L sdswap /dev/mmcblk1
$ sudo swapon /dev/mmcblk1

That will use the full SD card just for swap for that session. To make it permanent:

$ echo /dev/mmcblk1 none swap sw defaults 0 0 |sudo tee -a /etc/fstab

Note that if you don't have that exact SD card inserted, it'll fail to boot.

@jtgans
Copy link

jtgans commented Mar 29, 2019

Note that SD cards and USB flash drives will also have a limited number of write cycles as well, depending on the grade and quality of the card/flash drive.

@jtgans
Copy link

jtgans commented Mar 29, 2019

Also, if you want swap on an sdcard with a filesystem (say mounted at /home like in #6), do this:

$ sudo truncate -s2G /home/swapfile
$ sudo mkswap /home/swapfile
$ sudo swapon /home/swapfile

And again, to make it permanent:

$ echo /home/swapfile none swap sw defaults 0 0 |sudo tee -a /etc/fstab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DevBoard Related to the dev board Tutorial Linux stuff that you can do to have a better Coral experience.
Projects
None yet
Development

No branches or pull requests

4 participants