One can make a ramdisk in Linux by modprobe brd rd_nr=1 rd_size=$SizeInKB (creates uncompressed /dev/ram0) or by modprobe zram && echo $SizeInBytes >| /sys/block/zram0/disksize (creates compressed /dev/zram0).
These types of ramdisk are both unable to be paged out to a swap device and thus limited to a fraction of the physical memory.
To make a swappable in-memory block device which can grow larger than physical memory, one can use
mkdir -p /run/ramfs && mount -t tmpfs -o size=0 ramfs /run/ramfs && \
truncate --size $SizeInBytes /run/ramfs/ramfs && losetup -f && losetup -f /run/ramfs/ramfs.
This is uncompressed but can be combined with zswap to make it compressed (at least some in-memory part of it).
But this involves the overhead of the tmpfs filesystem and the loopback device.
Is there a better method to make a pageable/swappable (possibly compressed) in-memory block device that avoids the overhead of a filesystem below the block layer ?