tmpfs - Handle low memory situations a little better (2)

* When handling pageout daemon requests we want to try to free pages
  directly to the VM page cache or the freeq and not necessarily cycle
  them through active or inactive.

  Shortcutting to the cache/free queues will allow the machine to
  unstick much more quickly which is particularly important on boxes
  with a lot of memory because the pageout hysteresis runs in such a
  large range.

* Greatly improves monster's performance under extreme tmpfs write loads.
kernel - Sync numerous commits from FreeBSD

Synchronize a bunch of commits from the FreeBSD tree.  Commit
ids shown below are from the github FreeBSD repo.

Several commits were not synchronized, the main one being 3c7b39f7b5a4...
(Bring in LSI's latest mps(4) 6Gb SAS and WarpDrive driver, version).
This one needs to be brought in.

One other note, not yet fixed is an issue where the driver configures
many more tags than the disk drive can actually support.  In my test
case, 255 tags for a Seagate SAS disk that really only seems to support
63.  When large numbers of commands are queued, and even sometimes when
not, the drive becomes severely inefficient for reads and writes.  Write
bandwidth that is usually in the ~30-50 MB/s range drops to ~5 MB/s.

Doing a camcontrol to reduce tags to ~16 or so seems to fix the issue.
(camcontrol tags da0 -N 16), but we need a permanent solution for this
problem.

* 56527fa077227f78a92c9ebc6f4f35d1bc3e1c21

  Bring in a number of mps(4) driver fixes from LSI:

    1.  Fixed timeout specification for the msleep in mps_wait_command().
        Added 30 second timeout for mps_wait_command() calls in mps_user.c.

    2.  Make sure we call mps_detach_user() from the kldunload path.

    3.  Raid Hotplug behavior change.

        The driver now removes a volume when it goes to a failed state,
        so we also need to add volume back to the OS when it goes to
        opitimal/degraded/online from failed/missing.

        Handle raid volume add and remove from the IR_Volume event.
    4.  Added some more debugging information.

    5.  Replace xpt_async(AC_LOST_DEVICE, path, NULL) with
        mpssas_rescan_target().

        This is to work around a panic in CAM that shows up when adding a
        drive with a rescan and removing another device from the driver thread
        with an AC_LOST_DEVICE async notification.

        This problem was encountered in testing with the LSI sas2ircu utility,
        which was used to create a RAID volume from physical disks.  The driver
        has to create the RAID volume target and remove the physical disk
        targets, and triggered a panic in the process.

        The CAM issue needs to be fully diagnosed and fixed, but this works
        around the issue for now.

    6.  Fix some memory initialization issues in mps_free_command().

    7.  Resolve the "devq freeze forever" issue.  This was caused by the
        internal read capacity command issued in the non-head version of the
        driver.  When the command completed with an error, the driver wasn't
        unfreezing thd device queue.

        The version in head uses the CAM infrastructure for getting the read
        capacity information, and therefore doesn't have the same issue.

    8.  Bump the version to 13.00.00.00-fbsd. (this is very close to LSI's
        internal stable driver 13.00.00.00)

* ebc4133dca40744e7e5a2037e613bf403a16cc65

    Return BUS_PROBE_DEFAULT instead of BUS_PROBE_VENDOR from the mps driver
    probe routine.

    This will allow LSI to ship drivers that return BUS_PROBE_VENDOR to
    override the in-tree version of the driver.

* dce65ce6be9088b0a0444b5f603e5f110a76e249

    Set the max_lun field of the path inquiry CCB to 8.

    This allows LUNs greater than 0 to be probed.  It can be increased later if
    need be.

    This brings back SVN rev 224973, which was inadvertently removed with the
    import of the LSI driver.

* 4b86692e31efa1f09f72ff85635a3fdfe28368c5 (not synchronized)

    (Make the mps(4) module depend on the cam module)

* 8473fac9559e9e3560fcd37c558101cd1718ba01 (originated from DragonFly)

    (Correct sizeof usage)

* 3c7b39f7b5a4dac525c1cf3896051741096de47a (not synchronized - TODO!)

    (Bring in LSI's latest mps(4) 6Gb SAS and WarpDrive driver, version)

* 0069682926e482627d3f64225ad0ad6018023ce6 (not synchronized)

    Change the mps(4) driver to only scan a target if that is what is
    needed instead of scanning the full bus every time.

* 5f97d83a2bb253e5fadfc217cb66c65542557a91

    Fix a small memory leak in mpssas_get_sata_identify().  The change has been
    submitted upstream as well.

* e5c6ca6783da2418a0046f43f47977f4534925d3

    Fix kernel panic on `camcontrol reset` for specific target, caused by
    uninitialized cm_targ in mpssas_action_resetdev().

* d35997f97e5bca6ac7e1dffebc4f7bc0bf4a168e

    Several fixes to allow firmware/BIOS flash access from user-level:
    Set max DMA segment size to 24bit, as MPI SGE supports it.
    Use mps_add_dmaseg() to add empty SGE instead of custom code.
    Tune endianness safety.

* 8600cbb5b6ebb06db859c9e2c76d07be50b8ff6a

    Correct double "the the"

* 5277f913de0e34474af844aed711a14c28c20d2b (not synchronized)

    (Add casts to unbreak the i386 PAE build for the mps(4) driver.)

* f124bf985f4786c8ddd24f5127e7bf200d0396ad

    Don't lose the 255'th disk behind the initiator.

* 3f7a414911a892c8c84206394eb643cbde706d20 (already synchronized)

    remove duplicate semicolons where possible.

* bd7f0fa0bb4b7b0f87227e0c4d49a4bd9b113cf0 (not synchronized)

    (Reform the busdma API so that new types may be added without modifying...)

* 8857575b13cf118cc89efb1b462dd314df09c180 (not applicable)

    (Replace the TDP_NOSLEEPING flag with a counter so that the)

* 674a0b97f5232c5275bfd0394620e7809315c694 (not applicable)

    (Except one case mps(4) driver does not touch the data and works well...)

* 3d32e6b10c85bbbaea953937412778787bba3629

    MFprojects/camlock r248982:
    Stop abusing xpt_periph in random plases that really have no periph related

* bf0ecb667034d07b6288c04623d895a0919377c0

    Fix uninitialized warning in mps

* 0389554b1afa82981e507befda68b56631251990

    Fix NULL-dereference kernel panic in case of mps_attach() failure.

* 9a638117821b8de32c1f05d7244562702b4155b6

    Fix uninitialized memory reference in mps_read_config_page.  It was
    ...
kernel - Wakeup threads blocked in the VM page allocator more quickly

Additional tuning to changes in the way the pageout daemon and VM system
wakes up threads blocked allocating normal VM pages.  Previously the VM
system would wait for the vm_paging_target() to be reached before waking
up all waiters, and had code to try to wakeup individual threads past
the minimum.

This just didn't work very well on machines with lots of memory because
it could take quite a long time for the pageout daemon to actually reach
the vm_paging_target() (and VM load could prevent it from being reached at
all!).  Many threads could wind up being blocked indefinitely waiting for
cache and/or free page counts to reach reasonable levels.

The solution is to give the kernel time to build up a smaller number
of free+cache pages beyond the minimum, enough to give all waiting threads
a fair shot at allocating at least one page, and then simply wakeup all
the waiters.  This hysteresis is set smallish on purpose, defaulting to
a value of 16 in order to avoid holding threads blocked for excessive
periods of time.

Under heavy VM loads this creates an overlap between memory consumers and
the pageout daemon, allowing the pageout daemon to run continuously in
these situations.

* Add the vm.page_free_hysteresis sysctl, initialized to 16.  This field
  specifies a small number of pages past the minimum required for normal
  system operation before the VM system will wakeup threads blocked in the
  VM page allocator.

* Adjust tmpfs to force-free pages through the hysteresis value to reduce
  degenerate block/wakeup situations under heavy VM loads.
Merge branch 'master' into gsocdrm_alter
kernel: Fix compiling tmpfs into the kernel.
kernel - Change lwkt_wait_ipiq() to use the TSC

* lwkt_wait_ipiq() was using a static counter/constant for its failsafe
  panic, which can vary immensly over time and might not be long enough
  for systems running under VMs.

* Change the code to use the TSC api to properly time the failsafe.  It
  will generate warnings each second and panic at 10 seconds if the IPIQ
  fails to drain.

Reported-by: marino
Merge branch 'master' into gsocdrm_alter