Create swap space?


CHIP’s 512MB RAM space seems small. I tried to create a swap space by creat a swap file according to what shown here. Basically, I did the following:
dd if=/dev/zero of=/swapfile bs=1024 count=512000
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
However, the last command returns the error: “swapon: /swapfile: swapon failed: Invalid argument”.
From Googling, I think it could be due to the CHIP’s file system type. Is this true? Does anybody know if there is a way to create a swap space for the CHIP? Thanks.


Um, it’s generally a very, very bad idea to create swap on NAND flash. So it’s a good thing that didn’t work…

If you really need additional swap space (which would be super-slow, probably, but I guess better than nothing) you could always do it on a USB flash drive.


barawn is correct, we don’t recommend creating swap space on NAND. It’s likely you would be just adding a lot of wear and tear on the NAND storage and significantly reduce its lifespan.


However! You can absolutely mount a swap file/partition on a USB device. Will it be 10x slower? Yep. But is that a noticable difference of already being 100x slower than RAM. Nope.


Using USB drive kept kill my CHIP when I write big file to it. I just can’t trust it. I guess I just give up.


Wow I found that out too. When I wanted to save a big .zip file to a 64GB USB drive on the CHIP. It only uploaded a little and then locked up. On reboot it can’t boot up all the way then. I have to reflash it.

That good it’s just not me.

"[quote=“twinclouds, post:5, topic:2052”]
Using USB drive kept kill my CHIP when I write big file to it.

-Raymond Day


It has happened multiple times for me. (Almost always when I tried to back up the system onto the USB drive.). However, I was always able to reboot it back. I just cannot trust to use the USB drive on CHIP anymore.


For the folks where the USB drive kills the CHIP, are these separately powered USB drives? Just curious if using a USB drive with it’s own power supply separate from CHIP still kills the CHIP.


I’d be curious to know of this as well, along with what the amps on the power supply you are using. It seems possible that CHIP needs to do more work to transfer the file and the power supply can’t keep up with the demand. Some flash drives need more power than others.

Cloud5thunder may be right. I would guess that using the drive in a powered USB hub would help. Or try using a power supply that has enough amps to power CHIP and have enough for the 500mAh the USB port may need.

If you feel you had a good power supply, I’d also like to know the brand of the Flash drives so we can do our own tests.


I tried using a powered SATA deck with a 2.5" drive plugged in. It works fine to do backups using rsynch and tar. The data wrote are over 1GB each. So the problem is the CHIP USP port power limit. If using external powered drive, it should be fine.


Great thread, I tried on the CHIP as well because OOM killer reared it’s ugly head on GCC while compiling OLA. I wanted a temporary way to swap to get the package built, then would disable it. I’ll be trying the same on a USB stick when I get back to that work.


This is actually the same reason I did it! Had a compile job that used just slightly more than 500M. Ended up mounting a flash drive as swap and bam!


When I used a USB flash drive, I got this to work so I could compile some code, as mentioned by others. But I will elaborate in hopes of helping some other person struggling with this.

I basically did the same, but replaced “/dev/zero” with “/dev/sda1” (the flash drive) and swapon is expecting the device path, not the file path, as an argument. I also had to sudo everything.

This is exactly what I did:

sudo dd if=/dev/sda1 of=/swapfile bs=1024 count=512000
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /dev/sda1

Doing so allowed me to compile my needed code. Then the swap was not needed for normal operation of my CHIP. I just removed the flash drive during a reboot. It was never added to /etc/fstab as a permanent swap.

I hope this info is found useful! :innocent:

ps I did not use a seperatly powered USB drive, just a 8 gig “thumb” drive pluged in directly, and had no issue in that regard. The drive has no LEDs, maybe that helped. :wink:


Looking over your instructions again, it looks like it’s creating that 512mb file on the root directory of the CHIP, which causes more writes to the NAND

These instructions should work no problem as /dev/zero is just a null file that gets copied to /mnt/usb/swap.file

sudo mkdir /mnt/usb
sudo mount /dev/sda1 /mnt/usb

sudo dd if=/dev/zero of=/mnt/usb/swap.file bs=1M count=512
sudo chmod 600 /mnt/usb/swap.file
sudo mkswap /mnt/usb/swap.file
sudo swapon /mnt/usb/swap.file

Depending on the filesystem it’ll properly go to 600, but even if it stays at 755 it works fine (which using FAT formatted by win7 it seems to do). I’ve used this to build a program no problem so I can attest that it works fine and ensures you don’t write the swap to the NAND


Oh, yes. I see the error of my ways. Thanks for pointing that out!


I do not agree with the scary warnings about using swap on Flash-media. First off, unless you’re doing compiling or such RAM-heavy tasks your system is unlikely to put anything in the swap in the first place, or if it does, it’s stuff that would just sit idly in RAM, ie. parts of shared libraries or such that aren’t in actual use by any binary running on the system. (Linux has to load the whole shared library, even if only 10% of it was actually used.) Secondly, the Flash just doesn’t wear out that fast. The Flash-cells are generally rated for at least 10,000 writes, and UBIFS also happens to be a wear-leveling filesystem, so you’d have to be doing a god damn heck-ton of writes to wear it out.


dd takes a lot of arguments… if is the input file of is the output file. So dd if=/dev/zero of=/swapfile will create an empty file called /swapfile. If you want to use /dev/sda1 then you should ideally tag it with the right type for a swap device but you can then just do a mkswap and then swapon. swap devices are usually more efficient than swap files, but ideally you don’t want to be swapping.


I kept running out of memory while trying to compile. Since I had a spare 8GB micro SD card laying around–and a USB SD card reader–I went ahead and set up some swap space.

1. Format SD card as linux-swap using Gparted on my Fedora box (other methods are out there)
2. Insert in chip
3. $ sudo mkswap /dev/sda1
4. $ sudo swapon /dev/sda1
5. Compile with no memory errors!

I’m not sure if the mkswap command is necessary or not, since this was already formatted as a swap partition.

This was done with a passive SD card reader, no external power supply, no issues with chip crashing. Probably would be a different story if you’re trying to power a whole USB HD.


Or do it like tinycore.
Zlib compressed swap in RAM


I can confirm that this method worked for me. A couple of weeks ago I was trying to flash my phone with some “evil” rom and noticed that when I tried to send the system zip the process was interrupted and displayed an error. After I googled the error it said that my system was complaining about a lack of ram because the file I was trying to flash needed to be decompressed in ram before being sent to the phone, so I grabbed an old micro sd card that I had laying around (in fact, it was my first one, bought in 2009 if I remember well), created a 2 gb Linux swap partition and mounted it, and it worked like a charm, so I now have a rooted phone with a custom rom thanks to my Pocket CHIP. I’ve been thinking when I have some time trying something different and create a larger swap partition to try to compile the devkit ppc in my Pocket CHIP, who knows if it also works. Thanks very much guys.