GithubHelp home page GithubHelp logo

lackdaz / resizeswapmemory Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jetsonhacksnano/resizeswapmemory

0.0 1.0 0.0 21 KB

Resize the Zram swapfile on the Jetson Nano

License: MIT License

Shell 100.00%

resizeswapmemory's Introduction

resizeSwapMemory

Resize the size of swap memory on the Jetson Nano

Note that in addition to zram swap memory, you may want to also have a swapfile. See: https://github.com/JetsonHacksNano/installSwapfile/

Starting with L4T 32.2.1/JetPack 4.2.2, the Jetson Nano by default has 2GB of swap memory. The swap memory allows for "extra memory" when there is memory pressure on main (physical) memory by swapping portions of memory to disk. Because the Jetson Nano has a relatively small amount of memory (4GB) this can be very useful, especially when, say, compiling large projects.

The swap memory method in use is Zram. You can examine the swap memory information:

$ zramctl

You will notice that there are four entries (one for each CPU of the Jetson Nano) /dev/zram0 - /dev/zram3. Each entry has an allocated amount of swap memory associated with it, by default 494.6M, for a total of around 2GB. This is half the size of the main memory. You will find this to be adequate for most tasks.

However, there are times you may want to adjust the size of swap memory ...

The configuration for the Zram allocation is done on startup. The file that controls this is /etc/systemd/nvzramconfig.sh

The size of the Zram for each CPU is calculated by the line:

mem=$((("${totalmem}" / 2 / "${NRDEVICES}") * 1024))

where totalmem is the total amount of memory, and NRDEVICES is the number of CPUs.

Basically it divides the amount of physical memory by the number of CPUS with a divisor, in this case 2 to get the 2GB total. You can simply edit this equation using a text editor. You should probably make a backup of the file first, just in case. You will need sudo permissions to change the file.

sudo gedit /etc/systemd/nvzramconfig.sh

For example, you may remove the divisor to get a full 4GB.

You can also use the script in the repository.

usage: ./setSwapMemorySize [ [-g #gigabytes ] | [ -m #megabytes ] | [ -h ]
  -g #gigabytes - #gigabytes total to use for swap area
  -m #megabytes - #megabytes total to use for swap area
  -h - help

Example usage:


$ ./setSwapMemorySize -g 4

will set the entire swap memory size to 4GB.

This will modify the /etc/systemd/nvzramconfig.sh to set the requested memory for the swap file as specified.

You will need to reboot for the change to take effect.

Notes

The recommended swap memory size is 2GB for a 4GB Jetson Nano. Larger swap memory sizes can sometimes cause decreased performance. It is recommended to use a swap file in addition to swap memory if you need larger amounts of memory for building projects.

November 2019

Initial Release

  • v1.0
  • Jetson Nano
  • L4T 32.2.1/JetPack 4.2.2
  • L4T 32.2.3/JetPack 4.2.2

resizeswapmemory's People

Contributors

jetsonhacksnano avatar jetsonhacks avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.