|
|
This document is available in: English Castellano Deutsch Francais Nederlands Portugues Russian Turkce |
by Mark Nielsen About the author: Mark works as an independent consultant donating time to causes like GNUJobs.com, writing articles, writing free software, and working as a volunteer at eastmont.net. Content: |
Abstract:
RamFs is a very simple file system with some interesting aspects. It is a new things in the 2.4 Kernel.
What is a RamDisk? A RamDisk is a portion of memory that you allocate to use as a partition. Or, in other words, you take some of your memory and pretend it is a hard drive that you can format, mount, save files to etc.
There are two types of ramdisks we will be talking about. The first is a ramdisk that you can format and mount. The second is a ramdisk you cannot format, but has some nice features. Here is a breakdown:
The old /dev/ram1 approach:
To use your kernel 2.0 and 2.2 ramdisks, just type three commands:
mkfs -t ext2 /dev/ram1 mkdir -p /RAM1 mount /dev/ram1 /RAM1as root, and you are done. On most systems the size is limited to 4 megs. This can be changed at boot-time or if you recompile the kernel, but read my old article for that. You can also add more like this,
mkfs -t ext2 /dev/ram2 mkdir -p /RAM2 mount /dev/ram2 /RAM2
Very simple. Make a directory and mount ramfs there.
mkdir -p /RAM1 mount -t ramfs none /RAM1If you want a second one, very simple. Make a directory and mount ramfs there.
mkdir -p /RAM2 mount -t ramfs none /RAM2
Here is an example of how to make a 10 meg ramdisk.
mkdir -p /RAM1 mount -t ramfs none /RAM1 -o maxsize=10000Taken directly from http://www.linuxhq.com/kernel/v2.4/patch/patch-2.4.3-ac2/linux.ac_Documentation_filesystems_ramfs.txt.html
+ ramfs - An automatically resizing memory based filesystem + + + Ramfs is a file system which keeps all files in RAM. It allows read + and write access. In contrast to RAM disks, which get allocated a + fixed amount of RAM, ramfs grows and shrinks to accommodate the + files it contains. + + You can mount the ramfs with: + mount -t ramfs none /mnt/wherever + + Then just create and use files. When the filesystem is unmounted, all + its contents are lost. + + NOTE! This filesystem is probably most useful not as a real + filesystem, but as an example of how virtual filesystems can be + written. + +Resource limits: + +By default a ramfs will be limited to using half of (physical) memory +for storing file contents, a bit over that when the metadata is +included. The resource usage limits of ramfs can be controlled with +the following mount options: + + maxsize=NNN + Sets the maximum allowed memory usage of the +filesystem to NNN kilobytes. This will be rounded down to a multiple +of the page size. The default is half of physical memory. NB. unlike +most of the other limits, setting this to zero does *not* mean no +limit, but will actually limit the size of the filesystem data to zero +pages. There might be a use for this in some perverse situation. + + maxfilesize=NNN + Sets the maximum size of a single file on the +filesystem to NNN kilobytes. This will be rounded down to a multiple +of the page size. If NNN=0 there is no limit. The default is no limit. + + maxdentries=NNN + Sets the maximum number of directory entries (hard +links) on the filesystem to NNN. If NNN=0 there is no limit. By +default this is set to maxsize/4. + + maxinodes=NNN + Sets the maximum number of inodes (i.e. distinct +files) on the filesystem to NNN. If NNN=0 there is no limit. The +default is no limit (but there can never be more inodes than dentries).
Ram is cheap these days. I got 128 megs of ram for $120 recently, and I imagine the price will continue to drop. For 128 megs of ram, I can easily fit any of my webservers into it. If my webserver has huge files, I can configure httpd.conf to look a another directory not in the ram disk. My DNS server is very small. My largest database server is only 28 megs. Considering the fact you can get 1 gig memory computers these days real cheap, I think it would be cool to run everything I have in ram. The only tricky part with the database server is that you should first save all writes to a separate database server before writing to your database server in ram. This is slow, but considering most of the time you are reading and not writing, it should increase performance. Perhaps if we could mirror a ram disk to a hard drive
I already explained this in my other article, so please read it here: http://www.gnujobs.com/mark/articles/Ramdisk.html#Example. Just replace these commands
### Make the ramdisk partitions /sbin/mkfs -t ext2 /dev/ram0 /sbin/mkfs -t ext2 /dev/ram1 /sbin/mkfs -t ext2 /dev/ram2 ### Mount the ramdisks to their appropriate places mount /dev/ram0 /home/httpd/cgi-bin mount /dev/ram1 /home/httpd/icons mount /dev/ram2 /home/httpd/htmlwith these commands (increase the number if 10 megs isn't good enough):
mount -t ramfs none /home/httpd/cgi-bin -o maxsize=10000 mount -t ramfs none /home/httpd/icons -o maxsize=10000 mount -t ramfs none /home/httpd/html -o maxsize=10000
There are three problems combining a ramdisk with a hard drive partition.
raiddev /dev/md3 raid-level 1 nr-raid-disks 2 nr-spare-disks 0 chunk-size 4 persistent-superblock 1 device /dev/hdb6 raid-disk 1 device /dev/ram3 raid-disk 0Then I executed,
mkraid /dev/md3 mkfs -t ext2 /dev/md3 mkdir -p /RAID1 mount /dev/md3 /RAID1Problem, upon reboot, the ramdisk is going to get messed up. Thus, on reboot,
raidstart /dev/md3 raidhotadd /dev/md3 /dev/ram3 mount /dev/md3 /RAID1Now remember, if you didn't reconfigure the old ramdisks to be larger than 4 megs, it is pointless for your hard drive partition to be larger than 4 megs.
It would be really cool to have a mirrored raid with 3 partitions. 1 being the ramdisk and 2 being hard drive paritions and to also make it so only the ramdisk is read for read cycles. I don't know if it is possible to isolate reads to only one of the partitions in a raid, but it would be cool if you could.
Thanks to Katja for some help!
Copyright © 4/2001 Mark Nielsen
Article Version 1.3 : Date Last Changed Sat May 19
06:04:06 2001
|
Webpages maintained by the LinuxFocus Editor team
© Mark Nielsen, FDL LinuxFocus.org Click here to report a fault or send a comment to LinuxFocus |
2001-06-29, generated by lfparser version 2.16