Ramdisks are physical portions of memory literally dedicated to act as part of your Linux filesystem. Files can be written to this area as if it were a directory on your hard disk, though the hard disk is completely unused. MineOS uses ramdisks to hold the world's chunk-files, allowing the server speedier access to them, in order to relay them to clients faster.
On the original MineOS page, you can see the benefits of ramdisks and a side-by-side comparison of ramdisks vs. non-ramdisk configurations. This is a terrific primer to help understand why ramdisks are Minecraft's friend.
Note about ramdisks obsolescence!
With the ever-decreasing prices of SSDs and the ever-increasing RAM-demands of Minecraft and plugins, the benefits of ramdisks are slowly diminishing (if not almost entirely gone).
At this point in Minecraft and Bukkit development, Minecraft is no longer the high-file-count and low-memory-footprint game it used to be.
Previously, a large world resulted in up to tens or hundreds of thousands of individual files, all of which were tiny in size. Since then, MCRegion addressed this by reducing filecount by a factor of thousands. Slow non-sequential seek times and write times were one of the primary reasons for ramdisks--and now, with Anvil file format and SSDs, this is scarcely a compelling reason to use ramdisks.
Also, before Anvil, disk-representations of a chunk and a block were held within a 8-bit character (2^8). Now that block IDs go up to 4096 (2^12), filesizes of moderate to large worlds are exponentially larger. With a larger disk-footprint comes a larger ramdisk-footprint, making ramdisks again less compelling options.
When possessing the advantage of the above two issues (in the past), but no longer...ramdisks are almost more of a hassle than they are worth megabyte per dollar. At this point (i.e., since Anvil), I do not recommend using ramdisks any more.
Ramfs vs tmpfs
Linux makes a distinction between a RAM filesystem and the temp filesystem. There are numerous practical differences between the two:
- Ramfs will grow dynamically, tmpfs will not
- This means as more and more content is piled into a mounted ramfs, the ramfs is granted additional capacity from physical memory as your worlds need.
- With tmpfs, if your worlds grow larger than your allocated space, Minecraft server will resort to swap space.
- tmpfs uses swap space, ramfs does not
- Swap space is located on a hard disk, which means if a 55MB world grows to 80MB on a 75MB tmpfs ramdisk, Linux pushes the least-used pages of memory to the HD, which results in degraded server performance.
However, ever-expanding ramfs is dangerous if your world expands to infinity--the server just goes down: Minecraft, sshd, MySQL and the webui. There will be no telling which of the services will drop first. Thus, ramfs eliminates the dependability of RAM allocation. Under tmpfs, if the worldsize exceeds the ramdisk size, swapfile will be used and the server will remain up. When swapfile is used, however, performance will degrade greatly, but you will have ample time to close the server properly and safely, assess the appropriate new size, and restart the server.
On the other hand, ramfs allows for the perfect allocation of memory--you never have to allocate more than exactly what is used--but you also have no control over whether it will take up all your space.
Therefore, you must decide which is more suited for your server, based on your Minecraft client population (trusted vs not trusted), your plug-ins (boundary-limited or not), and your available resources.
To change tmpfs to ramfs, simply adjust the /etc/fstab. You can leave the size attribute present if you want, as it will be ignored under ramfs.
Why is tmpfs default?
tmpfs was chosen because it provides the most consistent and reliable operation. In some cases, this results in minimal waste and often it involves more looking after than ramfs. However, in the absolute worst-case scenario, the worst that can happen to a tmpfs-based server is Minecraft crashes, releasing all Minecraft ram back into the system. The worst that can happen in a ramfs-based server is Linux will crash, meaning you may need to physically shut off the server (SSH may be among services closed), changes to MySQL and the Minecraft world will not be committed, and the server will wait indefinitely with no RAM and no operation.
Based on worst-case scenarios, tmpfs seems the clear winner. However, even if your world's border-expansions are dependable (plugin protection or trust in your population), ramfs has some downsides. Using addons like pigmap use a lot of memory. Even if your world size is greatly under your limit, other programs may soak it all up, which may result in the same outcome. Under tmpfs, however, size overages or memory over-extending will only result in decreased performance in swapfile--which is easily detectable and non-fatal.
|Example Scenario||100MB/100MB tmpfs/swap||ramfs|
|world size = 80MB||100MB tmpfs ramdisk||80MB ramdisk|
|world size = 105MB||100MB/5MB tmpfs/swap used, decreased performance||105MB ramdisk|
|world size = 205MB||100MB/100MB tmpfs/swap used, Minecraft crashes at 201MB||205MB ramdisk|
|java heap + world size > physical ram||Minecraft won't start||services crash: Minecraft/MySQL/sshd/web-ui|
Create a ramdisk (Steps)
To make a permanent ramdisk, add these entries to the bottom of your /etc/fstab, changing 100000k (100MB) to whatever value you wish to use.
none /mnt/ramdisk tmpfs rw,relatime,size=100000k 0 0
Use Ramdisk for Minecraft
Below your ramdisk fstab entry, bind the live server directory to the ramdisk.
/mnt/ramdisk /home/mc/servers bind defaults,bind 0 0
Create a ramdisk (Explanation)
It is important to understand how Linux mounts work to fully understand how a ramdisk works, and how it logically stores a ramdisk within your base filesystem.
Creating a ramfs
mount -t ramfs ramfs /mnt/ramdisk
Creating a tmpfs
mount -t tmpfs -o size=150m tmpfs /mnt/ramdisk
Understanding the command
mount -t vfs -o size=XXm dev /mnt/loc
- mount - program that takes a block device, such as an hd, cdrom, or ram, and gives it a logical location (e.g., /mnt/sda1, /mnt/cdrom)
- -t vfs - specifies the virtual filesystem
- -o - specifies additional options about mounting
- size=XXm - size determined as XXm of ram
- dev - the physical device being mounted (RAM)
- /mnt/loc - the desired path for the allocated space
Verifying the mount
# mount /dev/sda1 on / type reiserfs (rw) devpts on /dev/pts type devpts (rw) none on /sys type sysfs (rw) none on /proc type proc (rw) ramfs on /mnt/ramdisk type ramfs (rw,size=50m) # df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 3.0G 933M 1.9G 33% /
Note how unlike tmpfs, ramfs is not listed under 'df' (diskfree). This is because ramfs will never hit capacity until your entire server is exhausted of available memory.
# mount /dev/sda1 on / type reiserfs (rw) devpts on /dev/pts type devpts (rw) none on /sys type sysfs (rw) none on /proc type proc (rw) tmpfs on /mnt/ramdisk type tmpfs (rw,size=50m) # df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 3.0G 933M 1.9G 33% / tmpfs 50M 0 50M 0% /mnt/ramdisk
Reinstalling MineOS CRUX is one approach to removing a ramdisk, though it is often overkill due to the ease of toggling them on/off. Just as adding ramdisks require lines to be added, removing ramdisks require the removal or commenting-out of these lines.
To disable ramdisks, comment out these entries to the bottom of your /etc/fstab.
#none /mnt/ramdisk tmpfs rw,relatime,size=100000k 0 0 #/mnt/ramdisk /home/mc/servers bind defaults,bind 0 0
Before doing this, be sure to make a backup of any servers! In addition, turn off the option for all servers (if enabled) to Restore on Reboot, which is a ramdisk-only relevant feature.
Upon restarting, /home/mc/servers should be empty of your worlds (directories may exist for each server), which should be restored once each.