├── LICENSE ├── setSwapMemorySize.sh └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 JetsonHacksNano 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /setSwapMemorySize.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2019 Jetsonhacks 3 | # MIT License 4 | # Set the zram swap file size on Jetson Nano 5 | # Default is 2GB 6 | 7 | 8 | function usage 9 | { 10 | echo " usage: ./setSwapFileSize [ [-g #gigabytes ] | [ -m #megabytes ] | [ -h ]" 11 | echo " -g #gigabytes - #gigabytes total to use for swap area" 12 | echo " -m #megabytes - #megabytes total to use for swap area" 13 | echo " -h | --help This message" 14 | } 15 | 16 | # Iterate through command line inputs 17 | if [ "$#" -gt 2 ] || [ "$#" == 0 ] ; then 18 | usage 19 | exit 1 20 | fi 21 | MEGABYTES="" 22 | while [ "$1" != "" ]; do 23 | case $1 in 24 | -g | -G ) 25 | MEGABYTES=1000 26 | ;; 27 | -m | -M ) 28 | MEGABYTES=1 29 | ;; 30 | 31 | ( *[!0-9]* | *[0-9] ) 32 | MEGABYTES=$((MEGABYTES*$1)) 33 | if [ $MEGABYTES == 0 ] ; then 34 | echo "Please specify a number > 0" 35 | usage 36 | exit 1 37 | fi 38 | ;; 39 | 40 | -h | --help ) usage 41 | exit 42 | ;; 43 | 44 | * ) echo "test" 45 | usage 46 | exit 1 47 | ;; 48 | esac 49 | shift 50 | done 51 | NRDEVICES=$(grep -c ^processor /proc/cpuinfo | sed 's/^0$/1/') 52 | REQUESTED_BYTES=$((( "$MEGABYTES" / "${NRDEVICES}" )*1024*1024)) 53 | # The configuration file is here: 54 | CONFIG_FILE=/etc/systemd/nvzramconfig.sh 55 | 56 | if [ -f $CONFIG_FILE ] ; then 57 | # we replace the memory request with the desired outcome 58 | sudo sed -i '/^mem=/c\mem='"$REQUESTED_BYTES"'' $CONFIG_FILE 59 | echo "Please reboot for changes to take effect." 60 | else 61 | echo "The swap configuration file does not exist." 62 | echo "Unable to configure swap memory" 63 | fi 64 | 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # resizeSwapMemory 2 | Resize the size of swap memory on the Jetson Nano 3 | 4 | Note that in addition to zram swap memory, you may want to also have a swapfile. See: https://github.com/JetsonHacksNano/installSwapfile/ 5 | 6 | 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. 7 | 8 | The swap memory method in use is Zram. You can examine the swap memory information: 9 |
10 | $ zramctl11 | 12 | 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. 13 | 14 | However, there are times you may want to adjust the size of swap memory ... 15 | 16 | The configuration for the Zram allocation is done on startup. The file that controls this is /etc/systemd/nvzramconfig.sh 17 | 18 | The size of the Zram for each CPU is calculated by the line: 19 |
20 | mem=$((("${totalmem}" / 2 / "${NRDEVICES}") * 1024)) 21 |22 | 23 | where totalmem is the total amount of memory, and NRDEVICES is the number of CPUs. 24 | 25 | 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. 26 | 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. 27 |
28 | sudo gedit /etc/systemd/nvzramconfig.sh 29 |30 | 31 | For example, you may remove the divisor to get a full 4GB. 32 | 33 | You can also use the script in the repository. 34 |
35 | usage: ./setSwapMemorySize [ [-g #gigabytes ] | [ -m #megabytes ] | [ -h ]41 | 42 | Example usage:
36 | -g #gigabytes - #gigabytes total to use for swap area
37 | -m #megabytes - #megabytes total to use for swap area
38 | -h - help 39 |
40 |
44 |47 | 48 | will set the entire swap memory size to 4GB. 49 | 50 | This will modify the /etc/systemd/nvzramconfig.sh to set the requested memory for the swap file as specified. 51 | 52 | You will need to reboot for the change to take effect. 53 | 54 |
45 | $ ./setSwapMemorySize -g 4
46 |