Skip to content

Commit cba738f

Browse files
neilbrownakpm00
authored andcommitted
doc: update documentation for swap_activate and swap_rw
This documentation for ->swap_activate() has been out-of-date for a long time. This patch updates it to match recent changes, and adds documentation for the associated ->swap_rw() Link: https://lkml.kernel.org/r/164859778126.29473.6778751233552859461.stgit@noble.brown Signed-off-by: NeilBrown <neilb@suse.de> Reviewed-by: Christoph Hellwig <hch@lst.de> Tested-by: David Howells <dhowells@redhat.com> Tested-by: Geert Uytterhoeven <geert+renesas@glider.be> Cc: Hugh Dickins <hughd@google.com> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: Trond Myklebust <trond.myklebust@hammerspace.com> Cc: Miaohe Lin <linmiaohe@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 7eadabc commit cba738f

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

Documentation/filesystems/locking.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,9 @@ prototypes::
258258
int (*launder_folio)(struct folio *);
259259
bool (*is_partially_uptodate)(struct folio *, size_t from, size_t count);
260260
int (*error_remove_page)(struct address_space *, struct page *);
261-
int (*swap_activate)(struct file *);
261+
int (*swap_activate)(struct swap_info_struct *sis, struct file *f, sector_t *span)
262262
int (*swap_deactivate)(struct file *);
263+
int (*swap_rw)(struct kiocb *iocb, struct iov_iter *iter);
263264

264265
locking rules:
265266
All except dirty_folio and freepage may block
@@ -287,6 +288,7 @@ is_partially_uptodate: yes
287288
error_remove_page: yes
288289
swap_activate: no
289290
swap_deactivate: no
291+
swap_rw: yes, unlocks
290292
====================== ======================== ========= ===============
291293

292294
->write_begin(), ->write_end() and ->readpage() may be called from
@@ -386,15 +388,19 @@ cleaned, or an error value if not. Note that in order to prevent the folio
386388
getting mapped back in and redirtied, it needs to be kept locked
387389
across the entire operation.
388390

389-
->swap_activate will be called with a non-zero argument on
390-
files backing (non block device backed) swapfiles. A return value
391-
of zero indicates success, in which case this file can be used for
392-
backing swapspace. The swapspace operations will be proxied to the
393-
address space operations.
391+
->swap_activate() will be called to prepare the given file for swap. It
392+
should perform any validation and preparation necessary to ensure that
393+
writes can be performed with minimal memory allocation. It should call
394+
add_swap_extent(), or the helper iomap_swapfile_activate(), and return
395+
the number of extents added. If IO should be submitted through
396+
->swap_rw(), it should set SWP_FS_OPS, otherwise IO will be submitted
397+
directly to the block device ``sis->bdev``.
394398

395399
->swap_deactivate() will be called in the sys_swapoff()
396400
path after ->swap_activate() returned success.
397401

402+
->swap_rw will be called for swap IO if SWP_FS_OPS was set by ->swap_activate().
403+
398404
file_lock_operations
399405
====================
400406

Documentation/filesystems/vfs.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,9 @@ cache in your filesystem. The following members are defined:
749749
size_t count);
750750
void (*is_dirty_writeback) (struct page *, bool *, bool *);
751751
int (*error_remove_page) (struct mapping *mapping, struct page *page);
752-
int (*swap_activate)(struct file *);
752+
int (*swap_activate)(struct swap_info_struct *sis, struct file *f, sector_t *span)
753753
int (*swap_deactivate)(struct file *);
754+
int (*swap_rw)(struct kiocb *iocb, struct iov_iter *iter);
754755
};
755756
756757
``writepage``
@@ -952,15 +953,21 @@ cache in your filesystem. The following members are defined:
952953
unless you have them locked or reference counts increased.
953954

954955
``swap_activate``
955-
Called when swapon is used on a file to allocate space if
956-
necessary and pin the block lookup information in memory. A
957-
return value of zero indicates success, in which case this file
958-
can be used to back swapspace.
956+
957+
Called to prepare the given file for swap. It should perform
958+
any validation and preparation necessary to ensure that writes
959+
can be performed with minimal memory allocation. It should call
960+
add_swap_extent(), or the helper iomap_swapfile_activate(), and
961+
return the number of extents added. If IO should be submitted
962+
through ->swap_rw(), it should set SWP_FS_OPS, otherwise IO will
963+
be submitted directly to the block device ``sis->bdev``.
959964

960965
``swap_deactivate``
961966
Called during swapoff on files where swap_activate was
962967
successful.
963968

969+
``swap_rw``
970+
Called to read or write swap pages when SWP_FS_OPS is set.
964971

965972
The File Object
966973
===============

0 commit comments

Comments
 (0)