ramdisk(HW) 19 June 1992 ramdisk(HW) Name ramdisk - memory block device Description The ramdisk device driver provides a block interface to memory. A ramdisk can be used like any other block device, including making it into a file- system using mkfs(ADM). There are eight ramdisks available. The characteristics of a ramdisk file are determined by its minor device number. The bits in the minor device number encode its size, longevity, and which of the eight possible ramdisks it is. The three low-order bits of the minor device number determine which of the eight ramdisks is being accessed. The next four bits of the minor device number determine the size of the ramdisk. The size of a ramdisk must be a power of 2, and must be at least 16K. Since 4 bits are available, there are 16 possible sizes, starting at 16K and doubling every time the size indicator is incre- mented, to produce possible sizes of 16K, 32K, 64K, and up. The high-order bit is a longevity indicator. If set, memory is permanently allocated to that ramdisk, and can be deallocated only by rebooting the system. Permanent ramdisks can only be allocated by the super user. However, once a permanent ramdisk is allocated (by opening it), it can be read and written by anyone having the appropriate permis- sions on the ramdisk inode. If clear, the ramdisk is deallocated when no processes have it open. An unmounted ramdisk will be deallocated immediately when it is closed. To create an easily removable, but semi-permanent ramdisk, use a separate process to keep the device open for as long as necessary. Since a complete set of ramdisks (8) would consume 256 inodes if all pos- sible minor numbers were used, only one example 16K ramdisk (/dev/ram00) is created when the system is installed. The system administrator can check this existing file to determine the major device number for any other required ramdisks. All ramdisks will use the same major device num- ber. The following table shows how the minor device number is constructed: Example Minor Device Number Construction _________________________________________________________________________ Description Longe- Size (see Ram Minor vity next table) Disk No. Device Number _______________|________|______|_____|_____|___|______|_____|___|________ 16K (#1) (Tem-| 0 | 0 | 0 | 0 | 0| 0 | 0 | 1| 1 porary) | | | | | | | | | 16K (#1) (Per-| 1 | 0 | 0 | 0 | 0| 0 | 0 | 1| 129 manent) | | | | | | | | | 64K (#0) (Tem-| 0 | 0 | 0 | 1 | 0| 0 | 0 | 0| 16 porary) | | | | | | | | | 512K (#7) | 1 | 0 | 1 | 0 | 1| 1 | 1 | 1| 175 (Permanent) | | | | | | | | | The contents of the size field and the corresponding ramdisk size is shown in the next table. ________________________________________________________________________ Size Bits Ramdisk Size _______|_____________|____________|___________|_________________________ 0 | 0 | 0 | 0 | 16K 0 | 0 | 0 | 1 | 32K 0 | 0 | 1 | 0 | 64K 0 | 0 | 1 | 1 | 128K 0 | 1 | 0 | 0 | 256K 0 | 1 | 0 | 1 | 512K 0 | 1 | 1 | 0 | 1M 0 | 1 | 1 | 1 | 2M 1 | 0 | 0 | 0 | 4M 1 | 0 | 0 | 1 | 8M 1 | 0 | 1 | 0 | 16M 1 | 0 | 1 | 1 | 32M 1 | 1 | 0 | 0 | 64M 1 | 1 | 0 | 1 | 128M 1 | 1 | 1 | 0 | 256M 1 | 1 | 1 | 1 | 512M To create a ramdisk, follow these steps: 1. Create the device node. You must first create the device that the ramdisk will reside on. It has the form: mknod devicename [b|c] 31 minordevicenumber ``b'' is for blocked devices and is the one you will use. ``31'' is the major number for this type of device. The minor number is derived from the table above. The minor number is the sum of the three attribute columns. Longevity: permanent = 128 non-permanent = 0 Size: 16K = 0 128K = 24 1 Meg = 48 8 Meg = 72 32K = 8 256K = 32 2 Meg = 56 16 Meg = 80 64K = 16 512K = 40 4 Meg = 64 32 Meg = 88 Ramdisk number: 0 through 7 Note: There are only 8 devices available. Two different size devices may not share the same num- ber. For example, to create a 64K permanent ramdisk, the minor number could vary from 144 to 151. If the disk number was 1, the mknod command would be: mknod /dev/ram64 b 31 145 2. Make a filesystem. This creates a filesystem on the the ramdisk. In this example, mkfs(ADM) has the form: mkfs devicename sizeoffileinBSIZEblocks In this example, the command to create a 64K filesystem would be: mkfs /dev/ram64 64 3. Mount the filesystem. This mounts the selected device on the specified mountpoint. It has the form: mount devicename mountpoint In order to mount the example 64K ramdisk on /mnt the command would be: mount /dev/ram64 /mnt To make a filesystem on a non-permanent ramdisk, the device file must be held open between the mkfs and the mount(ADM) operations. Otherwise, the ramdisk is allocated at the start of the mkfs com- mand, and deallocated at its end, before it can be mounted. Once the ramdisk is mounted, it is open until it is unmounted. The following shell fragment shows one way to use mkfs on a non- permanent 512K ramdisk, and then mount it: ( /etc/mkfs /dev/ram40 512 /etc/mount /dev/ram40 /mnt ) < /dev/ram40 The procedure is executed in a sub-shell taking its standard input from /dev/ram40 in order to keep /dev/ram40 open between its crea- tion and the time at which it is mounted. Notes Ramdisks must occupy contiguous memory. If free memory is fragmented, opening a ramdisk may fail even though there is enough total memory available. Ideally, all ramdisks should be allocated at system startup. This helps prevent the ramdisks themselves from fragmenting memory. Ramdisks are geared towards use in specialized applications. In many cases, you will notice a decrease in system performance when ramdisks are used, because UNIX can generally put the memory to better use elsewhere. File /dev/ram00 See also mkfs(ADM), mknod(C), mount(ADM) Value added ramdisk is an extension of AT&T System V provided by The Santa Cruz Operation, Inc.