I have allocated /dev/ram0:
dd if=/dev/zero of=/dev/ram0 bs=1M count=1024
Now I have 1Gb sitting in memory. How do I free up the allocated space?
I have allocated /dev/ram0:
dd if=/dev/zero of=/dev/ram0 bs=1M count=1024
Now I have 1Gb sitting in memory. How do I free up the allocated space?
I believe, you can use blockdev command, which is available from util-linux package (in Debian)
blockdev --flushbufs /dev/ram0
Using brd for the ramdisk
Using brd for the ramdisk, the only way to free up the RAM is by removing the module from the kernel, or by a reboot. freeramdisk does not work (for me).
Here is an example of usage
apt-get install loadln # Contains "freeramdisk" command
modprobe brd rd_size=$((1024*128)) # 128MB
free -m # total=1000 used=356 free=643
dd if=/dev/zero bs=1M of=/dev/ram0 # writes 128 x 1MB records (as expected)
free -m # total=1000 used=485 free=515
freeramdisk # "freeramdisk: cannot open /dev/ram: No such file or directory"
free -m # total=1000 used=485 free=515
rmmod brd # REMOVE ALL THE RAM DISKS
free -m # total=1000 used=358 free=641
There doesn't seem to be an easy way to determine the original size of the ramdisk other than by using dd to read the device until failure. However, given these devices are implicitly small it wouldn't take long to do this. Thus a "quick reset" command can be created:
resetramdisk() {
mb=$(dd if=/dev/ram0 bs=1M of=/dev/null 2>&1 | sed -n 's/+.*//p;q')
if test -n "$mb"
then
rmmod brd
modprobe brd rd_size=$((1024*$mb))
fi
}
Using kernel boot-time ramdisk
I believe that these disks can be freed up with freeramdisk, but I don't have a configuration that I can test right now.