3

I am running a Jetson Nano with Jetpack 4.4 which (Ubuntu 18.04), by default, has 4x495 Meg ZRAM partitions for swap space. The problem is that for a data science project I need MORE RAM than the 4gig installed on the Jetson (and whatever I get from compressed ZRAM - not much). So I'd like to make an 8gb swap file instead of the ZRAM swap.

enter image description here

How do I disable the ZRAM swap altogether so that I can create a swap file?

I've tried

sudo apt remove --purge zram-config
sudo dpkg --purge zrawmswap-enabler
sudo dpkg --purge zram-config
sudo service zramswap stop

But none of it works. ZRAM swap is still enabled on reboot: enter image description here

Alternatively can I just create a disk swap file and expect it to replace ZRAM?

Thomas Browne
  • 376
  • 3
  • 8
  • 26

1 Answers1

3

With zram you are having swap in RAM and compressed. Whenever your system swaps it will be doing it very fast, as is RAM.

You don't need to stop the zram to replace with another swap. You can just add more swap, and let the system handle it.

If you want to change the config ratio of zram edit: /etc/systemd/nvzramconfig.sh

In order to create a new swap on disk you have either two options:

  • Create a partition for swap, dedicated
  • Create a file in a drive and use it for the swap.

If you expect a lot of movement from swap to ram and viceversa:

  • You can use the 16 GB eMMC 5.1 in the Jet Nano, but it will die soon. They are not made for rewriting like swap does when system is memory hungry. Speed will be slow too.
  • You can connect a external drive using the USB 3.0 interface
  • If you use SSD, writing a lot may lead to a premature die of the SSD You can use SAS SSD Enterprise grade, but I think that would be overkill for a computer which cost is low and anyway the speed will be limited to the speed of the USB 3.0 port.
  • If you use HDD, swapping will be very slow. In both cases you'll be limited by the speed of the USB 3.0

For what you are commenting I believe you'll run that scientific program few times, let's say a maximum of 100 times, so even if swap is being strongly used should be no problem for a domestic SSD. You can also attach an NVMe using an external case, but you'll not see high speed, as the speed constraint is in the USB 3.0. The Samsung PRO series offer double of writing before they die.

Pay attention to use the 3.0 and not a 2.0 accidentally.

If you require to use that scientific program, may be you can assemble a cheap PC with 16 GB or 32 GB of RAM and you will not need swap at all.

Update 2020-11-04: In JetPack-4.4 nvzramconfig is a Systemd Service, so in /etc/systemd/system you have a file called nvzramconfig.service

#
# Copyright (c) 2019, NVIDIA CORPORATION.  All rights reserved.
#

[Unit] Description=ZRAM configuration ; Everything depends on the NVIDIA per-boot script After=nv.service ; TPC power gating must be enabled before anything touching gpu After=nvpmodel.service

[Service] Type=simple ExecStart=/etc/systemd/nvzramconfig.sh

[Install] WantedBy=multi-user.target

You can prevent completely this Service from starting by disabling it:

sudo systemctl disable nvzramconfig

That's the preferred way to do it. But if for whatever reason you don't want to disable the service the not so nice option is to just comment every line in the file /etc/systemd/nvzramconfig.sh like this:

#!/bin/bash
#
# Copyright (c) 2019, NVIDIA CORPORATION.  All rights reserved.
#

NRDEVICES=$(grep -c ^processor /proc/cpuinfo | sed 's/^0$/1/')

if modinfo zram | grep -q ' zram_num_devices:' 2>/dev/null; then

MODPROBE_ARGS="zram_num_devices=${NRDEVICES}"

elif modinfo zram | grep -q ' num_devices:' 2>/dev/null; then

MODPROBE_ARGS="num_devices=${NRDEVICES}"

else

exit 1

fi

modprobe zram "${MODPROBE_ARGS}"

Calculate memory to use for zram (1/2 of ram)

totalmem=LC_ALL=C free | grep -e "^Mem:" | sed -e 's/^Mem: *//' -e 's/ *.*//'

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

initialize the devices

for i in $(seq "${NRDEVICES}"); do

DEVNUMBER=$((i - 1))

echo "${mem}" > /sys/block/zram"${DEVNUMBER}"/disksize

mkswap /dev/zram"${DEVNUMBER}"

swapon -p 5 /dev/zram"${DEVNUMBER}"

done

As long as the execution exits with error level 0 (so no error or no exit code different from 0) it will be seen as working.

In both ways the Kernel module will not be loaded (modprobe zram).

Cheers

Carles Mateo
  • 1,647
  • 7
  • 12