From: Nikolay Borisov <nborisov@suse.com>
To: Omar Sandoval <osandov@osandov.com>, linux-btrfs@vger.kernel.org
Cc: kernel-team@fb.com, linux-fsdevel@vger.kernel.org,
Tejun Heo <tj@kernel.org>
Subject: Re: [RFC PATCH v4 1/6] mm: split SWP_FILE into SWP_ACTIVATED and SWP_FS
Date: Fri, 25 May 2018 12:11:36 +0300 [thread overview]
Message-ID: <6fe668b5-f94a-0473-f9ab-a0e2b355ab91@suse.com> (raw)
In-Reply-To: <289f334fa8e5d1239eab667415d287edf0e13f14.1527197312.git.osandov@fb.com>
On 25.05.2018 00:41, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
>
> The SWP_FILE flag serves two purposes: to make swap_{read,write}page()
> go through the filesystem, and to make swapoff() call
> ->swap_deactivate(). For Btrfs, we want the latter but not the former,
> so split this flag into two. This makes us always call
> ->swap_deactivate() if ->swap_activate() succeeded, not just if it
> didn't add any swap extents itself.
>
> This also resolves the issue of the very misleading name of SWP_FILE,
> which is only used for swap files over NFS.
>
> Signed-off-by: Omar Sandoval <osandov@fb.com>
Generally looks good:
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
just one cleanup suggestion, see below.
> ---
> include/linux/swap.h | 13 +++++++------
> mm/page_io.c | 6 +++---
> mm/swapfile.c | 13 ++++++++-----
> 3 files changed, 18 insertions(+), 14 deletions(-)
>
> diff --git a/include/linux/swap.h b/include/linux/swap.h
> index 2417d288e016..29dfd436435c 100644
> --- a/include/linux/swap.h
> +++ b/include/linux/swap.h
> @@ -167,13 +167,14 @@ enum {
> SWP_SOLIDSTATE = (1 << 4), /* blkdev seeks are cheap */
> SWP_CONTINUED = (1 << 5), /* swap_map has count continuation */
> SWP_BLKDEV = (1 << 6), /* its a block device */
> - SWP_FILE = (1 << 7), /* set after swap_activate success */
> - SWP_AREA_DISCARD = (1 << 8), /* single-time swap area discards */
> - SWP_PAGE_DISCARD = (1 << 9), /* freed swap page-cluster discards */
> - SWP_STABLE_WRITES = (1 << 10), /* no overwrite PG_writeback pages */
> - SWP_SYNCHRONOUS_IO = (1 << 11), /* synchronous IO is efficient */
> + SWP_ACTIVATED = (1 << 7), /* set after swap_activate success */
> + SWP_FS = (1 << 8), /* swap file goes through fs */
> + SWP_AREA_DISCARD = (1 << 9), /* single-time swap area discards */
> + SWP_PAGE_DISCARD = (1 << 10), /* freed swap page-cluster discards */
> + SWP_STABLE_WRITES = (1 << 11), /* no overwrite PG_writeback pages */
> + SWP_SYNCHRONOUS_IO = (1 << 12), /* synchronous IO is efficient */
> /* add others here before... */
> - SWP_SCANNING = (1 << 12), /* refcount in scan_swap_map */
> + SWP_SCANNING = (1 << 13), /* refcount in scan_swap_map */
> };
>
> #define SWAP_CLUSTER_MAX 32UL
> diff --git a/mm/page_io.c b/mm/page_io.c
> index b41cf9644585..f2d06c1d0cc1 100644
> --- a/mm/page_io.c
> +++ b/mm/page_io.c
> @@ -283,7 +283,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
> struct swap_info_struct *sis = page_swap_info(page);
>
> VM_BUG_ON_PAGE(!PageSwapCache(page), page);
> - if (sis->flags & SWP_FILE) {
> + if (sis->flags & SWP_FS) {
Not necessarily for this series but something to keep in mind:
nit: The way the fs case is tucked onto the __swap_writepage is a bit
ugly. How about factoring out the filesystem/blockdev casae into two
functions :
__swap_writepage_fs/__swap_writepage_bdev
then in swap_writepage we just have the if (sis->flags & SWP_FS) check
and dispatch to either write_page_fs or writepage_bdev.
> struct kiocb kiocb;
> struct file *swap_file = sis->swap_file;
> struct address_space *mapping = swap_file->f_mapping;
> @@ -364,7 +364,7 @@ int swap_readpage(struct page *page, bool synchronous)
> goto out;
> }
>
> - if (sis->flags & SWP_FILE) {
> + if (sis->flags & SWP_FS) {
> struct file *swap_file = sis->swap_file;
> struct address_space *mapping = swap_file->f_mapping;
>
> @@ -422,7 +422,7 @@ int swap_set_page_dirty(struct page *page)
> {
> struct swap_info_struct *sis = page_swap_info(page);
>
> - if (sis->flags & SWP_FILE) {
> + if (sis->flags & SWP_FS) {
> struct address_space *mapping = sis->swap_file->f_mapping;
>
> VM_BUG_ON_PAGE(!PageSwapCache(page), page);
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index cc2cf04d9018..886c9d89b144 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -973,7 +973,7 @@ int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[])
> goto nextsi;
> }
> if (cluster) {
> - if (!(si->flags & SWP_FILE))
> + if (!(si->flags & SWP_FS))
> n_ret = swap_alloc_cluster(si, swp_entries);
> } else
> n_ret = scan_swap_map_slots(si, SWAP_HAS_CACHE,
> @@ -2327,12 +2327,13 @@ static void destroy_swap_extents(struct swap_info_struct *sis)
> kfree(se);
> }
>
> - if (sis->flags & SWP_FILE) {
> + if (sis->flags & SWP_ACTIVATED) {
> struct file *swap_file = sis->swap_file;
> struct address_space *mapping = swap_file->f_mapping;
>
> - sis->flags &= ~SWP_FILE;
> - mapping->a_ops->swap_deactivate(swap_file);
> + sis->flags &= ~SWP_ACTIVATED;
> + if (mapping->a_ops->swap_deactivate)
> + mapping->a_ops->swap_deactivate(swap_file);
> }
> }
>
> @@ -2428,8 +2429,10 @@ static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span)
>
> if (mapping->a_ops->swap_activate) {
> ret = mapping->a_ops->swap_activate(sis, swap_file, span);
> + if (ret >= 0)
> + sis->flags |= SWP_ACTIVATED;
> if (!ret) {
> - sis->flags |= SWP_FILE;
> + sis->flags |= SWP_FS;
> ret = add_swap_extent(sis, 0, sis->max, 0);
> *span = sis->pages;
> }
>
next prev parent reply other threads:[~2018-05-25 9:11 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-24 21:41 [RFC PATCH v4 0/6] Btrfs: implement swap file support Omar Sandoval
2018-05-24 21:41 ` [RFC PATCH v4 1/6] mm: split SWP_FILE into SWP_ACTIVATED and SWP_FS Omar Sandoval
2018-05-25 9:11 ` Nikolay Borisov [this message]
2018-05-24 21:41 ` [RFC PATCH v4 2/6] vfs: update swap_{,de}activate documentation Omar Sandoval
2018-05-25 9:15 ` Nikolay Borisov
2018-05-24 21:41 ` [RFC PATCH v4 3/6] Btrfs: push EXCL_OP set into btrfs_rm_device() Omar Sandoval
2018-05-25 9:19 ` Nikolay Borisov
2018-05-28 13:29 ` David Sterba
2018-05-24 21:41 ` [RFC PATCH v4 4/6] Btrfs: prevent ioctls from interfering with a swap file Omar Sandoval
2018-05-25 14:50 ` David Sterba
2018-05-25 16:00 ` Omar Sandoval
2018-05-25 16:10 ` David Sterba
2018-08-21 8:46 ` Omar Sandoval
2018-05-24 21:41 ` [RFC PATCH v4 5/6] Btrfs: rename get_chunk_map() and make it non-static Omar Sandoval
2018-05-25 9:21 ` Nikolay Borisov
2018-05-25 16:02 ` Omar Sandoval
2018-05-24 21:41 ` [RFC PATCH v4 6/6] Btrfs: support swap files Omar Sandoval
2018-05-25 10:07 ` Nikolay Borisov
2018-05-25 16:16 ` Omar Sandoval
2018-05-28 13:46 ` David Sterba
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=6fe668b5-f94a-0473-f9ab-a0e2b355ab91@suse.com \
--to=nborisov@suse.com \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=osandov@osandov.com \
--cc=tj@kernel.org \
/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).