kernel - SWAP CACHE part 8/many - Add the swap cache read intercept, rate ctl
authorMatthew Dillon <dillon@apollo.backplane.com>
Thu, 4 Feb 2010 22:56:42 +0000 (14:56 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Thu, 4 Feb 2010 22:56:42 +0000 (14:56 -0800)
commitc504e38ecd4536447026bf29e61a391cd2340ec3
tree73113d0421e0e4beab0ed7fde8d9e141bdb676f2
parent451a550e8e883d4be3ae3b79ec27df8fd75cd623
kernel - SWAP CACHE part 8/many - Add the swap cache read intercept, rate ctl

* Add vn_cache_strategy() and adjust vn_strategy() to call it.  This
  implements the read intercept.  If vn_cache_strategy() determines that
  the entire request can be handled by the swap cache it issues an
  appropriate swap_pager_strategy() call and returns 1, else it returns 0
  and the normal vn_strategy() function is run.

  vn_cache_strategy() only intercepts READ's which meet some fairly strict
  requirements, including no bogus pages and page alignment (so certain
  meta-data in UFS which uses a 6144 byte block size cannot be read via
  the swap cache, sorry).

* Implement numerous sysctls.

  vm.swapcache.accrate (default 1000000)

     The average long-term write rate in bytes/second for writing
     data to the swap cache.  This is what ultimately controls the
     wear rate of the SSD swap.

  vm.swapcache.maxburst (default 1000000000)
  vm.swapcache.curburst (default starts at 1000000000)

     On machine boot curburst defaults to maxburst and will automatically
     be trimmed to maxburst if you change maxburst.  This allows a high
     write-rate after boot.

     During normal operation writes reduce curburst and accrate increases
     curburst (up to maxburst), so periods of inactivity will allow another
     burst of write activity later on.

  vm.swapcache.read_enable (default 0 - disabled)

     Enable the swap cache read intercept.  When turned on vn_strategy()
     calls will read from the swap cache if possible.  When turned off
     vn_strategy() calls read from the underlying vnode whether data
     is available in the swap cache or not.

  vm.swapcache.meta_enable (default 0 - disabled)

     Enable swap caching of meta-data (The VM-backed block devices used
     by filesystems).  The swapcache code scans the VM page inactive
     queue for suitable clean VCHR-backed VM pages and writes them to
     the swap cache.

  vm.swapcache.data_enable (default 0 - disabled)

     Enable swap caching of data (Regular files).  The swapcache code
     scans the VM page inactive queue for suitable clean VREG-backed VM
     pages and writes them to the swap cache.

  vm.swapcache.maxlaunder (default 128 pages per 1/10 second)

     Specifies the maximum number of pages in the inactive queue to
     scan every 1/10 second.  Set fairly low for the moment but
     the default will ultimately be increased to something like 512
     or 1024.

  vm.swapcache.write_count

     The total amount of data written by the swap cache to swap,
     in bytes, since boot.

* Call swap_pager_unswapped() in a few more places that need it.

* NFS doesn't use bread/vn_strategy so it has been modified to call
  vn_cache_strategy() directly for async IO.  Currently we cannot
  easily do it for synchronous IO.  But async IO will get most of
  it.

* The swap cache will use up to 2/3 of available swap space to
  cache clean vnode-backed data.  Currently once this limit is
  reached it will rely on vnode recycling to clean out space
  and make room for more.

  Vnode recycling is currently excessively limiting the amount of
  data which can be cached, since when a vnode is recycled it's
  backing VM object is also recycled and the swap cache assignments
  are freed.  Meta-data has other problems... it can choke the
  swap cache.

  Dealing with these issues is on the TODO.
sys/kern/vfs_bio.c
sys/sys/vnode.h
sys/vfs/nfs/nfs_bio.c
sys/vm/swap_pager.c
sys/vm/swap_pager.h
sys/vm/vm_pageout.c
sys/vm/vm_swapcache.c