element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Blog Part X.3 Arduino Yun Extending the RAM with swap file
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: pmohan
  • Date Created: 19 Dec 2014 6:46 PM Date Created
  • Views 2428 views
  • Likes 2 likes
  • Comments 6 comments
  • RoadTest
  • ram
  • yun
  • wifi_christmas_tree
  • iot_holidaylights
  • swap
  • expand
  • arduino_yun
  • arduino
Related
Recommended

Part X.3 Arduino Yun Extending the RAM with swap file

pmohan
pmohan
19 Dec 2014

In the last blog post, i installed node js on my Arduino Yun. Then when i tried to install some more node packages using node package manager (npm) i ran in to "out of memory" issue.

 

FATAL ERROR: Evacuation Allocation failed - process out of memory

Aborted

 

At some point of time when you are running some process on the OpenWrt-Yun Linux side of the Arduino Yun, you are bound to face this error.  Note that even when you are running a sketch on the Arduino side, if you happen to use any of the Bridge libraries, you are in essence running a process on the linux side. So inadvertently you might run a process that consumes more RAM than available on the linux side.  For a reference here is the linux memory footprints on the Yun

Type of Memory

Linux Microprocessor

Comments

Flash Memory

16 MB (9MB used by OpenWrt-Yun)

The linux flash memory can be expanded by using the SD Card to load more disk space as explained here.

RAM

64 MB

About 18 to 20 MB of this will be free for you to run other process.

 

So when you run out of this 18+ MB free memory in RAM, we will run in to fatal error above.

 

To avoid this you should set up a swap file or a swap partition for the Linux side of the Yun. When you expand disk space as described here, the YunDiskSpaceExpander sketch doesn’t set up a swap partition by default.  So we have to create a swap file that can be used by openwrt-yun to avoid running out of RAM memory. (Later when i have some time i will see if i can enhance the script to set up a swap partition by default)

 

Verifying Free Memory

 

Connect to Yun using ssh  (i.e. by running "ssh root@youryun.local” from terminal). Then run:

free -m

This should show your current Free memory.. On mine its this:

             total         used         free       shared      buffers
Mem:         61116        43556        17560            0         9612
-/+ buffers:              33944        27172
Swap:            0            0            0

Note the Swap.. Its 0.

So now that i have confirmed that there is no swap file, I tried and set that swap file up on my Yun. The process involves 4 steps.

 

Step 1: Create an empty file to act as a swap file:

 

While connected to the Yun through the ssh terminal, run: (Note that this line will create a 512 MB swap file named yunswapfile in folder "/swap"and fill it with zero

dd if=/dev/zero of=/swap/yunswapfile bs=1M count=512

 

This should run for a bit and provide output like this:

512+0 records in

512+0 records out

 

Step 2: Designate the file as a Swap file:

The step above just created an empty file. To make sure it can be used as a swap file, run this from the shell:

mkswap /swap/yunswapfile

 

You should get output like this:

Setting up swapspace version 1, size = 524284 KiB
no label, UUID=e3e63fad-e6f7-4d4e-a32a-a326bbe48e8c


Step 3: Load the swap file for verifying

To verify that the swap file is good, try to load it by running this:

swapon /swap/yunswapfile

 

This will not provide any output if everything is cool. So verify by checking free memory.

free -m

 

             total         used         free       shared      buffers

Mem:         61116        28644        32472            0         4888

-/+ buffers:              23756        37360

Swap:       524284            0       524284

 

Viola!!! Now you can notice that a swap file is available for use by the RAM. Its not finished yet. Make sure you do step 4 below.

 

Step 4: Load the swap file as part of boot sequence

 

If you stop with Step 3, next time when you restart your Yun (linux part..either through power off/on or the Linux reset button near the LEDs) the swap file will not have been loaded. So to make sure that its gets loaded every time, you need to set the swap file as part of boot sequence.

 

Warning: The steps are fairly simple. But if you the steps are not executed fully you might leave a inconsistent boot config and Linux part of Yun may not load properly. Well this is Arduino. So you can reset the whole thing easily and try again. So please execute the following cleanly after understanding them.


//1. add swap config entry to fstab

root@youryun:/# uci add fstab swap


//2. set device config entry to swap. make sure you provide your full swap file name

root@youryun:/# uci set fstab.@swap[0].device=/swap/yunswapfile

//3. set swap is enabled

root@youryun:/# uci set fstab.@swap[0].enabled=1

//4. set file system type as "swap"

root@youryun:/# uci set fstab.@swap[0].fstype=swap


//5. set options to default

root@youryun:/# uci set fstab.@swap[0].options=default


//6. set fsck to 0

root@youryun:/# uci set fstab.@swap[0].enabled_fsck=0

 

//7. Commit the config changes. if you don't run commit, the config changes will not be added. So make sure the changes are commited.

root@youryun:/# uci commit


That's it. Done. Restart the Linux part of Yun (reset button near LEDs). After reboot, if you run "free -m" you should see the Swap file loaded. You have successfully expanded the RAM on your Arduino Yun's linux side.

  • Sign in to reply

Top Comments

  • pmohan
    pmohan over 10 years ago in reply to shabaz +1
    The Linux side of the yun has both flash memory (storage) and RAM (for running processes)..Similar to PC.. The 16 mb flash memory is expanded to any size by using the SD card. The 64 MB RAM can also be…
  • shabaz
    shabaz over 10 years ago in reply to pmohan

    Oh I see! I didn't realize the Yun had SD capability. Thanks for the clarification!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • pmohan
    pmohan over 10 years ago in reply to pmohan

    Also note that this doesnt change anything on the arduino microprocessor side of the yun. The architecture of arduino yun should be looked at as Microprocessor + Linux computer.  the bridge library simply allows the microprocessor communicate to Linux over serial.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • pmohan
    pmohan over 10 years ago in reply to shabaz

    The Linux side of the yun has both flash memory (storage) and RAM (for running processes)..Similar to PC.. The 16 mb flash memory is expanded to any size by using the SD card. The 64 MB RAM can also be expanded (virtually, not physically) by using a swap file or swap partition. in this post I showed how to Set up a swap file once SD card is available.it is still 64 mb ram but the Linux OS takes care of swapping portions of memory into the swap file to make it seem like larger memory for the application processes.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 10 years ago

    Hi Mohan,


    Did you mean 512kbyte? The text says 512MB, but you mentioned there is only 16Mbyte of Flash.

    (or maybe I misunderstood : ( I've not used this board before.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 10 years ago

    Very useful Mohan.

     

    Thanks very much.

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube