Create variable sized RAM-backed file systems (Ext4 and Btrfs)

block-devicefilesystemsramdisktmpfs

For benchmarking purposes I need to format and mount variable sized ram-backed block devices with Ext4 and Btrfs. Unfortunately the only solution I have come across uses ramdisks which seem to be inflexible (they are all the same size).

The only other solution I have thought of is to mount a loopback file in tmpfs using and then format this file with Ext4 or Btrfs.

Are there any other ram-backed block devices other than the ancient ramdisk?

Best Answer

You can try zram. It's compressed in-memory block device, which can free unused blocks of ext4 filesystem or any other filesystem which supports trim/discard.

But zram is on staging area in kernel, so probably your default distro kernel doesn't have it. Also, discard support for zram is relatively new and I'm not sure if it is intergated to some released kernel version.

And, of course there'll be some cpu overhead for compression/decompression, so it may not meet your testing requirements.