Date: Thu, 12 Aug 2004 11:28:14 -0400 From: Paul Mather <paul@gromit.dlib.vt.edu> To: freebsd-questions@freebsd.org Cc: Dan Nelson <dnelson@allantgroup.com> Subject: Re: tmpfs for FreeBSD? Message-ID: <1092324493.83481.39.camel@zappa.Chelsea-Ct.Org> In-Reply-To: <20040812120154.2EF1916A626@hub.freebsd.org> References: <20040812120154.2EF1916A626@hub.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 12 Aug 2004 00:53:15 -0500, Dan Nelson <dnelson@allantgroup.com> wrote: > In the last episode (Aug 11), adp said: > > I'm looking for a ramdisk-style filesystem for FreeBSD that can be > > used for scratch space, e.g., tmpfs in Solaris. The filesystem should > > be able to grow and shrink in memory (and use real disk space as > > needed) depending on the amount of free RAM on the system. I don't > > want just a fixed sized block of memory reserved for /tmp. I will be > > using this for scratch files that are quickly created and then > > destroyed, and will average around 2MB each. We are expecting out tmp > > filesystem to need around 256MB to 512MB on average. > > The best available at the moment is a swap-backed filesystem. It will > consume ram/swap as it grows, but won't release swap space when you > delete files. If you're running 5.*, just put this in rc.conf: > > tmpmfs="YES" > tmpsize="512m" > > and make sure you have at least 512MB of swap, so if it does happen to > grow to full size and then have most of its files deleted, the free > blocks can be pushed out to swap. Alternatively, for 4.x (and 5.x) you can simply have an mfs /tmp entry in /etc/fstab. Here is what I have in /etc/fstab for a 128 MB /tmp on my 4.10-STABLE system: swap /tmp mfs rw,nosuid,-s262144 0 0 On my 5.2-CURRENT system, I have this: md /tmp mfs rw,-s128m 0 0 Note how the device to mount on is "swap" in 4.x and a "md" device in 5.x. Under 4.x, a "df -h" looks something like this: Filesystem Size Used Avail Capacity Mounted on [[...]] mfs:28 124M 29K 114M 0% /tmp and like this under 5.x: Filesystem Size Used Avail Capacity Mounted on [[...]] /dev/md0 124M 12K 114M 0% /tmp The "-s" option in the /etc/fstab mount entry determines the size of the underlying VM device. In the case of the OP, that would be "-s512m" or larger. Make sure there is at least as much swap space to back it. FWIW, in 5.x you can also use a malloc-backed md device for a true RAM disk. Also, under 5.x, you can use a vnode-backed md device to use a large regular file as underlying backing storage. This would be handy, I presume, if you didn't want lots of your swap consumed by /tmp usage. In 4.x, this would be accomplished via vn devices. Be careful of the mount order when attempting this, though, if you want a virtual /tmp created during boot. See mount_mfs(8) for details and options. Cheers, Paul. -- e-mail: paul@gromit.dlib.vt.edu "Without music to decorate it, time is just a bunch of boring production deadlines or dates by which bills must be paid." --- Frank Vincent Zappa
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1092324493.83481.39.camel>