element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
Single-Board Computers
  • Products
  • Dev Tools
  • Single-Board Computers
  • More
  • Cancel
Single-Board Computers
Blog Give Yourself More Memory by Temporarily Increasing Swap Size
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Single-Board Computers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: oneleggedredcow
  • Date Created: 30 Jun 2014 3:12 AM Date Created
  • Views 538 views
  • Likes 0 likes
  • Comments 0 comments
Related
Recommended

Give Yourself More Memory by Temporarily Increasing Swap Size

oneleggedredcow
oneleggedredcow
30 Jun 2014

Sometimes you run across a situation where you want some more memory (RAM) to complete an operation. An example of this that I ran into was trying to compile something and gcc kept running out of memory.  One way to fix this is to temporarily allocate more swap space.

Swap space is memory that resides on your hard drive (or SD card in the case of a Raspberry Pi) that can be used like RAM.  This is helpful if you are running into an out of memory error, as it will give the computer more places to store things.  The downside is that the hard drive is much, much slower than RAM.  So, if your process needs this extra memory, then it is going to run much slower.  In the situation of compiling, it means that it will take longer to compile a program, but it will actually finish without an error.  A reasonable trade off.

 

Allocating More Swap Space

Here’s the steps to allocate more swap space:

 

 

The fallocate command allocates a 1GB worth of space and assigns it to a file called /mnt/1GB.swap.  The name is for our sanity so that we know exactly what the file was intended to do.  The chmod command changes the permission on the file so that only root can read and write to the file.  The mkswap command sets up the file to be used as swap space.  Finally, the swapon command turns on swapping to the file that we created.

How much space to allocate depends on what you are trying to accomplish.  If this is a temporary thing, I’d say pick a larger value than what you think you will need.

 

Removing the Swap Space

Once you are done with the swap space that you have allocated, you can remove it with:

 

 

The swapoff command turns off swapping to the file. The rm command removes the file and frees up the space once again on your hard drive.

 

This is a great way to give yourself more memory to complete a task and then free it back up when you are done.

  • Sign in to reply
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