kernel - Optimize vfs_msync() when MNTK_THR_SYNC is used

* vfs_msync() will now use vsyncscan() when MNTK_THR_SYNC is set.
  Lazy synchronization scans will still properly ignore MADV_NOSYNC
  areas, but will not be able to optimize away the scan overhead for
  those vnodes (they remain on the syncer list).

  This change allows both lazy synchronization and explicit 'sync' commands
  to avoid having to scan all cached vnodes on the system, resulting in O(1)
  operation in many cases where it might have taken a few seconds before
  (on large systems with hundreds of thousands to millions of vnodes cached).
  With this change both the vnode sync and the memory sync will be optimal.

  Currently implemented for hammer1 and hammer2.

* Add VOBJDIRTY to the set of flags that will place the vnode on the
  syncer list.  This occurs from the vm_page_dirty() and other bits of
  code only if MNTK_THR_SYNC is set.

  Theoretically it should be safe for us to do this even though neither
  the vm_object or the related vnode are likely locked or guarded, because
  neither can go away while an associated vm_page is busied.  The syncer
  list code itself is protected with a token.
kernel - Optimize sync and msync for tmpfs and nfs

* Flesh-out the vfs_sync API and implement vhold/vdrop callbacks
  (used by NFS).

* Use MNTK_THR_SYNC in tmpfs and finish implementing it in nfs.  This
  will optimize sync and msync for these filesystems.

* In both cases inode attributes are either synchronous or don't involve
  any VFS work to flush, so we don't have to use VISDIRTY.
stat.1 - Remove unsupported %B

* Our struct stat does not have st_birthtim so don't mention it.
kernel: Add a method to get the bus's bus_dma_tag_t

This is required by some machine architectures where there are separate
IOMMU's for each PCI bus.

Obtained-from: FreeBSD
vga_pci.c: Sync with FreeBSD

Most important change:

* Use vga_pci_alloc_resource() to map PCI Expansion ROMs

* This is cleaner and fixes Video BIOS mapping when the given device isn't
the boot display.

* Original author: dumbbell@
drm: Rename members of struct drm_agp_head to match Linux

This reduces the diff between FreeBSD and Linux 3.8.
drm: Rename struct drm_driver_info to struct drm_driver

This reduces the diff between FreeBSD and Linux 3.8.
drm/radeon: Add missing "return false" after unmapping invalid BIOS

Without that, we would try to copy the unmapped BIOS.

Submitted by:	Christoph Mallon <christoph.mallon@gmx.de>
Approved by:	re (blanket)
kernel - Performance optimization pass

* Numerous pid and priority related syscalls, such as getpid(), were
  improperly acquiring proc_token to protect fields that are now protected
  with per-process or per-pgrp tokens.

  Do a pass on kern_prot.c and kern_resource.c fixing these issues.  This
  removes the use of proc_token from several common system call paths but
  it should be noted that none of these system calls are in critical paths.
  The benefit is probably minor but will improve performance in the face
  of allproc-scanning operations (such as when you do a 'ps' or 'top').

* vmntvnodescan() is not in the critical path except for vflush()'s which
  occur on umount.  vflush()'s pass a NULL fast function.  The
  vmntvnodescan() only needs to hold the vmobj_token when the fastfunc is
  non-NULL.  Do not hold the vmobj_token when fastfunc is NULL.

  This primarily improves performance when tmpfs's are being mounted and
  unmounted at a high rate (poudriere bulk builds).
kernel - Fix bug when running swapon a gpt slice

* diskpsize() and related API functions to obtain the number of blocks
  in a disk specification was punting if there was no dragonfly disklabel.
  This path was being specifically used by swapon.

* Do not require a dragonfly disklabel when the whole-slice partition is
  specified (i.e. /dev/daXsY with no a...z suffix).

* Swapon now works on gpt swap slices.

Reported-by: julianp
pwd(1), realpath(1): Split shared source file into separate ones

The realpath(1) and pwd(1) programs share the same source file using the
program name as a condition.  Let's create a dedicated directory for
realpath, duplicate the source file, then tailor both.  Not only is this
more logical, it will make maintenance easier in the (near) future.
realpath(1): Sync with FreeBSD to add -q option

If -q is specified, warnings will not be printed out when realpath(3) fails.
pwd(1): Sync with FreeBSD (very minor, mainly editorial)
find(1): Sync with FreeBSD

Originally I did this to gain the -quit feature.  It turns out that we
already had it, but FreeBSD didn't document it until 4 years after they
implemented it, so it wasn't on our man page either.

With this sync, we get time comparisons down to the nanosecond.  We get
the -sparse option.  The behavior of -delete was changed the delete the
files given as arguments.

The only thing that was omitted with all the birthtime options.
The new find was used successfully in locate.update job, something
that failed in the last sync and code in functions.c had to be
partially reverted.
pgrep(1), pkill(1): Sync with FreeBSD to get the -F options

These functions haven't been touched since DragonFly 1.1 (2004), other
than build tweaks.  It was claimed that it would be "trivial" to add
the -F options (pid file) but I wouldn't classify it as such.  There
is a pretty big diff between the FreeBSD and DragonFly 1.1 version.  I
had make some modifications, but the functions appear to work in the
very short tests that I performed.
pwait(1): Import from FreeBSD, built without modification!
Fix world build bootstrapping issue

The new version of find(1) uses a new locale function called rpmatch.
The use of this function breaks the world build on systems that don't
have the new locale functionality yet, e.g. Release 3.4.

To fix this, I added a BOOTSTRAPPING macro that will check the
first letter of the response character array rather than use the
locale function.  This modification appears only in the bootstrap tool.
netinet/in.h: Add missing IPPORT_MAX definition

Obtained-from: FreeBSD
kernel - Greatly improve concurrent fork's and concurrent exec's

* Rewrite all the vm_fault*() API functions to use a two-stage methodology
  which keeps track of whether a shared or exclusive lock is being used
  on fs.first_object and fs.object.  For most VM faults a shared lock is
  sufficient, particularly under fork and exec circumstances.

  If the shared lock is not sufficient the functions will back-down to an
  exclusive lock on either or both elements.

* Implement shared chain locks for use by the above.

* kern_exec - exec_map_page() now attempts to access the page with a
  shared lock first, and backs down to an exclusive lock if the page
  is not conveniently available.

* vm_object ref-counting now uses atomic ops across the board.  The
  acquisition call can operate with a shared object lock.  The deallocate
  call will optimize decrementation of ref_count for values above 3 using
  an atomic op without needing any lock at all.

* vm_map_split() and vm_object_collapse() and associated functions are now
  smart about handling terminal (e.g. OBJT_VNODE) VM objects and will use
  a shared lock when possible.

* When creating new shadow chains in front of a OBJT_VNODE object, we no
  longer enter those objects onto the OBJT_VNODE object's shadow_head.
  That is, only DEFAULT and SWAP objects need to track who might be shadowing
  them.  TODO: This code needs to be cleaned up a bit though.

  This removes another exclusive object lock from the critical path.

* vm_page_grab() will use a shared object lock when possible.
drm: Define BITS_PER_LONG

At the same time, rename a macro of the same name in drm_atomic.h. They
both have the same meaning but the one in drm_atomic.h uses sizeof(),
which prevents from using it inside an #if preprocessor condition.