Page MenuHomeFreeBSD

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

Authored by stevek on Jul 28 2017, 3:40 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Mar 11, 9:57 PM
Unknown Object (File)
Jan 6 2024, 12:46 PM
Unknown Object (File)
Dec 20 2023, 4:20 AM
Unknown Object (File)
Dec 14 2023, 8:42 PM
Unknown Object (File)
Nov 26 2023, 5:07 AM
Unknown Object (File)
Nov 23 2023, 4:47 AM
Unknown Object (File)
Nov 22 2023, 12:25 PM
Unknown Object (File)
Nov 22 2023, 12:20 PM

Details

Reviewers
brooks
ngie
Summary

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

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 10720
Build 11118: arc lint + arc unit

Event Timeline

stevek added reviewers: brooks, ngie.

Edited comment for load_tmpfs

etc/rc.initdiskless
215

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.
etc/rc.initdiskless
215

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 inline comments.
etc/rc.initdiskless
215

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

I propose https://reviews.freebsd.org/D12301 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.

D12301 takes care of things better.