linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Omar Sandoval <osandov@osandov.com>
To: linux-btrfs@vger.kernel.org
Cc: Mel Gorman <mgorman@suse.de>,
	linux-kernel@vger.kernel.org, <linux-fsdevel@vger.kernel.org>,
	Omar Sandoval <osandov@osandov.com>
Subject: [RFC PATCH 0/6] btrfs: implement swap file support
Date: Mon, 17 Nov 2014 02:36:53 -0800	[thread overview]
Message-ID: <cover.1416219974.git.osandov@osandov.com> (raw)

This patch series, based on 3.18-rc5, implements support for swap files on
BTRFS.

The standard swap file implementation uses the filesystem's implementation of
bmap() to get a list of physical blocks on disk, which the swap file code then
does I/O on directly without going through the filesystem. This doesn't work
for BTRFS, which is copy-on-write and therefore moves disk blocks around (COW
isn't the only thing that can shuffle around disk blocks: consider
defragmentation, balancing, etc.).

Swap-over-NFS introduced an interface through which a filesystem can arbitrate
swap I/O through address space operations:

- swap_activate() is called by swapon() and informs the address space that the
  given file is going to be used for swap, so it should take adequate measures
  like reserving space on disk and pinning block lookup information in memory
- swap_deactivate() is used to clean up on swapoff()
- readpage() is used to page in (read a page from disk)
- direct_IO() is used to page out (write a page out to disk)

This patch series uses that interface to add support for swap files to BTRFS.

A few things make the implementation a bit hairier than simply adding a
btrfs_swap_activate. In particular, pages in the swap cache behave a bit
differently:

- Swapcache pages store a swp_entry_t in ->private, and the VM system
  doesn't like PG_private being set on swapcache pages. This means that the
  private field isn't available for the filesystem.
- Swapcache pages don't use the ->mapping or ->index fields; swapcache
  pages must use page_file_{mapping,index,offset} instead, which uses the
  swp_entry_t in ->private to get the same information. This calls for some
  nasty global search and replace.

A few other considerations specific to BTRFS:

- We can't do direct I/O on compressed or inline extents.
- Supporting COW swapfiles might come with some weird edge cases? This is
  something that is probably good for discussion.

This functionality is tenuously tested in a virtual machine with some
artificial workloads. I'd really appreciate any comments.

Omar Sandoval (6):
  btrfs: convert uses of ->mapping and ->index to wrappers
  btrfs: don't allow -C or +c chattrs on a swap file
  btrfs: don't set ->private on swapcache pages
  btrfs: don't check the cleancache for swapcache pages
  btrfs: don't mark extents used for swap as up to date
  btrfs: enable swap file support

 fs/btrfs/disk-io.c    |  16 ++---
 fs/btrfs/extent_io.c  | 174 ++++++++++++++++++++++++++++----------------------
 fs/btrfs/file-item.c  |   6 +-
 fs/btrfs/inode.c      | 119 +++++++++++++++++++++++++++-------
 fs/btrfs/ioctl.c      |  60 ++++++++++-------
 fs/btrfs/relocation.c |   2 +-
 fs/btrfs/scrub.c      |   4 +-
 7 files changed, 242 insertions(+), 139 deletions(-)

-- 
2.1.3


             reply	other threads:[~2014-11-17 10:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-17 10:36 Omar Sandoval [this message]
2014-11-17 10:36 ` [RFC PATCH 1/6] btrfs: convert uses of ->mapping and ->index to wrappers Omar Sandoval
2014-11-17 10:36 ` [RFC PATCH 2/6] btrfs: don't allow -C or +c chattrs on a swap file Omar Sandoval
2014-11-17 10:36 ` [RFC PATCH 3/6] btrfs: don't set ->private on swapcache pages Omar Sandoval
2014-11-17 10:36 ` [RFC PATCH 4/6] btrfs: don't check the cleancache for " Omar Sandoval
2014-11-17 10:36 ` [RFC PATCH 5/6] btrfs: don't mark extents used for swap as up to date Omar Sandoval
2014-11-17 10:36 ` [RFC PATCH 6/6] btrfs: enable swap file support Omar Sandoval
2014-11-17 15:48 ` [RFC PATCH 0/6] btrfs: implement " Christoph Hellwig
2014-11-19  7:22   ` Omar Sandoval
2014-11-21 10:06     ` Christoph Hellwig
2014-11-21 10:12       ` Omar Sandoval

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1416219974.git.osandov@osandov.com \
    --to=osandov@osandov.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).