Go to file
Brian Behlendorf e2dcc6e2b8 Emergency slab objects
This patch is designed to resolve a deadlock which can occur with
__vmalloc() based slabs.  The issue is that the Linux kernel does
not honor the flags passed to __vmalloc().  This makes it unsafe
to use in a writeback context.  Unfortunately, this is a use case
ZFS depends on for correct operation.

Fixing this issue in the upstream kernel was pursued and patches
are available which resolve the issue.

  https://bugs.gentoo.org/show_bug.cgi?id=416685

However, these changes were rejected because upstream felt that
using __vmalloc() in the context of writeback should never be done.
Their solution was for us to rewrite parts of ZFS to accomidate
the Linux VM.

While that is probably the right long term solution, and it is
something we want to pursue, it is not a trivial task and will
likely destabilize the existing code.  This work has been planned
for the 0.7.0 release but in the meanwhile we want to improve the
SPL slab implementation to accomidate this expected ZFS usage.

This is accomplished by performing the __vmalloc() asynchronously
in the context of a work queue.  This doesn't prevent the posibility
of the worker thread from deadlocking.  However, the caller can now
safely block on a wait queue for the slab allocation to complete.

Normally this will occur in a reasonable amount of time and the
caller will be woken up when the new slab is available,.  The objects
will then get cached in the per-cpu magazines and everything will
proceed as usual.

However, if the __vmalloc() deadlocks for the reasons described
above, or is just very slow, then the callers on the wait queues
will timeout out.  When this rare situation occurs they will attempt
to kmalloc() a single minimally sized object using the GFP_NOIO flags.
This allocation will not deadlock because kmalloc() will honor the
passed flags and the caller will be able to make forward progress.

As long as forward progress can be maintained then even if the
worker thread is deadlocked the critical thread will make progress.
This will eventually allow the deadlocked worker thread to complete
and normal operation will resume.

These emergency allocations will likely be slow since they require
contiguous pages.  However, their use should be rare so the impact
is expected to be minimal.  If that turns out not to be the case in
practice further optimizations are possible.

One additional concern is if these emergency objects are long lived.
Right now they are simply tracked on a list which must be walked when
an object is freed.  Is they accumulate on a system and the list
grows freeing objects will become more expensive.  This could be
handled relatively easily by using a hash instead of a list, but that
optimization (if needed) is left for a follow up patch.

Additionally, these emeregency objects could be repacked in to existing
slabs as objects are freed if the kmem_cache_set_move() functionality
was implemented.  See issue https://github.com/zfsonlinux/spl/issues/26
for full details.  This work would also help reduce ZFS's memory
fragmentation problems.

The /proc/spl/kmem/slab file has had two new columns added at the
end.  The 'emerg' column reports the current number of these emergency
objects in use for the cache, and the following 'max' column shows
the historical worst case.  These value should give us a good idea
of how often these objects are needed.  Based on these values under
real use cases we can tune the default behavior.

Lastly, as a side benefit using a single work queue for the slab
allocations should reduce cpu contention on the global virtual address
space lock.   This should manifest itself as reduced cpu usage for
the system.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
2012-08-27 12:00:42 -07:00
cmd Remove autotools products 2012-08-27 11:46:23 -07:00
config Remove SPL_LINUX_CONFIG autoconf macro 2012-08-27 11:58:37 -07:00
include Emergency slab objects 2012-08-27 12:00:42 -07:00
lib Remove autotools products 2012-08-27 11:46:23 -07:00
module Emergency slab objects 2012-08-27 12:00:42 -07:00
patches Reimplement rwlocks for Linux lock profiling/analysis. 2009-09-18 16:09:47 -07:00
scripts Remove autotools products 2012-08-27 11:46:23 -07:00
.gitignore Remove autotools products 2012-08-27 11:46:23 -07:00
AUTHORS Public Release Prep 2010-05-17 15:18:00 -07:00
autogen.sh Remove autotools products 2012-08-27 11:46:23 -07:00
ChangeLog Prep for spl-0.5.0 tag 2010-08-13 09:33:50 -07:00
configure.ac Support building a spl-modules-dkms sub package 2012-08-08 13:49:40 -07:00
copy-builtin Add script for builtin module building. 2012-07-26 15:13:09 -07:00
COPYING Public Release Prep 2010-05-17 15:18:00 -07:00
DISCLAIMER Public Release Prep 2010-05-17 15:18:00 -07:00
dkms.conf.in Support building a spl-modules-dkms sub package 2012-08-08 13:49:40 -07:00
dkms.postinst Support building a spl-modules-dkms sub package 2012-08-08 13:49:40 -07:00
INSTALL Public Release Prep 2010-05-17 15:18:00 -07:00
Makefile.am Add copy-builtin to EXTRA_DIST 2012-08-23 09:59:40 -07:00
META SPL 0.6.0-rc10 2012-08-13 16:34:39 -07:00
PKGBUILD-spl-modules.in Add make rule for building Arch Linux packages 2011-12-14 16:44:10 -08:00
PKGBUILD-spl.in Add make rule for building Arch Linux packages 2011-12-14 16:44:10 -08:00
README.markdown Add script for builtin module building. 2012-07-26 15:13:09 -07:00
spl_config.h.in When checking for symbol exports, try compiling. 2012-07-26 15:12:35 -07:00
spl-modules.spec.in Cleanly remove spl-modules-devel headers 2012-08-13 16:34:32 -07:00
spl.release.in Move spl.release generation to configure step 2012-07-12 12:13:47 -07:00
spl.spec.in Fix rpm dependencies 2012-01-18 11:24:36 -08:00

The Solaris Porting Layer (SPL) is a Linux kernel module which provides many of the Solaris kernel APIs. This shim layer makes it possible to run Solaris kernel code in the Linux kernel with relatively minimal modification. This can be particularly useful when you want to track upstream Solaris development closely and dont want the overhead of maintaining a large patch which converts Solaris primitives to Linux primitives.

To build packages for your distribution:

$ ./configure
$ make pkg

To copy the kernel code inside your kernel source tree for builtin compilation:

$ ./configure --enable-linux-builtin --with-linux=/usr/src/linux-...
$ ./copy-builtin /usr/src/linux-...

Full documentation for building, configuring, and using the SPL can be found at: http://zfsonlinux.org