Skip to content


Subversion checkout URL

You can clone with
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
Commits on Oct 03, 2011
Sepherosa Ziehau resource: Per-CPU hardware resources support, step 1 of many
- Add cpuid in the resource list entry, which points to the
  resource's owner CPU
- Add cpuid parameter to resource_list_add(), which could be used to
  set the resource's owner CPU
Sepherosa Ziehau resource: Per-CPU hardware resources support, step 2 of many
Add cpuid parameter to resource_list_alloc, so that this parameter could
be passed to bus_alloc_resource DEVMETHOD
Sepherosa Ziehau MachIntrABI: Add method to return IRQ's target CPU a05c798
Commits on Oct 04, 2011
Sepherosa Ziehau resource: Per-CPU hardware resources support, step 3 of many
- Add cpuid parameter to bus_set_resource() and bus_set_resource
  DEVMETHOD; Pass this parameter to resource_list_add()
- Obtain interrupt resource's owner CPU, i.e. target CPU, from
  MachIntrABI and pass it to bus_set_resource(), so that the owner
  CPU of the interrupt resource could be correctly setup
- Rest of types of resources, e.g. IOPORT, MEMORY and DRQ, are
  shared across CPUs, so their cpuids are set to -1
Commits on Oct 06, 2011
@vsrinivas vsrinivas kernel -- Add pool spinlocks interface. 9e2ac34
@tuxillo tuxillo x86_64 - Remove unneeded globaldata.c file.
Functions globaldata_find(), cpu_gdinit() and is_globaldata_space()
are correctly defined in machdep.c.
Commits on Oct 07, 2011
Matthew Dillon kernel - Fix bug in lwkt_token_swap()
* Fix a bug where lwkt_token_swap() would incorrectly assign the ref
  pointer when the top two tokens on the stack are the same token.

  When swapping the top two tokens where tok1 == tok2, the token
  can wind up being repointed to the top ref instead of the deeper
  ref.  When the top ref is released this caused the token to also
  release even though there was another deeper ref to the same

* Effected the vm_object traversal code and could cause an object token
  to be effectively lost without triggering a panic, resulting in
@vsrinivas vsrinivas kernel -- Resolve NULL ptr dereference in fill_kinfo_proc.
Reported-by: Justin Sherrill
@bissont bissont TRIM support
Signed-off-by: Samuel J. Greear <>
Commits on Oct 08, 2011
Sascha Wildner Fix the i386 buildworld.
Reported-by: Joachim de Groot <>
François Tigeot Add missing END() macros to libc i386 .S files
They were already present in the x86_64 versions of these files
Sascha Wildner libc: Remove the CVS ID in the recently changed files, too. 091337d
Commits on Oct 09, 2011
Sepherosa Ziehau rman: Record owner CPUID during initialization 65cd6ac
Sepherosa Ziehau resource: Per-CPU hardware resources support, step 4 of many
Add cpuid parameter to bus_alloc_resource DEVMETHOD, so cpuid
could be passed all the way to the nexus
Sepherosa Ziehau resource: Per-CPU hardware resources support, step 5 of many
Fix up cpuid parameter passed to resource_list_add() after
bus_set_resource and bus_alloc_resource DEVMETHODs have cpuid
Sascha Wildner libm: Match ENTRY()s with END()s. d04e869
Commits on Oct 10, 2011
@vsrinivas vsrinivas Document spin_pool_lock(9) and spin_pool_unlock(9). 01c7831
Sepherosa Ziehau atkbd: Set the interrupt's target CPU properly a93b38a
Sepherosa Ziehau psm: Set the interrupt's target CPU properly e87965e
Sepherosa Ziehau nexus: Log invalid target CPUID for interrupt resource a955f56
Sepherosa Ziehau atkbd: Interrupt resource is not shareable 637707a
Sascha Wildner libc_r/libstand/libthread_xu: Match ENTRY()s with END()s. 0ed9601
Sascha Wildner padlock(4): Match ENTRY()s with END()s. 4b2cf35
Sascha Wildner kernel/ufs: Fix mount_point access in ffs_blkfree() when using softdep.
Was going through inode->vnode->v_mount, but vnode was bad so
v_mount was NULL reference.

New way to get mount point: inode->i_devvp->v_mount.

Reported-by:   Thomas Nikolajsen
Dragonfly-bug: <>
Submitted-by:  Tim Bisson <>
Commits on Oct 11, 2011
Sascha Wildner kernel/drm: Clean up the Makefiles a bit. 97a2109
Sepherosa Ziehau bus: Add bus_alloc_legacy_irq_resource()
This is a convenient wrapper function for legacy (mainly ISA) drivers to
alloc IRQ resource
Sepherosa Ziehau atkbd: Utilize bus_alloc_legacy_irq_resource() 1cf280a
Sepherosa Ziehau psm: Utilize bus_alloc_legacy_irq_resource 920ffa6
Sepherosa Ziehau legacy devices: Utilize bus_alloc_legacy_irq_resource() abf2113
Sepherosa Ziehau Merge branch 'devel' 10c9bcd
Commits on Oct 12, 2011
Sascha Wildner Sync zoneinfo database with tzdata2011l from
* asia: Changed the end date for West Bank's Summer Time for
    this year (2011) to match reality reported by Steffen Thorsen.

* australasia: Adjust the end date for Summer time in Fiji in
    2012 (Feb) as reported by Steffen Thorsen.

* northamerica: Corrected typo in (ancient) LMT zone offset as
    detected by Zefram.

* southamerica: Resume Summer Time in Bahia, Brazil (following the
    standard Brazil algorithm, which causes Summer time to start
    Oct 16 this year, which matches the report.)
Commits on Oct 13, 2011
John Marino sdiff: fix wcwidth recursion
Apparently trying to diff non-UTF8 documents caused a stack overflow.
The culprit was correctly identified by Yonetani as the redefinition
of wcwidth in the wcwidth.c file.  Within that function, it calls itself
recursively forever.  I'm not sure how this would work differently
(macro or not) on another system.

My solution was to stop redefining wcwidth and just create a separate
function, one that will call the system wcwidth function as needed.

reported by: Peter Avalos
Sascha Wildner kernel/tmpfs: Remove a useless (and wrong, anyway) header. dff3cc7
Commits on Oct 14, 2011
Sascha Wildner ipiq: Remove an extra semicolon that was messing up an if.
Submitted-by:  c <>
Dragonfly-bug: <>
@tuxillo tuxillo syscons - Fix comment. 532503f
@tuxillo tuxillo syscons - Fix comments related to do_switch_scr()
do_switch_scr() no longer releases critical sections so all
the comments remarking this are now wrong, remove them.

Most of the code uses now tty_token for the non-critical paths
and it no longer needs a critical section.

Pointed-out-by: @dillon
Sascha Wildner Add PCI MMC/SD drivers to our standard kernel configurations. 0833f5c
Sascha Wildner ath(4): Remove a debug message (not in FreeBSD's either).
Reported-by:   Juan Francisco Cantero Hurtado <>
Dragonfly-bug: <>
Commits on Oct 15, 2011
John Marino crt1.o: provide symbol definition of __progname
When the linker version script requests "local: *", the linker chokes on
it because the weak __progname crt1.o symbol comes back undefined.

This is a duplicate definition to the ones provided by csu, but harmless
since the linker resolves it.

Also cleaned up some files involving libc_private.h that should have been
updated in previous changesets.
John Marino crt1.o: provide symbol definition of environ
Provide duplicate definition of char **environ to prevent linker choking
on version scripts ending with "local: *".
John Marino i386/sys/sbrk.S: extra "end" symbol removed
The i386 version of sbrk.S has carried an extra end symbol since the
first import.  It seems to have been an oversight to leave it there.

reported by: Francois Tigeot
Addresses: Failed heimdal build on i386
Commits on Oct 16, 2011
Sascha Wildner lgue(4): Fix an issue and do some cleanup.
In lgue_getmtu(), ced->wMaxSegmentSize was being referenced with ced
being either uninitialized or NULL.

While here, remove an unused variable and remove an extra 0 in the
Thomas Nikolajsen loader(8): Update: add more text on kenv vs local variables etc.
 - Add missing kenv variables to assignment white list;
all kenv variables which are used in loader(8) source are added.
 - Inhibiting loading of acpi(4) needs to use `lunset acpi_load',
not `unset', as `loadall' uses local variables; ditto for ehci.
 - Add info to loader.8 & help files on variables ($VAR / ${VAR}) in
command arguments and assignment; these are kenv variables.
 - Add description of vfs.root.realroot
 - Fix some whitespace style(7).
DragonFly-bug: <>
Commits on Oct 17, 2011
@tuxillo tuxillo pmap - Missing critical section when calling lwkt_ipiq_process().
- pmap_interlock_wait() explicitly calls lwkt_process_ipiq() which expects to
be in a critical section. We still need cpu_ccfence() to guarantee that
pmap->pm_active is always read inside the loop.

- Sync pmap_interlock_wait's comment for both i386 and x86_64.

DragonFly-bug: <>

Reviewed by: @dillon, @vsrinivas
Commits on Oct 18, 2011
@tuxillo tuxillo syscons - Avoid potential blocking issue.
- kbd_ioctl() uses it's own locking via lockmgr() and the
  syscons softc is protected using a mutex, so we better
  avoid both locks at once due possible blocking issues.
  In fact, in my particular case the panic only occurs in
  real hardware, while on a VMWare VM I had a lockup.
- Only found in 4-CPU SMP setups.
- Discovered via DEBUG_LOCKS option.

DragonFly-bug: <>
Reviewed-by: @dillon, @sjg
Matthew Dillon kernel - Major SMP performance patch / VM system, bus-fault/seg-fault…
… fixes

This is a very large patch which reworks locking in the entire VM subsystem,
concentrated on VM objects and the x86-64 pmap code.  These fixes remove
nearly all the spin lock contention for non-threaded VM faults and narrows
contention for threaded VM faults to just the threads sharing the pmap.

Multi-socket many-core machines will see a 30-50% improvement in parallel
build performance (tested on a 48-core opteron), depending on how well
the build parallelizes.

As part of this work a long-standing problem on 64-bit systems where programs
would occasionally seg-fault or bus-fault for no reason has been fixed.  The
problem was related to races between vm_fault, the vm_object collapse code,
and the vm_map splitting code.

* Most uses of vm_token have been removed.  All uses of vm_spin have been
  removed.  These have been replaced with per-object tokens and per-queue
  (vm_page_queues[]) spin locks.

  Note in particular that since we still have the page coloring code the
  PQ_FREE and PQ_CACHE queues are actually many queues, individually
  spin-locked, resulting in very excellent MP page allocation and freeing

* Reworked vm_page_lookup() and vm_object->rb_memq.  All (object,pindex)
  lookup operations are now covered by the vm_object hold/drop system,
  which utilize pool tokens on vm_objects.  Calls now require that the
  VM object be held in order to ensure a stable outcome.

  Also added vm_page_lookup_busy_wait(), vm_page_lookup_busy_try(),
  vm_page_busy_wait(), vm_page_busy_try(), and other API functions
  which integrate the PG_BUSY handling.

* Added OBJ_CHAINLOCK.  Most vm_object operations are protected by
  the vm_object_hold/drop() facility which is token-based.  Certain
  critical functions which must traverse backing_object chains use
  a hard-locking flag and lock almost the entire chain as it is traversed
  to prevent races against object deallocation, collapses, and splits.

  The last object in the chain (typically a vnode) is NOT locked in
  this manner, so concurrent faults which terminate at the same vnode will
  still have good performance.  This is important e.g. for parallel compiles
  which might be running dozens of the same compiler binary concurrently.

* Created a per vm_map token and removed most uses of vmspace_token.

* Removed the mp_lock in sys_execve().  It has not been needed in a while.

* Add kmem_lim_size() which returns approximate available memory (reduced
  by available KVM), in megabytes.  This is now used to scale up the
  slab allocator cache and the pipe buffer caches to reduce unnecessary
  global kmem operations.

* Rewrote vm_page_alloc(), various bits in vm/vm_contig.c, the swapcache
  scan code, and the pageout scan code.  These routines were rewritten
  to use the per-queue spin locks.

* Replaced the exponential backoff in the spinlock code with something
  a bit less complex and cleaned it up.

* Restructured the IPIQ func/arg1/arg2 array for better cache locality.
  Removed the per-queue ip_npoll and replaced it with a per-cpu gd_npoll,
  which is used by other cores to determine if they need to issue an
  actual hardware IPI or not.  This reduces hardware IPI issuance
  considerably (and the removal of the decontention code reduced it even

* Temporarily removed the lwkt thread fairq code and disabled a number of
  features.  These will be worked back in once we track down some of the
  remaining performance issues.

  Temproarily removed the lwkt thread resequencer for tokens for the same
  reason.  This might wind up being permanent.

  Added splz_check()s in a few critical places.

* Increased the number of pool tokens from 1024 to 4001 and went to a
  prime-number mod algorithm to reduce overlaps.

* Removed the token decontention code.  This was a bit of an eyesore and
  while it did its job when we had global locks it just gets in the way now
  that most of the global locks are gone.

  Replaced the decontention code with a fall back which acquires the
  tokens in sorted order, to guarantee that deadlocks will always be
  resolved eventually in the scheduler.

* Introduced a simplified spin-for-a-little-while function
  _lwkt_trytoken_spin() that the token code now uses rather than giving
  up immediately.

* The vfs_bio subsystem no longer uses vm_token and now uses the
  vm_object_hold/drop API for buffer cache operations, resulting
  in very good concurrency.

* Gave the vnode its own spinlock instead of sharing vp->v_lock.lk_spinlock,
  which fixes a deadlock.

* Adjusted all platform pamp.c's to handle the new main kernel APIs.  The
  i386 pmap.c is still a bit out of date but should be compatible.

* Completely rewrote very large chunks of the x86-64 pmap.c code.  The
  critical path no longer needs pmap_spin but pmap_spin itself is still
  used heavily, particularin the pv_entry handling code.

  A per-pmap token and per-pmap object are now used to serialize pmamp
  access and vm_page lookup operations when needed.

  The x86-64 pmap.c code now uses only vm_page->crit_count instead of
  both crit_count and hold_count, which fixes races against other parts of
  the kernel uses vm_page_hold().

  _pmap_allocpte() mechanics have been completely rewritten to remove
  potential races.  Much of pmap_enter() and pmap_enter_quick() has also
  been rewritten.

  Many other changes.

* The following subsystems (and probably more) no longer use the vm_token
  or vmobj_token in critical paths:

  x The swap_pager now uses the vm_object_hold/drop API instead of vm_token.

  x mmap() and vm_map/vm_mmap in general now use the vm_object_hold/drop API
    instead of vm_token.

  x vnode_pager

  x zalloc

  x vm_page handling

  x vfs_bio

  x umtx system calls

  x vm_fault and friends

* Minor fixes to fill_kinfo_proc() to deal with process scan panics (ps)
  revealed by recent global lock removals.

* lockmgr() locks no longer support LK_NOSPINWAIT.  Spin locks are
  unconditionally acquired.

* Replaced netif/e1000's spinlocks with lockmgr locks.  The spinlocks
  were not appropriate owing to the large context they were covering.

* Misc atomic ops added
Commits on Oct 19, 2011
Matthew Dillon kernel - pmap_spin needed for UP build
* Place the pmap_spin declaration outside the #ifdef SMP sequence for UP.
Matthew Dillon kernel - Fix latency issue with many cores contending on a token
* Fix a latency issue when many cores are contending on the same token.
  This can be tested e.g. by setting an interface to use polling mode
  and then pinging it from the outside.  Ping times in excess of 60 seconds
  (yes, seconds!) could occur.

* The problem turns out to be in usched_bsd4.c in the loop that tries to
  acquire the current process designation.  This loop runs in a critical
  section (and probably its caller too) and while it checks for the
  LWKT thread reschedule flag it fails to call splz() to process pending
  interrupts (like IPIs) that might SET the flag.

  Adding a single splz() prior to the lwkt reschedule check greatly
  reduces the latency problem.
Matthew Dillon kernel - Increase exec args cache on 64-bit boxes
* Increase the exec args cache on 64-bit boxes with more than 4G of ram.
  This increases the number of concurrent applicationss which can be
  undergoing an exec.
Matthew Dillon kernel - Fix long-standing vfork/exec bug
* Fix an issue where the parent process can get stuck in the "ppwait"
  state due to a tsleep/wakeup race with its child.

* This bug was present but masked by other tokens prior to a few patches
  ago.  With those tokens now gone this bug reared its face.
Matthew Dillon kernel - Move a vm_object_pip_wakeup() call
* Move a vm_object_pip_wakeup() call from before the related vm_page has
  been woken up to afterwords.  Since the vm_page was already busied I
  don't think this fixes anything in particular, but it is more correct.
Sascha Wildner LINT/LINT64: Sort filesystems. 8124268
Sascha Wildner LINT/LINT64: Add ext2fs. 66e5c58
Sascha Wildner Revert "LINT/LINT64: Add ext2fs."
This reverts commit 66e5c58.

I overlooked that it was already present.
Commits on Oct 20, 2011
Sascha Wildner spinlock.9: A little cleanup. f040cd3
Sascha Wildner Some cleanup after addition of TRIM support.
* Remove unused -R option in newfs(8).

* Miscellaneous small cosmetics.
Commits on Oct 21, 2011
Sascha Wildner kernel: Move GPL'd kernel files to sys/gnu to have them all in one pl…

This affects files in sys/dev/sound/pci/gnu and sys/vfs/gnu/ext2fs.

sys/gnu is analogous to the gnu directory for userland, i.e. below it, we
follow the same hierarchy as in /usr/src/sys.

This commit changes the location of the ext2fs headers, which are public,
so I've bumped __DragonFly_version in order to have something to patch
against in pkgsrc, in case this causes build breakage for any packages.
@davshao davshao DRM from FreeBSD current, tested for r600
Author:    David Shao <>
@thesjg DRM - Fix LINT build 9a8ae71
Commits on Oct 22, 2011
Sascha Wildner Remove some duplicate includes in sys/kern. f406e2f
Sepherosa Ziehau tcp: We have dropped T/TCP for a long time; remove the implied connec…

The hack padding at the end of the struct netmsg_pru_send is also removed,
since connect will not happen on the sending path at all.
Sepherosa Ziehau tcp: We have dropped T/TCP for a long time; remove the implied connec…

The hack padding at the end of the struct netmsg_pru_send is also removed,
since connect will not happen on the sending path at all.
Sascha Wildner accept_filter.9: Add missing include. 9097550
Matthew Dillon kernel - Fix null-pointer crash in i386/pmap.c
* Related to recent work, check that m->object is not NULL
@tuxillo tuxillo kern - Do not allow calls to vmspace_president_count() from userland.
- Processes' vm_map is not read in by kvm_proclist() thus we cannot
  call vmspace_president_count() which entirely relies on that.
- This fixes segfaults in ps(1), w(1) and fstat(1) when using -M
  and -N parameters.

Help-from: @corecode
@tuxillo tuxillo test - Little program to list processes from coredumps or kmem. 5d89600
Commits on Oct 23, 2011
Sascha Wildner Remove some EISA remains in a couple of manual pages. 9c5a96c
Sepherosa Ziehau tcp: Add sosendtcp for further optimization
- Cleanup the 'atomic' logic
- Free the 'control' earlier
- Remove the "implied connection" related bits
Commits on Oct 24, 2011
Sepherosa Ziehau tcp: Let sosendtcp() call tcp_usrreq.pru_send asynchronous
- Embed netmsg_pru_send into mbuf.m_hdr, which shares the space with
- Use the newly added netmsg_pru_send in mbuf to perform asynchronous
  pru_send.  For asynchronous pru_send, PRUS_NOREPLY is added, which
  prevents pru_send to reply the message.
- In sosendtcp(), if we have more data to call pru_send, we call it
  asynchronously.  The last piece of data or OOB data will still be
  passed to pru_send synchronously.

On Phenom 9550 (4 core, 2.2GHz):
8 parallel netperf -H (4 runs, unit: Mbps)

old  5863.85  5773.13  5534.14  5506.72
new  6735.98  6903.13  6971.89  7056.66

This give ~20% performance improvement.

It has no obvious impact on 1000BaseT or 100baseTX network performace.
Sepherosa Ziehau tcp: Aggregate the mbuf in sosendtcp() a little bit
This greatly reducse the ipi interrupts caused by ipi sending (both
domsg and sendmsg), thus improves overall performance a bit.

net.inet.tcp.sosnd_agglim is added to tune how much mbuf should be
aggregated; it is default to 2.  Setting this sysctl to 1 restores
the old behaviour: one full mbuf at a time.

On Phenom 9550 (4 core, 2.2GHz):
8 parallel netperf -H -P0 (4 runs, unit; Mbps)

                                              IPIs/s (sum of 4 core)
 1 mbuf  6735.98  6903.13  6971.89  7056.66   ~400K
 2 mbuf  7675.47  7757.28  7815.45  7514.50   ~240K
 4 mbuf  7895.33  7584.22  7704.12  7723.33   ~180K
 8 mbuf  8006.94  8077.87  7701.23  8061.12   ~120K
16 mbuf  8151.68  8023.03  7972.42  8046.13   ~100K

The default value (2) for the sosnd_agglim improve the whole
performance by ~10%.  IPI rate is also reduce greatly.

It has no obvious impact on 1000BaseT or 100baseTX network performace.
Sepherosa Ziehau Merge branch 'devel' ead125b
Commits on Oct 25, 2011
Matthew Dillon kernel - Increase VM page free minimums for allocations
* Recent work removed the global vm_token and moved to per-vm_page_queue
  spin locks, which allows cpus to allocate VM pages concurrently.  This
  could result in a situation where remaining free pages got blown out
  without giving the system a chance to replentish them.

* Symptoms included the BUF/BIO system complaining of memory exhaustion
  and the pageout daemon deadlocking on low memory (which would deadlock
  the whole machine in a memory-exhausted state).

* Increase minimums to prevent this.  In particular, the interrupt_free_min
  was previously hardwired to a value of 2.. as in 2 pages (8192 bytes),
  which is an excessively low value.  The new calculations place this value
  (typically) around a few-hundred pages.
Sepherosa Ziehau tmpfs: Implement vptofh, so programs open files in tmpfs could coredump
Submitted-by: Tim Bissont <>
Sascha Wildner periodic/daily: Fix the check for denied zone transfers (AXFR and IXFR).
Just use grep -E here (fgrep -E seems to have stopped working at some
point anyway).
Sascha Wildner Sync zoneinfo database with tzdata2011m from
asia:           8.68 -> 8.69
australasia:    8.27 -> 8.28
backward:       8.9  -> 8.10
europe:         8.38 -> 8.39
northamerica:   8.49 -> 8.50
southamerica:   8.50 -> 8.52       8.49 -> 8.50

* asia, australasia, northamerica: Bump version for tzdata2011l.

* europe, backward: Pridnestrovian Moldavian Republic (Europe/Tiraspol)
    has followed much of Russia, and will retain "summer time" year round
    (that is no time transition is due Oct 30). This reintroduces a zone
    that had earlier been removed, and so removes the "backward" link.

    On the other hand, Ukraine have decided not to follow, so the change
    which had been made in preparation for that in tzdata2011k is now
    reverted, and there will be a transition on Oct 30.

* southamerica: The change to Bahia, Brazil, that introduced summer time
    (following the regular Brazil rules, so commencing this year on
    Oct 16 - last SUnday) that was mooted before tzdata2011l was released,
    but withdrawn because the change was not yet official, has now been
@vsrinivas vsrinivas kernel -- lwbuf: Convert cmpxchg loop to LOCK OR; we are just setting…
… a bit.
@tuxillo tuxillo libhammer - HAMMER filesystem library.
Initial work to bring a library to help operating
HAMMER filesystems from userland.

It's barebones as of now, only "info" directive is
adapted, progressively the rest of the directives
will be migrated

Help-from: @swildner, @sjg
Commits on Oct 26, 2011
@vsrinivas vsrinivas librt -- aio: lio_listio: Do not dereference NULL sigevp.
Reported-by: Z`
Sascha Wildner pf.conf.5/swapcache.8: Fix some typos (verses -> versus). 5242e85
@vsrinivas vsrinivas libc -- string: strspn should return 0 for empty match strings, not s…
…tring len.

Reported-by: lentferj
Matthew Dillon kernel - callout_init() -> callout_init_mp() in selected cases
* Use callout_init_mp() in numerous cases where the BGL is not
  needed.  There are still a lot more left.
Matthew Dillon kernel - Fix cumulative nprocs bug
* nprocs requires atomic ops now that the related code is MPSAFE.

* Fixes issue reported w/pkgbox64 of the machine running out of processes

* Also move a wakeup() to outside p->p_token to improve concurrency and
  other minor adjustments.
Matthew Dillon kernel - limit allproc_scan() to snapshot
* Limit the allproc_scan() to (roughly) a snapshot of nprocs processes.
  If we don't do this it is possible for the scan to race fork/exec'ing
  programs and essentially run forever.
Matthew Dillon kernel - Optimize spinlocks for 48-core contention
* Change the spinlock algorithm to do a read-test before atomic_swap_int().
  This has no effect on single-chip cpus (tested on phenom II quad-core),
  but has a HUGE HUGE HUGE effect on multi-chip/many-core systems.  On
  monster (48-core opteron / 4 x 12-core chips) concurrent kernel compile
  time is reduced from 170 seconds to 75 seconds with this one change.
  That's well over 100%.

  The reason the change is important is because it unloads the hardware
  cache coherency bus and communication by creating a closed-loop with
  the pre-read, which essentially passively waits for the cache update
  instead of actively issuing a locked bus cycle memory op.  This prevents
  total armagheddon on the memory busses when a substantial number of
  cores are doing real work.

* Increase the number of pool spinlocks from 1024 to 8192.  We need them
  now that vm_page's use pool spinlocks.
Matthew Dillon kernel - Make the itimers MPSAFE
* Use the per-process p_token instead of the MP lock for per-process
Matthew Dillon kernel - Major vm_page, lwkt thread, and other changes
* Remove the rest of the LWKT fairq code, it may be added back in a different
  form later.  Go back to the strict priority model with round-robining
  of same-priority LWKT threads.

  Currently the model scans gd_tdrunq for sort insertion, which is probably
  a bit too inefficient.

* Refactor the LWKT scheduler clock.  The round-robining is now based on
  the head of gd->gd_tdrunq and the lwkt_schedulerclock() function will
  move it.  When a thread not on the head is selected to run (because
  the head is contending on a token), the round-robin tick will force a
  resched on the next tick.  As before, we never reschedule-ahead the
  kernel scheduler helper thread or threads that have already dropped
  to a user priority.

* The token code now tries a little harder to acquire the token before
  giving up, controllable with lwkt.token_spin and lwkt.token_delay
  (token_spin is the number of times to try and token_delay is the delay
  between tries, in nanoseconds).

* Fix a serious bug in usched_bsd4.c which improperly reassigned the 'dd'
  variable and caused the scheduler helper to monitor the wrong dd

* Refactor the vm_page coloring code.  On SMP systems we now use the
  coloring code to implement cpu localization when allocating pages.
  The pages are still 'twisted' based on their physical address so both
  functions are served, but cpu localization is now the more important

* Implement NON-OBJECT vm_page allocations.  NULL may now be passed, which
  allocates a VM page unassociated with any VM object.  This will be
  used by the pmap code.

* Implement cpu localization for zalloc() and friends.  This removes a major
  contention point when handling concurrent VM faults.  The only major
  contention point left is the PQ_INACTIVE vm_page_queues[] queue.

* Temporarily remove the VM_ALLOC_ZERO request.  This will probably be
  reenabled in a later commit.

* Remove MSGF_NORESCHED (it is not being used) and simplify related
  lwkt scheduler functions.

* schedcpu_stats() and schedcpu_resource() no longer stall the callout
  kernel threads when scanning allproc, if they are unable to acquire

* Move the need_lwkt_resched() from hardclock() to lwkt_schedulerclock()
  (which hardclock() calls).
Matthew Dillon kernel - remove MP lock from uipc socket functions, route table, and …

* Remove the MP lock from the uipc_socket.c kqueue filterops.

* Remove the MP lock from the route table threads.

* Remoev the MP lock from the IPV6 MLD6 implementation.
Matthew Dillon kernel - Rewrite the x86-64 pmap code
* Use unassociated VM pages (without a VM object) for all page table pages.

* Remove kptobj and pmap->pm_pteobj.

* For the moment implement a Red-Black tree for pv_entry_t manipulation.
  Revamp the pindex to include all page table page levels, from terminal
  pages to the PML4 page.  The hierarchy is now arranged via the PV system.

* As before, the kernel page tables only use PV entries for terminal pages.

* Refactor the locking to allow blocking operations during deep scans.
  Individual PV entries are now locked and critical PMAP operations do not
  require the pmap->pm_token.  This should greatly improve threaded
  program performance.

* Fix kgdb on the live kernel (pmap_extract() was not handling short-cutted
  page directory pages).
Matthew Dillon kernel - Handle pmap_protect() race in pmap code
* If we find an unexpectedly non-NULL pte_pv from a pv_find(), which only
  holds the pv, we have to resolve a locked pte_pv to rectify the race.
  Add debug code to catch and rectify the situation.
Matthew Dillon kernel - Adjust pagezero/pagecopy assembly and re-enable VM_ALLOC_ZERO
* Remove the movnti, sfence, and prefetch instructions from the pagezero(0
  and pagecopy() assembly.  They don't help and will eve hurt on some of
  the less powerful cpus.

* Re-enable the use of VM_ALLOC_ZERO.  There was no difference in test
  compile times w/ the concurrent buildkernel -j 48 NO_MODULES=TRUE test.
  It might help w/lower-load edge cases so keep it around.
Matthew Dillon kernel - pmap (64bit) add missing wiring to fix panic
* When entering an unmanaged pte into a user pmap we have to bump the
  wiring count of the parent page table page.

Reported-by: thesjg
Matthew Dillon kernel - Fix recently introduced bus error w/postgres scoreboard
* The OBJ_ONEMAPPING flag has to be cleared when forking a shared

* Fixed an issue with the postgres scoreboard.

Reported-by: Studbolt, thesjg
Matthew Dillon test - Add code to test recent bus error issue
Submitted-by: "Samuel J. Greear" <>
Commits on Oct 27, 2011
Matthew Dillon kernel - Fix deep recursion in vm_object_collapse()
* vm_object_collapse() will loop but its backing_object sometimes needs
  to be deallocated as well and this can trigger another collapse against
  a different parent object.

* Introduce vm_object_dealloc_list and friends to collect a list of objects
  requiring deallocation so the caller can run the list in a way that avoids
  a deep recursion.

Reported-by: juanfra
Matthew Dillon kernel - Fix memory leak when execv()ing certain paths.
* Fix a memory leak when execv()ing paths prefixed with a "./"
Matthew Dillon kernel - Fix deep recursion in vm_object_collapse() (2)
* Fix bug in previous deep recursion commit.  A chainlock was being
  released too late.
Commits on Oct 28, 2011
Sascha Wildner Fix tzsetup(8) breakage.
If a country has >1 zones, each one needs a description.

tzdata2011m accidentally violated this rule (when Moldova was split),
which caused tzsetup(8) to exit early and whine about it:

tzsetup: /usr/share/zoneinfo/ conflicting zone definition

To fix this, add the standard "most locations" for the Europe/Chisinau
zone until the next tzdata2011n arrives.
Matthew Dillon kernel - More many-cores SMP work
* Add lwkt_yield() calls in a few critical places which can hog the cpu
  on large many-cores boxes during periods of very heavy contention.  This
  allows other kernel threads on the same cpu to run and reduces symptoms
  of e.g. high ping times under certain load conditions.

* Run the callout kernel threads at the same priority as other kernel
  threads so cpu-hogging operations run from callouts can yield to
  other kernel threads (e.g. yield to the netisr threads).

* Change the vm_page_alloc() API to catch situations where the allocation
  races an insertion due to potentially blocking when dealing with
  PQ_CACHE pages.  VM_ALLOC_NULL_OK allows vm_page_alloc() to return NULL
  in this case (otherwise it will panic).

* Change vm_page_insert() to return TRUE if the insertion succeeded and
  FALSE if it didn't due to a race against another thread.

* Change the meaning of the cpuid argument to lwkt_alloc_thread() and
  lwkt_create().  A cpuid of -1 will cause the kernel to choose a cpu
  to run the thread on (instead of choosing the current cpu).

  Eventually this specification will allow dynamic migration (but not at
  the moment).

  Adjust lwp_fork() to specify the current cpu, required for initial
  LWKT calls when setting the forked thread up.

  Numerous kernel threads will now be spread around available cpus for
  now.  devfs core threads, NFS socket threads, etc.

  Interrupt threads are still fixed on cpu 0 awaiting additional work from

  Put the emergency interrupt thread on the last cpu.

* Change the vm_page_grab() API.  When VM_ALLOC_ZERO is specified the
  vm_page_grab() code will automatically set an invalid page valid and
  zero it (using the PG_ZERO optimization if possible).  Pages which are
  already valid are not zero'd.

  This simplies several use cases.

* Change vm_fault_page() to enter the page into the pmap while the vm_map
  is still locked, instead of after unlocking it.  For now anyhow.

* Minor change to ensure that a deterministic value is stored in *freebuf
  in vn_fullpath().

* Minor debugging features added to help track down a x86-64 sge-fault
Sascha Wildner Fix i386 buildkernel. 480c83b
Sepherosa Ziehau intr: Pass cpuid to register_int and unregister_int 6355d93
Sepherosa Ziehau swi: Pass cpuid to swi register and unregister
Pass -1 as cpuid then these functions will try pin the ithread to
different CPU based on the 'intr' to be registered/unregistered.

Device and taskqueue swi ithreads' cpuid is not explicitly specified,
i.e. -1 is used, swi_vm still runs on CPU0.
Matthew Dillon kernel - add lwkt_set_interrupt_support_thread() API
* Add a new API that may be used by a device driver's support thread
  to run the thread at a higher (near interrupt) priority and allow
  it to preempt normal threads.

* Adjust the AHCI driver's helper threads to use the new API.
Matthew Dillon kernel - Clean up spinlock code, add more lwkt_yield()s
* Clean up some of the critical path in the spin_unlock() API

* Add a few more lwkt_yield()s in the buffer cache and vm_object cleaning
Matthew Dillon kernel - Another huge HUGE VM performance improvement for many-cores
This requires a bit of explanation.  The last single-point spinlocks in the
VM system were the spinlocks for the inactive and active queue.  Even though
these two spinlocks are only held for a very short period of time they can
create a major point of contention when one has (e.g.) 48 cores all trying
to run a VM fault at the same time.  This is an issue with multi-socket/
many-cores systems and not so much an issue with single-socket systems.

On many cores systems the global VM fault rate was limited to around
~200-250K zfod faults per second prior to this commit on our 48-core
opteron test box.  Since any single compiler process can run ~35K zfod
faults per second the maximum concurrency topped out at around ~7 concurrent

With this commit the global VM fault rate was tested to almost 900K zfod
faults per second.  That's 900,000 page faults per second (about 3.5 GBytes
per second).  Typical operation was consistently above 750K zfod faults per
second.  Maximum concurrency at a 35K fault rate per process is thus
increased from 7 processes to over 25 processes, and is probably approaching
the physical memory bus limit considering that one also has to take into
account generic page-fault overhead above and beyond the memory impact on the
page itself.

I can't stress enough how important it is to avoid contention entirely when
possible on a many-cores system.  In this case even though the VM page queue
spinlocks are only held for a very short period of time, the convulsing of
the cache coherency management between physical cpu sockets when all the
cores need to use the spinlock still created an enormous bottleneck.  Fixing
this one spinlock easily doubled concurrent compiler performance on our
48-core opteron.

* Fan-out the PQ_INACTIVE and PQ_ACTIVE page queues from 1 queue to
  256 queues, each with its own spin lock.

* This removes the last major contention point in the VM system.

* -j48 buildkernel test on monster (48-core opteron) now runs in 55 seconds.
  It was originally 167 seconds, and 101 seconds just prior to this commit.

  Concurrent compiles are now three times faster (a +200% improvement) on
  a many-cores box, with virtually no contention at all.
Matthew Dillon kernel - Fix vm_object->rb_memq race in pageout daemon
* We were not properly holding a VM object's token while scanning its
  rb_memq.  Hold the token properly and also assert that it is held.
John Marino Upgrade GCC from 4.4.6-RELEASE to 4.4.7 snapshot 2011-10-25 d8f1d01
John Marino Merge branch 'vendor/GCC44' 060d465
John Marino gcc44: Update version from 4.4.6-RELEASE to 4.4.7-20111025 c2c5c3f
Matthew Dillon killall - Add support for pts specifications
* killall -t <number> now uses /dev/pts/<number> instead of

  killall -t <alpha>* continues to use /dev/tty<alpha>*.
Commits on Oct 29, 2011
Matthew Dillon kernel - shmid_ds structure needs to change on 64-bit :-(
* shmid_ds had very old parameters and used 'int' for the shm segment
  size.  It has to be adjusted to use size_t to accomodate shm segments
  greater than 2GB.

  This will break binary package compatibility on 64-bit systems until
  the related packages are recompiled.

* shmget() system call now takes a size_t instead of an int.
Matthew Dillon kernel - regenerate system calls
* Regenerate system calls (shm_ds).
Matthew Dillon kernel - shmget() adjustments
* Fix prototype and manual page
Matthew Dillon kernel - Remove libc shm shims
* Remove the shims so the new system calls are used instead of shmsys().
Matthew Dillon kernel - Fix bug in shmget()
* Fix bug in shmget() which was truncating requests >= 4G.
Matthew Dillon kernel - Autosize maximum shm pages
* If not overridden with a tunable autosize sysv shm to 2/3 of available
Sascha Wildner Further shared memory adjustments to be in line with POSIX.
* shmat()'s and shmdt()'s addr argument shall be const.

* Make struct shmid_ds's shm_nattch unsigned and define the shmatt_t
  type for it.

* More manual page adjustments.
Sascha Wildner kernel: Add missing MODULE_VERSION()s for file systems.
The loader will figure out by itself whether to load a module or not,
depending on whether it's already in the kernel config or not, iif
MODULE_VERSION() is present.

I.e., if MSDOSFS (that has MODULE_VERSION()) is in the config and
msdos_load="YES" is in /boot/loader.conf, msdos.ko will not be loaded
by the loader at all.

Without MODULE_VERSION() it will lead (in the best case) to whining in
dmesg like for ahci or (in the worst case) to weird behavior, such as
for nullfs:

# mount -a
null: vfsload(null): No such file or directory

Therefore, we definitely want MODULE_VERSION() for all new modules.

This commit is the first in a series to add the missing MODULE_VERSION()s.

I know that ufs is not a module, just included it for completeness' sake.

Reported-by: marino, tuxillo
Sepherosa Ziehau x86_64/ioapic: Allow GSI's target CPU to be configured
- Tuneable hw.ioapic.gsi.X.cpu is added, which could be used to specify
  the GSI X's target CPU id
- If hw.ioapic.gsi.X is not set, then GSI X will be target to CPU Y,
  Y = X % ncpus
Sepherosa Ziehau x86_64/nexus: Per-cpu IRQ rman
Now interrupt thread will be pin to the same CPU as where its GSI
will go.
@tuxillo tuxillo libhammer - Include overlooked field freebigblocks. e2fb426
@lentferj lentferj ipcs: Adjust ipcs display to take into account new shared memory sizes aea32a3
Matthew Dillon ipcs - Make it compile w/WARNS=6
* Correct misc types, verify compilation on 32 and 64 bit
Matthew Dillon kernel - Fix deadlock in vm_prefault
* vm_prefault*() was being called while the primary vm_fault page was
  still being held busy, which could result in a deadlock.

* Reorder the case to unbusy the primary fault page before calling

Reported-by: tuxillo
Matthew Dillon kernel - Fix LINT compilation on 32-bit
* Fix conditional debug compilation that was breaking 32-bit LINT builds

Reported-by: swildner
John Marino Upgrade diffutils from 3.0 to 3.2 on the vendor branch 008e37b
John Marino Merge branch 'vendor/DIFFUTILS' 0e1bdf4
John Marino diffutils: Upgrade to version 3.2
The majority of the changes were inherited from gnulib.  There were only
a few observable differences from version 3.0:

Release 3.2 (2011-09-02) [stable]
Release 3.1 (2011-08-10) [stable]

Bug fixes
diff no longer reports spurious differences merely because two entries
in the same directory have names that compare equal in the current
locale, or compare equal because --ignore-file-name-case was given.

Changes in behavior
--ignore-file-name-case now applies at the top level too.
For example, "diff dir inIt" might compare "dir/Init" to "inIt".

New features
diff and sdiff have a new option --ignore-trailing-space (-Z).
John Marino diff: Remove location modification from 2004
diffutils has been carrying this modification since version 2.8.1.  That
version was changed to support libgnuregex which has since been removed.

It appears that likely libgnuregex didn't support the
RE_NO_POSIX_BACKTRACKING option, and thus required the modification.
John Marino Upgrade grep version 2.7 to 2.9 on the vendor branch 200fbe8
John Marino Merge branch 'vendor/GREP' 9b33b22
John Marino grep: Upgrade to version 2.9
Release 2.9 (2011-06-21) [stable]
Release 2.8 (2011-05-13) [stable]

Bug Fixes
1. echo c|grep '[c]' would fail for any c in 0x80..0xff,
   and in many locales.
   E.g., printf '\xff\n'|grep "$(printf '[\xff]')" || echo FAIL
   would print FAIL rather than the required matching line.
   [bug introduced in grep-2.6]

2. grep's interpretation of range expression is now more consistent with
   that of other tools.  [bug present since multi-byte character set
   support was introduced in 2.5.2, though the steps needed to reproduce
   it changed in grep-2.6]

3. grep erroneously returned with exit status 1 on some memory allocation
   failure. [bug present since "the beginning"]

4. grep no longer clobbers heap for an ERE like '(^| )*( |$)'
   [bug introduced in grep-2.6]

5. grep is faster on regular expressions that match multibyte characters
   in brackets (such as '[áéíóú]').

6. echo c|grep '[c]' would fail for any c in 0x80..0xff, with a uni-byte
   encoding for which the byte-to-wide-char mapping is nontrivial.  For
   example, the ISO-88591 locales are not affected, but ru_RU.KOI8-R is.
   [bug introduced in grep-2.6]

7. grep -P no longer aborts when PCRE's backtracking limit is exceeded
   Before, echo aaaaaaaaaaaaaab |grep -P '((a+)*)+$' would abort.  Now,
   it diagnoses the problem and exits with status 2.
Commits on Oct 30, 2011
@thesjg Merge branch 'master' into soc11_kev_refactor
Commits on Nov 05, 2011
@thesjg kernel - kevent refactor - Raft of fixes (1 of ?)
* Remove various kprintf debugging

* Do a better job validating filter ops vectors

* Zero-initialize memory used within kq/kev subsystem

* Off-by-one error in check against EVFILT_SYSCOUNT

* Add device clone function

* Preliminary fixes to socket_wait (unfinished)

* Fix filter init on bpf clone devices (must fix all others)