5

I am having trouble to deallocate RAMdisk in Linux.

I think that blockdev --flushbufs /dev/ram0 used to work in the past.

But now:

cat /dev/urandom > /dev/ram0

md5sum /dev/ram0
c71df700969640324b201ae5f7a96c41  /dev/ram0

blockdev -v --flushbufs /dev/ram0
flush buffers succeeded.

md5sum /dev/ram0
c71df700969640324b201ae5f7a96c41  /dev/ram0

It did not wipe the RAMdisk. I tested in recent Linux 4.14 and 5.4. Am I missing something?

Vlastimil Burián
  • 27,586
  • 56
  • 179
  • 309
  • 1
    You might be interested in this: https://man.cx/freeramdisk(8) – KGIII Aug 24 '20 at 22:24
  • 1
    you say kernel 4.14 and 5.4. Isn't this all *tmpfs* now? And does *flushing buffer* of a block device have any relevance in this context? A buffer is not the contents of tmpfs. – ron Sep 14 '20 at 17:01
  • `ls -l /dev/ram0` please. Is it actually a block device? The reason I'm asking is because the answer here definitely still works for me on kernel 4.9.35-v7+ (Raspberry Pi) – roaima Sep 14 '20 at 20:05
  • Yes, `/dev/ram0` is a block device. I looked into it more and found that BLKFLSBUF ioctl support for ramdisk was removed in 4.10 [link](https://www.spinics.net/lists/linux-block/msg05934.html). There is also something about implementing discard [link](https://www.spinics.net/lists/linux-block/msg05986.html) but `blkdiscard /dev/ram0` does not work for me in 5.4.61 – John Lee McMahon Sep 15 '20 at 06:18
  • How and where does the shown code de-allocate and free the ram disk? – planetmaker Sep 20 '20 at 06:10

1 Answers1

1

Currently there does not seem to be any other way to deallocate Linux ramdisk except using ramdisk as a module and removing the ramdisk module.