I try Peppermint OS (a distro based on Lubuntu) on live usb. I check ram by the command

free -h

and the result is

peppermint@peppermint ~ $ free -h
              total        used        free      shared  buff/cache   available
Mem:           3.8G        1.0G        1.0G        866M        1.8G        1.8G
Swap:          5.7G         51M        5.7G

My usb is 4G, my ram is 4G.

Why swap is 5.7G? And does this happen in any other ubuntu based distros?

As I understand, trying ubuntu distros on live usb does not create swap on hard disk, so I considered 3 cases:

  1. I already created a swap of 4G before (when I created dual boot), and this swap is used, but here swap is 5.7G

  2. Another swap is created on the usb, but my usb only has 4G; so why swap is 5.7G?

  3. A swap of 1.7 G is created on usb, and 5.7G is the result of combining the two swaps. But I check my usb is 2.5G free and the linux iso in it is about 1.3G, so cannot have a swap of 1.7G on my usb

As sourcejedi suggested, here is the result of cat /proc/swaps:

peppermint@peppermint ~ $ cat /proc/swaps
Filename                Type        Size    Used    Priority
/dev/sda5               partition   3998716 0      -2
/dev/zram0              partition   1006892 26320   5
/dev/zram1              partition   1006892 26044   5
  1. So it has detected your 4GB (decimal) swap partition, and automatically enabled it. I think this is fairly common. It is probably from common Ubuntu code.

  2. It is also using 2 x 1GB of zram swap. Data swapped to zram is compressed, and stored in RAM. This can be particularly useful on low-memory systems. Android can use a similar (same?) approach, and so does Windows 10 on low-memory systems.

This is the result of Peppermint including the zram-config package from Ubuntu. As far as I know, the original Ubuntu Desktop does not install zram-config by default.

You can see the code in /usr/bin/init-zram-swapping. It currently creates one zram device per CPU (for parallel compression or decompression).

# 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}
  • I searching about zram and seem like there're many things to figure out. I simply guest: zram is a small partition in RAM that compresses some applications (that is not using) for quick access (since in RAM) when need (of course need decompress to use) ; and actual size of zram partition in RAM is much smaller than capacity it can compress. In my case, the zram partition can compress maximum about 1.7 GB. And the 5.7G above is about 4G of swap I created and this 1.7G. Is that right? If so, how to know actual size of zram partition. – ydhhat Jun 14 at 19:32
  • @ydhhat I think you are about right. I don't know if there is any convenient tool to show statistics, but you can run cat /sys/block/zram*/mm_stat and look at the field definitions for mm_stat in git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/… – sourcejedi Jun 14 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.