opnsense-src/sys
Konstantin Belousov 698f05ab95 Mitigate several problems with the softdep_request_cleanup() on busy
host.

Problems start appearing when there are several threads all doing
operations on a UFS volume and the SU workqueue needs a cleanup.  It is
possible that each thread calling softdep_request_cleanup() owns the
lock for some dirty vnode (e.g. all of them are executing mkdir(2),
mknod(2), creat(2) etc) and all vnodes which must be flushed are locked
by corresponding thread. Then, we get all the threads simultaneously
entering softdep_request_cleanup().

There are two problems:
- Several threads execute MNT_VNODE_FOREACH_ALL() loops in parallel.  Due
  to the locking, they quickly start executing 'in phase' with the speed
  of the slowest thread.
- Since each thread already owns the lock for a dirty vnode, other threads
  non-blocking attempt to lock the vnode owned by other thread fail,
  and loops executing without making the progress.
Retry logic does not allow the situation to recover.  The result is
a livelock.

Fix these problems by making the following changes:
- Allow only one thread to enter MNT_VNODE_FOREACH_ALL() loop per mp.
  A new flag FLUSH_RC_ACTIVE guards the loop.
- If there were failed locking attempts during the loop, abort retry
  even if there are still work items on the mp work list.  An
  assumption is that the items will be cleaned when other thread
  either fsyncs its vnode, or unlock and allow yet another thread to
  make the progress.

It is possible now that some calls would get undeserved ENOSPC from
ffs_alloc(), because the cleanup is not aggressive enough. But I do
not see how can we reliably clean up workitems if calling
softdep_request_cleanup() while still owning the vnode lock. I thought
about scheme where ffs_alloc() returns ERESTART and saves the retry
counter somewhere in struct thread, to return to the top level, unlock
the vnode and retry.  But IMO the very rare (and unproven) spurious
ENOSPC is not worth the complications.

Reported and tested by:	pho
Style and comments by:	mckusick
Reviewed by:	mckusick
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
2017-06-03 16:18:50 +00:00
..
amd64 In r246085 some bits that are MI movied out into headers in compat/linux, 2017-05-28 08:46:57 +00:00
arm Add MULTIDELAY support to the mpcore timer driver. This is needed when 2017-06-03 15:56:54 +00:00
arm64 - Don't bother flushing the data cache for pages we're about to unmap, there's 2017-06-02 14:17:14 +00:00
boot Small cleanup in dev_net.c 2017-05-28 21:20:55 +00:00
bsm Commit the 64-bit inode project. 2017-05-23 09:29:05 +00:00
cam Introduce Genesys GL3224 quirks 2017-05-29 09:22:53 +00:00
cddl zfs_lookup: fix bogus arguments to lookup of "snapshot" directory 2017-05-29 06:30:34 +00:00
compat Improve kqueue() support in the LinuxKPI. Some applications using the 2017-06-02 16:52:18 +00:00
conf linux vdso: pass -fPIC to the assembler, not linker 2017-06-03 03:40:11 +00:00
contrib Merge ACPICA 20170531. 2017-06-01 00:01:19 +00:00
crypto Remove register keyword from sys/ and ANSIfy prototypes 2017-05-17 00:34:34 +00:00
ddb Remove register keyword from sys/ and ANSIfy prototypes 2017-05-17 00:34:34 +00:00
dev cxgbe(4): Update the statistics for compound tx work requests once per 2017-06-02 17:57:27 +00:00
fs msdosfs: use mem{cpy,move,set} instead of bcopy,bzero 2017-06-02 18:39:53 +00:00
gdb
geom Add MD_VERIFY option to enable O_VERIFY in open for vnode type. 2017-05-31 21:18:11 +00:00
gnu [mips] [rt2880] Add oldest Ralink MIPS SOC RT2880 support code. 2017-05-06 06:20:34 +00:00
i386 Remove the BSD/OS 2.1 system call gate LDT entry. 2017-05-23 22:34:18 +00:00
isa
kern Ensure that cached struct thread does not keep spurious td_su 2017-06-03 14:12:17 +00:00
kgssapi
libkern Sync qsort.c with userland r318515. 2017-05-19 06:37:16 +00:00
mips [ar71xx] rename AR724X_BASE -> std.AR724X 2017-05-31 16:32:33 +00:00
modules Support for linux ext2fs posix-draft ACLs. 2017-05-28 15:39:11 +00:00
net Call VLAN_CAPABILITIES() when LAGG capabilities change. 2017-05-26 22:22:48 +00:00
net80211 net80211: initialize i_seq for A-MPDU frames. 2017-06-01 20:46:43 +00:00
netgraph Make cached Bluetooth LE host advertise information visible from userland. 2017-04-27 15:03:24 +00:00
netinet Improve comments to describe what the code does. 2017-06-01 15:11:18 +00:00
netinet6 Fix an unnecessary/incorrect check in the PKTOPT_EXTHDRCPY macro. 2017-05-30 14:50:28 +00:00
netipsec Build kdebug_secreplay() function only when IPSEC_DEBUG is defined. 2017-06-01 10:04:12 +00:00
netpfil Fix the queue delay estimation in PIE/FQ-PIE when the timestamp 2017-05-19 08:38:03 +00:00
netsmb
nfs
nfsclient Add an NFSv4.1 mount option for "use one openowner". 2017-04-13 21:54:19 +00:00
nfsserver
nlm Commit the 64-bit inode project. 2017-05-23 09:29:05 +00:00
ofed All these files need sys/vmmeter.h, but now they got it implicitly 2017-04-17 17:07:00 +00:00
opencrypto Use const with some read-only buffers in opencrypto APIs. 2017-05-09 18:28:42 +00:00
powerpc Add a driver for the Chelsio T6 crypto accelerator engine. 2017-05-17 22:13:07 +00:00
riscv Follow r317061 "Remove struct vmmeter from struct pcpu" 2017-04-19 17:06:32 +00:00
rpc * limit size of buffers to RPC_MAXDATASIZE 2017-06-01 06:12:25 +00:00
security Commit the 64-bit inode project. 2017-05-23 09:29:05 +00:00
sparc64 fix sparc64 build by restoring 'register' in pcpu.h 2017-05-17 16:32:24 +00:00
sys Rename accept filter getopt/setopt functions, so that they are prefixed 2017-06-02 17:49:21 +00:00
teken Oops, my fix for bright colors broke bright black some more (in cases 2017-03-27 10:48:28 +00:00
tests style(9): sort headers 2017-05-09 05:08:47 +00:00
tools Declare the "snd_fxdiv_table" once. This shaves around 24Kbytes of 2017-05-25 05:23:47 +00:00
ufs Mitigate several problems with the softdep_request_cleanup() on busy 2017-06-03 16:18:50 +00:00
vm As old prophecy says, some day UMA_DEBUG printfs shall be made CTRs. 2017-06-01 18:36:52 +00:00
x86 fix indentation 2017-05-30 13:53:03 +00:00
xdr * limit size of buffers to RPC_MAXDATASIZE 2017-06-01 06:12:25 +00:00
xen
Makefile Remove glimpse make target added in r181432 2017-05-22 15:53:30 +00:00