Page MenuHomeFreeBSD

Fall back to md(4) in rc.initdiskless if tmpfs(5) is not available

Authored by stevek on Jul 28 2017, 3:40 AM.



Check if tmpfs(5) is loaded in the kernel. If it is not, try to load it.
If tmpfs(5) is not available, use md(4) instead.

This is a follow-up to D11106 after some e-mail discussions with ngie.

Test Plan

Test on 3 variants of kernels (with md always compiled in):

  1. with options TMPFS in the kernel
  2. with tmpfs.ko available in the file system
  3. without options TMPFS or tmpfs.ko in the file system

All three work correctly.

Diff Detail

rS FreeBSD src repository
Lint OK
No Unit Test Coverage
Build Status
Buildable 10720
Build 11118: arc lint + arc unit

Event Timeline

stevek created this revision.Jul 28 2017, 3:40 AM
stevek edited the summary of this revision. (Show Details)Jul 28 2017, 3:41 AM
stevek added reviewers: brooks, ngie.
stevek updated this revision to Diff 31293.Jul 28 2017, 3:43 AM

Edited comment for load_tmpfs

ngie added inline comments.Jul 28 2017, 4:43 PM

The multiplier here seems incorrect (in the previous commit as well) for tmpfs -- the comments below claim that the value should be in 512 byte sectors (this value is 8 times higher than it should be):

282 # - calculate memory filesystem sizes.  If the subdirectory (prior to
283 #   NFS remounting) contains the file 'md_size', the contents specified
284 #   in 512 byte sectors will be used to size the memory filesystem.  Otherwise
285 #   8192 sectors (4MB) is used.
stevek added inline comments.Jul 28 2017, 5:13 PM

I think that comment block needs updating, as it doesn't use 8192 sectors for the default. See create_md below where it uses md_size=10240 if md_size_$1 is empty.

Why do you think that the value is 8 times higher than it should be? And which value are you referring to here?

From the mdmfs(8) man page:

-s size
        Specify the size of the disk to create.  This only makes sense if
        -F is not specified.  That is, this will work for the default
        swap-backed (MD_SWAP) disks, and the optional (-M) malloc(9)
        backed disks (MD_MALLOC).

Looking at the mdmfs sources, the -s flag is passed on to newfs.

According to newfs(8) man page:

-s size
        The size of the file system in sectors.  This value defaults to
        the size of the raw partition specified in special less the
        reserved space at its end (see -r).  A size of 0 can also be used
        to choose the default value.  A valid size value cannot be larger
        than the default one, which means that the file system cannot
        extend into the reserved space.


-S sector-size
        The size of a sector in bytes (almost never anything but 512).

So if we're using tmpfs, we need to convert the md_size to number of bytes. Since sector size is 512 for mdmfs usage, we multiply the size by 512.

Also note that I have verified this is correct with empirical data.

ian added a subscriber: ian.Sep 8 2017, 10:39 PM
ian added inline comments.

It's even more complicated than all that. mdmfs doesn't pass the size arg to newfs at all, it just lets newfs use the size of the device.

mdmfs does pass the size arg to either mdconfig or mount -t tmpfs, and both of those recipients know how to interpret the usual size suffixes (10m, 30G, etc). Where it gets weird, but nobody has complained for years, is when the -s arg has no suffix the interpretation changes based on the md-device arg type, mdconfig treats it as a count of 512-byte "sectors", and tmpfs treats it as bytes.

So now to get it right, this script code has to sniff out possible size suffixes.

I have an alternative patchset from years ago that just moves all this functionality into mdmfs. It lets you use "auto" as the md-device value, and it will use tmpfs is available or mdconfig if not. I can dust it off and see if it still applies if there's any interest. (The main point of that change was that it lets a user set a new mfs_type var in rc.conf to 'md', 'tmpfs' or the default value is 'auto'.)

ian added a comment.Sep 10 2017, 1:52 AM

I propose as an alternate solution to this problem. I developed it back in 2014, but it was dismissed as unnecessary when I asked for comment on it, so I mothballed it. I've dusted it off and re-tested it, still seems to work fine.

stevek abandoned this revision.Oct 26 2017, 6:37 PM

D12301 takes care of things better.