mdconfig creating file based memory disk

Erich Dollansky erichsfreebsdlist at
Thu Sep 10 22:03:07 UTC 2015


On Thu, 10 Sep 2015 13:44:18 -0400
"Chad J. Milios" <milios at> wrote:

> > On Sep 9, 2015, at 11:10 PM, Erich Dollansky
> > <erichsfreebsdlist at> wrote:
> > 
> > I just came across a simple question. What will happen when I create
> > two memory disks using the same file?
> > 
> > Example:
> > 
> > mdconfig -f /usr/home/swap/swapfile -u 0
> > mdconfig -f /usr/home/swap/swapfile -u 1
> > 
> > and then I do a
> > 
> > swapon /dev/md0
> > swapon /dev/md1
> > 
> > It gives me double the size of 'swapfile' as swap space. It is
> > obvious to me that this must fail.
> > 
> > Shouldn't there be a note in the documentation?
> Perhaps, but if we documented every way in which FreeBSD allows one
> to shoot oneself in the foot, the docs would probably more than
> triple in size. :)
> This is an interesting experiment but I can't imagine anyone inviting
> the danger while actually expecting to get away with such a

the experiment started after I did not find any information if mdconfig
will lock the file. If the file would be locked, nothing would happen.
The problems happens with any other scenario in which a file is used as
the base for the memory disk. It just happened that I needed the swap.

The problem is that the software using the memory disk has to way to
find out if it is the sole user. It is just the scenario you are

> Imagine the following analog: a hypothetical database software which
> mmap()s a file possibly larger than physical memory to rely on the VM
> So without inspecting the relevant kernel source myself, based on the
> little experiment you've conducted, I can imagine the swap perhaps

Swap is not the problem. Swap must rely on the space it got assigned to
have it exclusively.
> On the outset of the experiment you describe, my expectation was
> almost certain spectacular failure. Anything else actually is quite
> curious and if such a config doesn't just burst right into flames I
> consider it quite a testament to sound *nix engineering. I'd be
> interested to hear someone exercise it with more swapping out and
> paging in of data and verifying the data and semantics.

I did this other test with normally mounted file systems. As it is one
file, what happens in one file system, is mirrored into the other one.
mdconfig is the bottle neck. If mdconfig would lock the file for
exclusive access, this would not happen. I should have a lock at the
sources when time permits this.


More information about the freebsd-questions mailing list