Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Sep 2015 06:02:51 +0800
From:      Erich Dollansky <erichsfreebsdlist@alogt.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: mdconfig creating file based memory disk
Message-ID:  <20150911060251.5cd303ba@X220.alogt.com>
In-Reply-To: <A646B4C4-04DD-4840-A478-2EB28B0951F9@ccsys.com>
References:  <20150910111034.20b97c41@X220.alogt.com> <A646B4C4-04DD-4840-A478-2EB28B0951F9@ccsys.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi,

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

> > On Sep 9, 2015, at 11:10 PM, Erich Dollansky
> > <erichsfreebsdlist@alogt.com> 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
describing.

> 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.

Erich



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150911060251.5cd303ba>