site  contact  subhomenews

EasyPup zram compression in RAM

November 27, 2020 — BarryK

Those who like EasyPup will be pleased that I am working on some enhancements. This has come out of my renewed interest in the multisession-DVD mode, where EasyPup (and most pups) can save the sessions back to the DVD, not involving the internal drives at all.

Yesterday I posted about an enhancement, saving to the DVD using zisofs, which burns the files to the DVD with gzip compression:

https://bkhome.org/news/202011/multisession-dvd-with-zisofs-compression.html

The new goodies haven't stopped there: today I have implemented zram compression in RAM. This is already done in EasyOS. Many of the modes of operation of Puppy, what we call PUPMODEs, have a tmpfs as the top layer of the aufs layered filesystem. tmpfs is a filesystem that runs in RAM. Multisession-DVD mode (PUPMODE=77) is an example, where the previous session is copied from the DVD at bootup, to tmpfs in RAM, and at shutdown, or via a "save" icon on the desktop, the user may optionally burn the current session to a new track on the DVD.

Ok, the files are now getting saved compressed in the DVD, but are uncompressed in RAM. By using zram, the files can also be compressed when in the RAM, which greatly increases the available free memory.

EDIT 2020-12-01:
There was a problem with switch_root failing, due to a dumb mistake -- must move the /dev devtmpfs to the main after-switch_root filesystem, prior to the switch. Another potential problem, is added "-b 4096" when created the ext2 filesystem, as if not 4096 block size, mount will fail. Changes in green text...
 

For example, this is code that was in the 'init' script in the 'initrd.gz':

 FREEK=`expr $RAMSIZE \/ 2` #half of physical.
[ $PUPMODE -eq 77 ] && FREEK=`expr $FREEK - 50000` #need some slack.
ALLOCK=`expr $FREEK + $EXTRAALLOCK`
mount -t tmpfs -o size=${ALLOCK}k tmpfs $CREATETMPFS

...where $CREATETMPFS is a folder, in this section of the script it is actually "/pup_rw", the top layer of the aufs filesystem.

Here is what I have today changed it too:

 echo -n "Creating zram0 compressed read-write aufs layer in RAM..." >/dev/console
#20201201 loading folders above will have reduced free ram. assign 3/4 here, but
#that will be uncompressed size. actual ram usage will be 3/8-3/4 depending on compression.
FREEK=$(grep '^MemFree:' /proc/meminfo | tr -s ' ' | cut -f 2 -d ' ')
HALFK=$(($FREEK/2))
QTRK=$(($HALFK/2))
ALLOCK=$(($HALFK+$QTRK))
if [ $PUPMODE -ne 77 ];then #77=multisession-dvd
ALLOCK=$(($ALLOC+$EXTRAALLOCK)) #add on half of swap.
fi
#20201130 zram0 instead of tmpfs...
#mount -t tmpfs -o size=${ALLOCK}k tmpfs $CREATETMPFS #/pup_rw
echo "${ALLOCK}K" > /sys/block/zram0/disksize
busybox mke2fs -L "EASYPUPZRAM0" -m 0 -b 4096 /dev/zram0 > /dev/null
sync
mount -t ext2 /dev/zram0 ${CREATETMPFS} #pup_rw
check_status $?

I may reduce that size a bit more, as, as far as I can determine from a bit of reading, tmpfs has an advantage in claiming only as much RAM as it needs. It would seem the that ext2 filesystem created in zram0 will mean that it has claimed just under half the RAM. However, it looks like zram can page out to a swap partition, if one exists.

So, we might be gaining on the swings, but losing on the roundabouts. I will do a build and play with it, see how it goes.

The new goodies haven't finished, will probably announce the next one tomorrow. 

Tags: easy