Discussion:
tmpfs for FreeBSD?
adp
2004-08-12 04:50:27 UTC
Permalink
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.
Dan Nelson
2004-08-12 05:53:15 UTC
Permalink
Post by adp
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.
--
Dan Nelson
***@allantgroup.com
Paul Mather
2004-08-12 15:28:14 UTC
Permalink
Post by Dan Nelson
Post by adp
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
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: ***@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
Loading...