I have a ramdisk mounted to /ram
which typically holds temporary data that I know don’t need saved. The filesystem of the ramdisk is f2fs
, created by zram-generator
with this configuration:
# /etc/systemd/zram-generator.conf
[zram0]
zram-size = ram
fs-type = f2fs
compression-algorithm = zstd
mount-point = /ram
options = nosuid,nodev,noatime,X-mount.mode=1777,X-mount.group=ramuser,atgc,gc_merge,lazytime
It will mount with these options:
$ findmnt /ram
TARGET SOURCE FSTYPE OPTIONS
/ram /dev/zram0 f2fs rw,nosuid,nodev,noatime,lazytime,background_gc=on,gc_merge,discard,discard_unit=block,user_xattr,inline_xattr,acl,inline_data,inline_dentry,flush_merge,barrier,extent_cache,mode=adaptive,active_logs=6,alloc_mode=default,checkpoint_merge,fsync_mode=posix,atgc,memory=normal,errors=continue
This works for all my purposes as I intend. (Typically, I have a lot of text files which benefit greatly from the compression.)
Now, I have a few video files which I want to convert to another format. I don’t need them on my disk and I am fine with them being lost after a power outage, so I have them only in memory.
For the conversion, I have this for loop:
for i in *.mkv; do
ffmpeg -i "${i}" "${i:r}.mp4" # convert mkv to mp4
rm -v "${i}" # remove original
done
(The ffmpeg command is abbreviated, it works.)
There are 6 mkv files which are 2 GB each, so it occupies 12 GB. This is fine. The converted mp4s are roughly the same size, so during the loop, it should use at maximum 12+2 GB. The -v
switch for rm
shows the removal of the file after the conversion.
However, the memory fills up and the system breaks at some point. When killing the loop (with Ctrl+c), the memory is finally freed. So, it does not purge the old mkv files until the loop has finished.
Does this for i in *.mkv
hold all files, so that they can’t be removed and are purged only after the loop has finished? lsof
does not show the old files being still accessed.
The file is removed (ls
doesn’t show it) but it seems like it’s not purged.