[PATCH 24/30] mm: add support for non block device backed swap files

Previous thread: [PATCH 11/30] mm: __GFP_MEMALLOC by Peter Zijlstra on Thursday, July 24, 2008 - 7:00 am. (4 messages)

Next thread: [PATCH 13/30] selinux: tag avc cache alloc as non-critical by Peter Zijlstra on Thursday, July 24, 2008 - 7:00 am. (1 message)
From: Peter Zijlstra
Date: Thursday, July 24, 2008 - 7:01 am

New addres_space_operations methods are added:
  int swapon(struct file *);
  int swapoff(struct file *);
  int swap_out(struct file *, struct page *, struct writeback_control *);
  int swap_in(struct file *, struct page *);

When during sys_swapon() the ->swapon() method is found and returns no error
the swapper_space.a_ops will proxy to sis->swap_file->f_mapping->a_ops, and
make use of ->swap_{out,in}() to write/read swapcache pages.

The ->swapon() method will be used to communicate to the file that the VM
relies on it, and the address_space should take adequate measures (like
reserving memory for mempools or the like). The ->swapoff() method will be
called on sys_swapoff() when ->swapon() was found and returned no error.

This new interface can be used to obviate the need for ->bmap in the swapfile
code. A filesystem would need to load (and maybe even allocate) the full block
map for a file into memory and pin it there on ->swapon() so that
->swap_{out,in}() have instant access to it. It can be released on ->swapoff().

The reason to provide ->swap_{out,in}() over using {write,read}page() is to
 1) make a distinction between swapcache and pagecache pages, and
 2) to provide a struct file * for credential context (normally not needed
    in the context of writepage, as the page content is normally dirtied
    using either of the following interfaces:
      write_{begin,end}()
      {prepare,commit}_write()
      page_mkwrite()
    which do have the file context.

[miklos@szeredi.hu: cleanups]
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 Documentation/filesystems/Locking |   22 ++++++++++++++++
 Documentation/filesystems/vfs.txt |   18 +++++++++++++
 include/linux/buffer_head.h       |    2 -
 include/linux/fs.h                |    9 ++++++
 include/linux/swap.h              |    4 ++
 mm/page_io.c                      |   52 ++++++++++++++++++++++++++++++++++++++
 mm/swap_state.c                   |    4 +-
 mm/swapfile.c                     |   32 ...
Previous thread: [PATCH 11/30] mm: __GFP_MEMALLOC by Peter Zijlstra on Thursday, July 24, 2008 - 7:00 am. (4 messages)

Next thread: [PATCH 13/30] selinux: tag avc cache alloc as non-critical by Peter Zijlstra on Thursday, July 24, 2008 - 7:00 am. (1 message)