How can I add memory to my Fox Board G20?
I have to admit, this question doesn’t quite fit the bill. However, If you’ve ever tried to compile a large project on your Fox Board G20, you may have noticed that it just won’t work due to memory problems. At some point, you will see the mmcqd process run overtime and your system grinds to a halt. I recently ran into this problem while trying to compile some big project and remembered that I had exactly the same problem when I tried to update the Perl installation on my G20. Believe me, you do not want to wait for this situation to resolve itself: it just won’t. In my case, I’d actually given up on trying to compile my project.
Thankfully, I asked about this problem in the G20 forum in Google Groups and I got an excellent pointer from Jan Klusacek:
Hi,
if RAM is issue then you should try use swap. You don’t have to create
new partition, 100MB file should be enough. After create, you can use
swapon to activate it.
I figured I could explain his suggested procedure here in more detail.
The reason you run into trouble building such a project actually is the lack of sufficient RAM. However, you cannot (easily) add more RAM to the G20, so you need a different solution. The solution is: swap space. Since kernel 2.6 you can use swap files with Linux; before that, you could only use a swap partition. So, we simply need to create a swap file on the G20. We don’t really need a lot of space, by adding a swap file of 100MB, you’re effectively more than doubling your memory, so this will suffice.
First, we need to create a swap file [1]:
debarm~# dd if=/dev/zero of=/myswapfile bs=1024 count=102400
This will create a file of 100 x 1024 blocks each having a size of 1024 bytes: 100 x 1024 x 1024 = 100 MB.
Next, we set up the swap space:
debarm~# mkswap /myswapfile
and immediately turn it on:
debarm~# swapon /myswapfile
Checking whether the swap is there and whether it’s used can be done using free:
debarm~# free -m
...... total used free shared buffers cached
Mem: 59 54 4 0 3 41
-/+ buffers/cache: 9 50
Swap: 99 6 93
The option -m tells free to show you the results in Megabytes, which makes for a more readable result for us humans.
Finally, you probably want to use your swap space after a reboot as well. Use your favorite editor (I use joe, simply apt-get install joe to get it) to open /etc/fstab:
debarm~# joe /etc/fstab
and add the following line to it:
/myswapfile swap swap defaults 0 0
in order to automatically start using your swap space after a reboot.
That’s all! No wait, there is something else I have to say about it. Be prepared that this is in no way a fast solution. Memory reads and writes to RAM are many, many, times faster than memory accesses to flash memory. And since the root file system of the G20 resides on an SD memory card, flash memory is what you’re dealing with. So it’s up to you to decide whether this trade off is acceptable to you.
I finally got my project to compile, even though it took the better part of a day to get there, so I’m more than happy with this solution!
One Comment so far ...
[...] Today, I decided I want to install OpenCV (Open Source Computer Vision) on my Fox Board G20 to prepare for a possible project that I might be doing in the near future. Already having an OpenCV demo on a regular PC, I thought it would be worth the effort to try and get that demo running on my G20 as a true embedded application. I like to share my results with you, dear reader, in case you’d like to create an embedded OpenCV-based vision solution as well. If you want to install OpenCV on your Fox Board G20, make sure you read this post first: How can I add memory to my Fox Board G20? [...]
Pingback on June 8, 2010 09:13 am