Linux – Possible to set size of ram disk

block-devicecentosfedoralinuxramdisk

When I do

yum install MAKEDEV
MAKEDEV ram
fdisk -l /dev/ram

I get the that it is 16MB.

I am using MAKEDEV to get a block-device instead of tmpfs.

Question

Is it possible to set it to e.g. 1GB?

Best Answer

The block device driver for ramdisks has the size set at the time the driver loads, using the ramdisk_size= parameter to specify the number of blocks (default blocksize = 1024 bytes, see ramdisk_blocksize= as well) to allocate to each ramdisk. If you're loading it as a module, you can use that parameter when loading the module, otherwise if it's built into the kernel you'll have to boot that system as a kernel option.

It appears that at some point in 2.6 the ramdisk driver was changed so that the first time you accessed it, the size of the ramdisk was set permanently (rather than using the kernel option).

Regarding setting it to 1GB, I think it would be possible but once the ramdisk has been accessed it will occupy all 1GB in RAM and cannot be swapped out (unlike tmpfs which can swap if necessary). There is also no way to unload the ramdisk and free the memory without a reboot.