1

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?

Sandra
  • 10,303
  • 38
  • 112
  • 165
  • 1
    FYI, MAKEDEV is obsolete. These days udev automatically creates the dev node when the driver is loaded. – psusi Dec 31 '12 at 15:30
  • @psusi Very interesting. How is that done with udev? When I boot I don't have `/dev/ram*` so doing `fdisk -l /dev/ram1` fails. – Sandra Dec 31 '12 at 17:12
  • The kernel notifies udev when new devices are detected, and it creates the dev node. Actually these days most distributions mount /dev as a devtmpfs, where the kernel internally automatically creates the node, and notifies udev for any additional processing. – psusi Dec 31 '12 at 21:22
  • @psusi I am not sure I understand. What would you type to get the ramdisk? – Sandra Dec 31 '12 at 22:25
  • You don't have to type anything; as long as the ramdisk driver is loaded, the dev nodes exist. If you had to create them with MAKEDEV then your udev/devtmpfs are not working correctly. – psusi Jan 01 '13 at 02:33
  • Is there a particular reason you want a block device to access RAM (as opposed to using `malloc()` in your program)? – voretaq7 Oct 09 '13 at 19:25

3 Answers3

4

mkfs -q /dev/ram1 X where X is the size in KB. You'd want 1048576 for 1GB.

Chris S
  • 77,945
  • 11
  • 124
  • 216
4

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.

DerfK
  • 19,493
  • 2
  • 38
  • 54
  • When I do that, I can see in `dmesg` that the `ramdisk_size=` have been passed, but `/dev/ram*` all remains 16MB. I have tried to set it to 99MB on my 8GB ram server, and it is still 16MB. – Sandra Dec 31 '12 at 17:14
  • 1
    @Sandra It may be that you'll need to use something like `dd if=/dev/zero of=/dev/ram1 bs=1024 count=1000000` to allocate the full GB before you do anything else with the device. Also, I'm not sure that I'd trust `fdisk` with the ramdisk since they're not partitionable normally. – DerfK Dec 31 '12 at 17:24
  • Interesting idea. Didn't work however. `16777216 bytes (17 MB) copied, 0.051657 s, 325 MB/s` – Sandra Dec 31 '12 at 17:53
  • 1
    The size is dynamically grown to fit as much as you write to it, like a file. The ramdisk_size argument has been obsolete for years. You also most certainly can unload the ramdisk module, or free a particular ramdisk memory with `blockdev --flushbufs /dev/ramX` – psusi Jan 01 '13 at 02:52
  • I'm not imagining that I have a freeramdisk command lying around. – joshudson Feb 26 '17 at 17:30
2

It looks like you're more looking for something like mount -t tmpfs -o size=1024m tmpfs mount_directory

Heis Spiter
  • 638
  • 9
  • 17