Skip to content

RFC btrfs: implement swap file support

Omar Sandoval linux-btrfs linux-fsdevel linux-mm linux-nfs lkml 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 RFC Latest7 patches 5 repliesIn review
  2. v25 patches 11 repliesSuperseded
  3. v1 RFC6 patches 4 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7direct-io: don't dirty ITER_BVEC pages on readfs/direct-io.c+5 -30 replies
2/7nfs: don't dirty ITER_BVEC pages read through direct I/Ofs/nfs/direct.c+4 -10 replies
3/7swap: use direct I/O for SWP_FILE swap_readpagemm/page_io.c+28 -40 replies
4/7vfs: update swap_{,de}activate documentationDocumentation/filesystems/Locking Documentation/filesystems/vfs.txt+8 -60 replies
5/7btrfs: prevent ioctls from interfering with a swap filefs/btrfs/ctree.h fs/btrfs/disk-io.c fs/btrfs/ioctl.c+35 -40 replies
6/7btrfs: add EXTENT_FLAG_SWAPFILEfs/btrfs/extent_io.c fs/btrfs/extent_map.h fs/btrfs/inode.c +1 more+5 -11 reply
7/7btrfs: enable swap file supportfs/btrfs/inode.c+131 -02 replies

Reviews trailers per patch

2 of 7 patches have a Reviewed-by or Acked-by.

PatchDave KleikampDavid Sterba
1/7A-b
2/7
3/7
4/7
5/7
6/7R-b
7/7

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [RFC PATCH v3 0/7] btrfs: implement swap file support

Hi, everyone,

This patch series, based on v3.18, implements support for swap files on BTRFS. Patches 1, 3, and 4 are for the VFS folks, patch 2 is for NFS, and the rest is all BTRFS.

The standard swap file implementation uses bmap() to get a list of physical blocks to do I/O on. This doesn't work for BTRFS, which moves disk blocks around as part of normal operation (COW, defragmentation, 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()
- direct_IO() is used to page in and out (this no longer uses readpage as part of this patch series)

Patches 1-4 clean up the necessary infrastructure. There's more that can make this better (like resurrecting kernel AIO), but that can be done as a follow-up to the work here.

Patches 5 and 6 lay the groundwork needed for using a swap file on BTRFS, and patch 7 implements the actual aops.

Version 3 incorporates a bunch of David Sterba's feedback, both style and design issues. We now audit various ioctls to prevent them from interfering with swap file operation and handle extents which can't be nocow'd.

After some discussion on the mailing list, I decided that for simplicity and reliability, it's best to simply disallow COW files and files with shared extents (like files with extents shared with a snapshot). From a user's perspective, this means that a snapshotted subvolume cannot be used for a swap file, but keeping the swap file in a separate subvolume that is never snapshotted seems entirely reasonable to me. An alternative suggestion was to allow swap files to be snapshotted and to do an implied COW on swap file activation, which I was ready to implement until I realized that we can't permit snapshotting a subvolume with an active swap file, so this creates a surprising inconsistency for users (in my opinion).

As with before, this functionality is tenuously tested in a virtual machine with some artificial workloads, but it "works for me". I'm pretty happy with the results on my end, so please comment away.

Thanks!

Omar Sandoval (7):
direct-io: don't dirty ITER_BVEC pages on read
nfs: don't dirty ITER_BVEC pages read through direct I/O
swap: use direct I/O for SWP_FILE swap_readpage
vfs: update swap_{,de}activate documentation
btrfs: prevent ioctls from interfering with a swap file
btrfs: add EXTENT_FLAG_SWAPFILE
btrfs: enable swap file support

 Documentation/filesystems/Locking |   7 +-
 Documentation/filesystems/vfs.txt |   7 +-
 fs/btrfs/ctree.h                  |   3 +
 fs/btrfs/disk-io.c                |   1 +
 fs/btrfs/extent_io.c              |   1 +
 fs/btrfs/extent_map.h             |   1 +
 fs/btrfs/inode.c                  | 132 ++++++++++++++++++++++++++++++++++++++
 fs/btrfs/ioctl.c                  |  35 ++++++++--
 fs/direct-io.c                    |   8 ++-
 fs/nfs/direct.c                   |   5 +-
 include/trace/events/btrfs.h      |   3 +-
 mm/page_io.c                      |  32 +++++++--
 12 files changed, 216 insertions(+), 19 deletions(-)
Signature · 7 lines
2.1.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>