tmpfs - Fix data loss issues
authorMatthew Dillon <dillon@apollo.backplane.com>
Sun, 11 Feb 2018 06:18:19 +0000 (22:18 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sun, 11 Feb 2018 06:48:27 +0000 (22:48 -0800)
commita1b829f26cc7a233e4b9acf03ea71c2379ec8f64
tree8bca8a975bb2088f5dc0a785c0a26783471c524a
parentc1f5cf510ddf6549261d5d542525a7e06597cac3
tmpfs - Fix data loss issues

* Fix a data loss issue that can occur when vnodes are cycled.  This
  can be replicated by setting kern.maxvnodes to a fairly low value.
  Vnode recycling does not necessarily issue a vinvalbuf() when clean
  pages are present, which tmpfs needs to retain.

* Fix a data loss issue when swap becomes full or when the system has
  no swap configured.  When tmpfs tries to flush to swap and fails,
  pages can remain associated with the vnode after the vinvalbuf()
  call, and then lost when the vnode is recycled.

* The above fixes are accomplished by call vinvalbuf() on vnode deactivation
  to make sure that all buffers have been flushed, and then moving any
  pages that remain to tn_aobj.

  The pages are moved back when the vnode is reinstantiated and an open(),
  read(), write(), or setattr (i.e.  truncation or extension) is called.

  We try to avoid moving the pages back if the vnode is merely *stat()d
  or deleted.

* Use cluster_read() by default to try to improve read throughput when
  pages are swap-backed.

Reported-by: zrj, marino
sys/vfs/tmpfs/tmpfs.h
sys/vfs/tmpfs/tmpfs_subr.c
sys/vfs/tmpfs/tmpfs_vnops.c