All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ric Mason <ric.masonn@gmail.com>
To: Mel Gorman <mgorman@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Jerome Marchand <jmarchan@redhat.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH] mm: swap: Mark swap pages writeback before queueing for direct IO
Date: Wed, 01 May 2013 14:58:03 +0800	[thread overview]
Message-ID: <5180BCFB.6090707@gmail.com> (raw)
In-Reply-To: <20130424185744.GB2144@suse.de>

Hi Mel,
On 04/25/2013 02:57 AM, Mel Gorman wrote:
> As pointed out by Andrew Morton, the swap-over-NFS writeback is not setting
> PageWriteback before it is queued for direct IO. While swap pages do not

Before commit commit 62c230bc1 (mm: add support for a filesystem to 
activate swap files and use direct_IO for writing swap pages), swap 
pages will write to page cache firstly and then writeback?

> participate in BDI or process dirty accounting and the IO is synchronous,
> the writeback bit is still required and not setting it in this case was
> an oversight.  swapoff depends on the page writeback to synchronoise all
> pending writes on a swap page before it is reused. Swapcache freeing and
> reuse depend on checking the PageWriteback under lock to ensure the page
> is safe to reuse.
>
> Direct IO handlers and the direct IO handler for NFS do not deal with
> PageWriteback as they are synchronous writes. In the case of NFS, it
> schedules pages (or a page in the case of swap) for IO and then waits
> synchronously for IO to complete in nfs_direct_write(). It is recognised
> that this is a slowdown from normal swap handling which is asynchronous
> and uses a completion handler. Shoving PageWriteback handling down into
> direct IO handlers looks like a bad fit to handle the swap case although
> it may have to be dealt with some day if swap is converted to use direct
> IO in general and bmap is finally done away with. At that point it will
> be necessary to refit asynchronous direct IO with completion handlers onto
> the swap subsystem.
>
> As swapcache currently depends on PageWriteback to protect against races,
> this patch sets PageWriteback under the page lock before queueing it for
> direct IO. It is cleared when the direct IO handler returns. IO errors
> are treated similarly to the direct-to-bio case except PageError is not
> set as in the case of swap-over-NFS, it is likely to be a transient error.
>
> It was asked what prevents such a page being reclaimed in parallel.
> With this patch applied, such a page will now be skipped (most of the time)
> or blocked until the writeback completes.  Reclaim checks PageWriteback
> under the page lock before calling try_to_free_swap and the page lock
> should prevent the page being requeued for IO before it is freed.
>
> This and Jerome's related patch should considered for -stable as far
> back as 3.6 when swap-over-NFS was introduced.
>
> Signed-off-by: Mel Gorman <mgorman@suse.de>
> ---
>   mm/page_io.c | 17 +++++++++++++++++
>   1 file changed, 17 insertions(+)
>
> diff --git a/mm/page_io.c b/mm/page_io.c
> index 04ca00d..ec04247 100644
> --- a/mm/page_io.c
> +++ b/mm/page_io.c
> @@ -214,6 +214,7 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
>   		kiocb.ki_left = PAGE_SIZE;
>   		kiocb.ki_nbytes = PAGE_SIZE;
>   
> +		set_page_writeback(page);
>   		unlock_page(page);
>   		ret = mapping->a_ops->direct_IO(KERNEL_WRITE,
>   						&kiocb, &iov,
> @@ -223,8 +224,24 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
>   			count_vm_event(PSWPOUT);
>   			ret = 0;
>   		} else {
> +			/*
> +			 * In the case of swap-over-nfs, this can be a
> +			 * temporary failure if the system has limited
> +			 * memory for allocating transmit buffers.
> +			 * Mark the page dirty and avoid
> +			 * rotate_reclaimable_page but rate-limit the
> +			 * messages but do not flag PageError like
> +			 * the normal direct-to-bio case as it could
> +			 * be temporary.
> +			 */
>   			set_page_dirty(page);
> +			ClearPageReclaim(page);
> +			if (printk_ratelimit()) {
> +				pr_err("Write-error on dio swapfile (%Lu)\n",
> +					(unsigned long long)page_file_offset(page));
> +			}
>   		}
> +		end_page_writeback(page);
>   		return ret;
>   	}
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

WARNING: multiple messages have this Message-ID (diff)
From: Ric Mason <ric.masonn@gmail.com>
To: Mel Gorman <mgorman@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Jerome Marchand <jmarchan@redhat.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH] mm: swap: Mark swap pages writeback before queueing for direct IO
Date: Wed, 01 May 2013 14:58:03 +0800	[thread overview]
Message-ID: <5180BCFB.6090707@gmail.com> (raw)
In-Reply-To: <20130424185744.GB2144@suse.de>

Hi Mel,
On 04/25/2013 02:57 AM, Mel Gorman wrote:
> As pointed out by Andrew Morton, the swap-over-NFS writeback is not setting
> PageWriteback before it is queued for direct IO. While swap pages do not

Before commit commit 62c230bc1 (mm: add support for a filesystem to 
activate swap files and use direct_IO for writing swap pages), swap 
pages will write to page cache firstly and then writeback?

> participate in BDI or process dirty accounting and the IO is synchronous,
> the writeback bit is still required and not setting it in this case was
> an oversight.  swapoff depends on the page writeback to synchronoise all
> pending writes on a swap page before it is reused. Swapcache freeing and
> reuse depend on checking the PageWriteback under lock to ensure the page
> is safe to reuse.
>
> Direct IO handlers and the direct IO handler for NFS do not deal with
> PageWriteback as they are synchronous writes. In the case of NFS, it
> schedules pages (or a page in the case of swap) for IO and then waits
> synchronously for IO to complete in nfs_direct_write(). It is recognised
> that this is a slowdown from normal swap handling which is asynchronous
> and uses a completion handler. Shoving PageWriteback handling down into
> direct IO handlers looks like a bad fit to handle the swap case although
> it may have to be dealt with some day if swap is converted to use direct
> IO in general and bmap is finally done away with. At that point it will
> be necessary to refit asynchronous direct IO with completion handlers onto
> the swap subsystem.
>
> As swapcache currently depends on PageWriteback to protect against races,
> this patch sets PageWriteback under the page lock before queueing it for
> direct IO. It is cleared when the direct IO handler returns. IO errors
> are treated similarly to the direct-to-bio case except PageError is not
> set as in the case of swap-over-NFS, it is likely to be a transient error.
>
> It was asked what prevents such a page being reclaimed in parallel.
> With this patch applied, such a page will now be skipped (most of the time)
> or blocked until the writeback completes.  Reclaim checks PageWriteback
> under the page lock before calling try_to_free_swap and the page lock
> should prevent the page being requeued for IO before it is freed.
>
> This and Jerome's related patch should considered for -stable as far
> back as 3.6 when swap-over-NFS was introduced.
>
> Signed-off-by: Mel Gorman <mgorman@suse.de>
> ---
>   mm/page_io.c | 17 +++++++++++++++++
>   1 file changed, 17 insertions(+)
>
> diff --git a/mm/page_io.c b/mm/page_io.c
> index 04ca00d..ec04247 100644
> --- a/mm/page_io.c
> +++ b/mm/page_io.c
> @@ -214,6 +214,7 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
>   		kiocb.ki_left = PAGE_SIZE;
>   		kiocb.ki_nbytes = PAGE_SIZE;
>   
> +		set_page_writeback(page);
>   		unlock_page(page);
>   		ret = mapping->a_ops->direct_IO(KERNEL_WRITE,
>   						&kiocb, &iov,
> @@ -223,8 +224,24 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
>   			count_vm_event(PSWPOUT);
>   			ret = 0;
>   		} else {
> +			/*
> +			 * In the case of swap-over-nfs, this can be a
> +			 * temporary failure if the system has limited
> +			 * memory for allocating transmit buffers.
> +			 * Mark the page dirty and avoid
> +			 * rotate_reclaimable_page but rate-limit the
> +			 * messages but do not flag PageError like
> +			 * the normal direct-to-bio case as it could
> +			 * be temporary.
> +			 */
>   			set_page_dirty(page);
> +			ClearPageReclaim(page);
> +			if (printk_ratelimit()) {
> +				pr_err("Write-error on dio swapfile (%Lu)\n",
> +					(unsigned long long)page_file_offset(page));
> +			}
>   		}
> +		end_page_writeback(page);
>   		return ret;
>   	}
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>


  parent reply	other threads:[~2013-05-01  6:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-17 12:11 [PATCH] swap: redirty page if page write fails on swap file Jerome Marchand
2013-04-17 12:11 ` Jerome Marchand
2013-04-17 15:07 ` Johannes Weiner
2013-04-17 15:07   ` Johannes Weiner
2013-04-17 15:08 ` Mel Gorman
2013-04-17 15:08   ` Mel Gorman
2013-04-18  0:13 ` Simon Jeons
2013-04-18  0:13   ` Simon Jeons
2013-05-01  7:39   ` Simon Jeons
2013-05-01  7:39     ` Simon Jeons
2013-05-03  9:12     ` Jerome Marchand
2013-05-03  9:12       ` Jerome Marchand
2013-04-22 20:37 ` Andrew Morton
2013-04-22 20:37   ` Andrew Morton
2013-04-24  9:57   ` Jerome Marchand
2013-04-24  9:57     ` Jerome Marchand
2013-05-01  7:38     ` Will Huck
2013-05-01  7:38       ` Will Huck
2013-04-24 18:57   ` [PATCH] mm: swap: Mark swap pages writeback before queueing for direct IO Mel Gorman
2013-04-24 18:57     ` Mel Gorman
2013-04-24 19:23     ` Andrew Morton
2013-04-24 19:23       ` Andrew Morton
2013-04-25  8:53       ` Mel Gorman
2013-04-25  8:53         ` Mel Gorman
2013-05-01  6:58     ` Ric Mason [this message]
2013-05-01  6:58       ` Ric Mason
2013-05-01  8:20       ` Mel Gorman
2013-05-01  8:20         ` Mel Gorman

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=5180BCFB.6090707@gmail.com \
    --to=ric.masonn@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=jmarchan@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.