0

I'm probably misunderstanding something, but it escapes me at this point. So please excuse me if I am asking something that has an obvious answer.

Because I want to save my Pies SD-card I thought I could mount a ramdisk to store temporary files. And to save on RAM memory I thought I could use squashfs to compress the files on the ramdisk.

To test this I did the following:

# install squashfs support
$ sudo apt install squashfs-tools

# view current status
$ free -h
             total       used       free     shared    buffers     cached
Mem:          482M       152M       329M        29M       5.5M        77M
-/+ buffers/cache:        70M       411M
Swap:           0B         0B         0B
$ df -h
Filesystem                      Size  Used Avail Use% Mounted on
/dev/root                       3.5G 1017M  2.4G  31% /
devtmpfs                        237M     0  237M   0% /dev
tmpfs                           242M     0  242M   0% /dev/shm
tmpfs                           242M   21M  221M   9% /run
tmpfs                           5.0M     0  5.0M   0% /run/lock
tmpfs                           242M     0  242M   0% /sys/fs/cgroup
tmpfs                            96M  2.8M   94M   3% /var/log
tmpfs                           242M  6.0M  236M   3% /tmp
/dev/mmcblk0p1                  128M   63M   66M  49% /boot
tmpfs                            49M     0   49M   0% /run/user/1000

# create the ramdisk
$ sudo mount -t tmpfs -o size=80M squashfs /mnt/ramdisk

# fill the disk
$ yes > /mnt/ramdisk/yes.txt
yes: standard output: No space left on device
yes: write error

I'm using yes because I figured this produces a very compressible file.

But, look at the results:

$ free -h
             total       used       free     shared    buffers     cached
Mem:          482M       233M       249M       109M       5.5M       157M
-/+ buffers/cache:        70M       411M
Swap:           0B         0B         0B
$ df -h
Filesystem                      Size  Used Avail Use% Mounted on
/dev/root                       3.5G 1017M  2.4G  31% /
devtmpfs                        237M     0  237M   0% /dev
tmpfs                           242M     0  242M   0% /dev/shm
tmpfs                           242M   21M  221M   9% /run
tmpfs                           5.0M     0  5.0M   0% /run/lock
tmpfs                           242M     0  242M   0% /sys/fs/cgroup
tmpfs                            96M  2.8M   94M   3% /var/log
tmpfs                           242M  6.0M  236M   3% /tmp
/dev/mmcblk0p1                  128M   63M   66M  49% /boot
tmpfs                            49M     0   49M   0% /run/user/1000
squashfs                         80M   80M     0 100% /mnt/ramdisk
$ ls -al /mnt/ramdisk
total 81924
drwxrwxrwt 2 root root       60 Nov 19 10:31 .
drwxr-xr-x 5 root root     4096 Nov 19 09:12 ..
-rw-r--r-- 1 pi   pi   83886080 Nov 19 10:31 yes.txt
$ wc /mnt/ramdisk/yes.txt
41943040 41943040 83886080 /mnt/ramdisk/yes.txt

The file contains exactly 80 megabytes of data. And the disk uses exactly 80M of RAM. I had expected that the disk would indeed use 80M of RAM, but that the file would contain much more than 80M of data thanks to the compression by squashfs.

What did I miss?

1 Answer 1

1

Squashfs is a read-only filesystem similar to the iso9660 filesystem used on CDs. You create it with the mksquashfs tool and all files you want to include. These are compressed by mksquashfs. The kernel can't write it later. It's not intended for writing. You can overlay a tmpfs on the squashfs but it's not compressed.

You want a plain tmpfs and/or zram/zswap.

3
  • Correct, I want a tmpfs but one that (de)compresses files as needed. zram/zswap is not a filesystem, so that wouldn't work.
    – Mausy5043
    Nov 19, 2016 at 14:16
  • Btrfs and ZFS both seem to have "transparent compression", may be worth looking into.
    – goldilocks
    Nov 19, 2016 at 17:41
  • @Mausy5043: You can put a standard ext2 filesystem on the device Zram offers. Or you can use tmpfs and Zswap, that way the excess pages from tmpfs are automatically compressed when more RAM is needed. I think that's the most elegant solution as it doesn't require you any setup on applications.
    – Janka
    Nov 19, 2016 at 19:41

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.