3

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.

6
  • 2
    Can you check with fuser or lsof if any process has the files still opened? In this case, only the directory entry is removed, the file data is still available until all processes have closed the file. Can you reproduce the problem with exactly the command shown in the question? If not, show the real command you use. Commented Sep 30, 2024 at 9:25
  • 1
    have you try to exec sync after remove (to flush cached operations)? (and sleep for few seconds of course) Commented Sep 30, 2024 at 9:46
  • With Linux use the already existing ramdisk /dev/shm. It does not have the problem described above. Commented Sep 30, 2024 at 19:52
  • Thanks bodo, lsof and fuser only show the currently open mp4 and mkv being accessed. This is the full command that I'm running, except ffmpeg is a bit longer (setting codecs and such), however the same happens with this command. Commented Oct 1, 2024 at 11:03
  • 1
    @burny, have you try my idea? Commented Oct 2, 2024 at 12:56

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.