linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: annotate refault stalls from swap_readpage
@ 2019-10-10 15:21 Minchan Kim
  2019-10-10 19:17 ` Johannes Weiner
  0 siblings, 1 reply; 5+ messages in thread
From: Minchan Kim @ 2019-10-10 15:21 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, LKML, Sahkeel Butt, Minchan Kim, Johannes Weiner

From: Minchan Kim <minchan@google.com>

If block device supports rw_page operation, it doesn't submit bio
so annotation in submit_bio for refault stall doesn't work.
It happens with zram in android, especially swap read path which
could consume CPU cycle for decompress. It is also a problem for
zswap which uses frontswap.

Annotate swap_readpage() to account the synchronous IO overhead
to prevent underreport memory pressure.

Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Minchan Kim <minchan@google.com>
---
 mm/page_io.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 24ee600f9131..20147473d4a5 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -22,6 +22,7 @@
 #include <linux/writeback.h>
 #include <linux/frontswap.h>
 #include <linux/blkdev.h>
+#include <linux/psi.h>
 #include <linux/uio.h>
 #include <linux/sched/task.h>
 #include <asm/pgtable.h>
@@ -354,10 +355,14 @@ int swap_readpage(struct page *page, bool synchronous)
 	struct swap_info_struct *sis = page_swap_info(page);
 	blk_qc_t qc;
 	struct gendisk *disk;
+	unsigned long pflags;
 
 	VM_BUG_ON_PAGE(!PageSwapCache(page) && !synchronous, page);
 	VM_BUG_ON_PAGE(!PageLocked(page), page);
 	VM_BUG_ON_PAGE(PageUptodate(page), page);
+
+	psi_memstall_enter(&pflags);
+
 	if (frontswap_load(page) == 0) {
 		SetPageUptodate(page);
 		unlock_page(page);
@@ -371,7 +376,7 @@ int swap_readpage(struct page *page, bool synchronous)
 		ret = mapping->a_ops->readpage(swap_file, page);
 		if (!ret)
 			count_vm_event(PSWPIN);
-		return ret;
+		goto out;
 	}
 
 	ret = bdev_read_page(sis->bdev, swap_page_sector(page), page);
@@ -382,7 +387,7 @@ int swap_readpage(struct page *page, bool synchronous)
 		}
 
 		count_vm_event(PSWPIN);
-		return 0;
+		goto out;
 	}
 
 	ret = 0;
@@ -418,6 +423,7 @@ int swap_readpage(struct page *page, bool synchronous)
 	bio_put(bio);
 
 out:
+	psi_memstall_leave(&pflags);
 	return ret;
 }
 
-- 
2.23.0.581.g78d2f28ef7-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: annotate refault stalls from swap_readpage
  2019-10-10 15:21 [PATCH] mm: annotate refault stalls from swap_readpage Minchan Kim
@ 2019-10-10 19:17 ` Johannes Weiner
  2019-10-10 22:11   ` Minchan Kim
  2019-10-11 21:32   ` Andrew Morton
  0 siblings, 2 replies; 5+ messages in thread
From: Johannes Weiner @ 2019-10-10 19:17 UTC (permalink / raw)
  To: Minchan Kim; +Cc: Andrew Morton, linux-mm, LKML, Sahkeel Butt, Minchan Kim

On Thu, Oct 10, 2019 at 08:21:34AM -0700, Minchan Kim wrote:
> From: Minchan Kim <minchan@google.com>
> 
> If block device supports rw_page operation, it doesn't submit bio
> so annotation in submit_bio for refault stall doesn't work.
> It happens with zram in android, especially swap read path which
> could consume CPU cycle for decompress. It is also a problem for
> zswap which uses frontswap.
> 
> Annotate swap_readpage() to account the synchronous IO overhead
> to prevent underreport memory pressure.
> 
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Minchan Kim <minchan@google.com>

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

Can you please add a comment to the caller? Lifted from submit_bio():

	/*
	 * Count submission time as memory stall. When the device is
	 * congested, or the submitting cgroup IO-throttled,
	 * submission can be a significant part of overall IO time.
	 */

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: annotate refault stalls from swap_readpage
  2019-10-10 19:17 ` Johannes Weiner
@ 2019-10-10 22:11   ` Minchan Kim
  2019-10-11 17:32     ` Shakeel Butt
  2019-10-11 21:32   ` Andrew Morton
  1 sibling, 1 reply; 5+ messages in thread
From: Minchan Kim @ 2019-10-10 22:11 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: Andrew Morton, linux-mm, LKML, Sahkeel Butt

On Thu, Oct 10, 2019 at 03:17:47PM -0400, Johannes Weiner wrote:
> On Thu, Oct 10, 2019 at 08:21:34AM -0700, Minchan Kim wrote:
> > From: Minchan Kim <minchan@google.com>
> > 
> > If block device supports rw_page operation, it doesn't submit bio
> > so annotation in submit_bio for refault stall doesn't work.
> > It happens with zram in android, especially swap read path which
> > could consume CPU cycle for decompress. It is also a problem for
> > zswap which uses frontswap.
> > 
> > Annotate swap_readpage() to account the synchronous IO overhead
> > to prevent underreport memory pressure.
> > 
> > Cc: Johannes Weiner <hannes@cmpxchg.org>
> > Signed-off-by: Minchan Kim <minchan@google.com>
> 
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>

Thanks, Johannes!

> 
> Can you please add a comment to the caller? Lifted from submit_bio():

Sure, I added a little about zram.

> 
> 	/*
> 	 * Count submission time as memory stall. When the device is
> 	 * congested, or the submitting cgroup IO-throttled,
> 	 * submission can be a significant part of overall IO time.
> 	 */


From a8ae7cbc2d3f050aca810fd68285d45cb933b825 Mon Sep 17 00:00:00 2001
From: Minchan Kim <minchan@google.com>
Date: Thu, 10 Oct 2019 08:09:06 -0700
Subject: [PATCH v2] mm: annotate refault stalls from swap_readpage

If block device supports rw_page operation, it doesn't submit bio
so annotation in submit_bio for refault stall doesn't work.
It happens with zram in android, especially swap read path which
could consume CPU cycle for decompress. It is also a problem for
zswap which uses frontswap.

Annotate swap_readpage() to account the synchronous IO overhead
to prevent underreport memory pressure.

Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Minchan Kim <minchan@google.com>
---
 mm/page_io.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 24ee600f9131..18f1f8e1d27f 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -22,6 +22,7 @@
 #include <linux/writeback.h>
 #include <linux/frontswap.h>
 #include <linux/blkdev.h>
+#include <linux/psi.h>
 #include <linux/uio.h>
 #include <linux/sched/task.h>
 #include <asm/pgtable.h>
@@ -354,10 +355,20 @@ int swap_readpage(struct page *page, bool synchronous)
 	struct swap_info_struct *sis = page_swap_info(page);
 	blk_qc_t qc;
 	struct gendisk *disk;
+	unsigned long pflags;
 
 	VM_BUG_ON_PAGE(!PageSwapCache(page) && !synchronous, page);
 	VM_BUG_ON_PAGE(!PageLocked(page), page);
 	VM_BUG_ON_PAGE(PageUptodate(page), page);
+
+	/*
+	 * Count submission time as memory stall. When the device is
+	 * congested, the submitting cgroup IO-throttled, or backing
+	 * device works synchronously(e.g., zram), submission can be
+	 * a significant part of overall IO time.
+	 */
+	psi_memstall_enter(&pflags);
+
 	if (frontswap_load(page) == 0) {
 		SetPageUptodate(page);
 		unlock_page(page);
@@ -371,7 +382,7 @@ int swap_readpage(struct page *page, bool synchronous)
 		ret = mapping->a_ops->readpage(swap_file, page);
 		if (!ret)
 			count_vm_event(PSWPIN);
-		return ret;
+		goto out;
 	}
 
 	ret = bdev_read_page(sis->bdev, swap_page_sector(page), page);
@@ -382,7 +393,7 @@ int swap_readpage(struct page *page, bool synchronous)
 		}
 
 		count_vm_event(PSWPIN);
-		return 0;
+		goto out;
 	}
 
 	ret = 0;
@@ -418,6 +429,7 @@ int swap_readpage(struct page *page, bool synchronous)
 	bio_put(bio);
 
 out:
+	psi_memstall_leave(&pflags);
 	return ret;
 }
 
-- 
2.23.0.581.g78d2f28ef7-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: annotate refault stalls from swap_readpage
  2019-10-10 22:11   ` Minchan Kim
@ 2019-10-11 17:32     ` Shakeel Butt
  0 siblings, 0 replies; 5+ messages in thread
From: Shakeel Butt @ 2019-10-11 17:32 UTC (permalink / raw)
  To: Minchan Kim; +Cc: Johannes Weiner, Andrew Morton, linux-mm, LKML

On Thu, Oct 10, 2019 at 3:11 PM Minchan Kim <minchan@kernel.org> wrote:
>
> On Thu, Oct 10, 2019 at 03:17:47PM -0400, Johannes Weiner wrote:
> > On Thu, Oct 10, 2019 at 08:21:34AM -0700, Minchan Kim wrote:
> > > From: Minchan Kim <minchan@google.com>
> > >
> > > If block device supports rw_page operation, it doesn't submit bio
> > > so annotation in submit_bio for refault stall doesn't work.
> > > It happens with zram in android, especially swap read path which
> > > could consume CPU cycle for decompress. It is also a problem for
> > > zswap which uses frontswap.
> > >
> > > Annotate swap_readpage() to account the synchronous IO overhead
> > > to prevent underreport memory pressure.
> > >
> > > Cc: Johannes Weiner <hannes@cmpxchg.org>
> > > Signed-off-by: Minchan Kim <minchan@google.com>
> >
> > Acked-by: Johannes Weiner <hannes@cmpxchg.org>
>
> Thanks, Johannes!
>
> >
> > Can you please add a comment to the caller? Lifted from submit_bio():
>
> Sure, I added a little about zram.
>
> >
> >       /*
> >        * Count submission time as memory stall. When the device is
> >        * congested, or the submitting cgroup IO-throttled,
> >        * submission can be a significant part of overall IO time.
> >        */
>
>
> From a8ae7cbc2d3f050aca810fd68285d45cb933b825 Mon Sep 17 00:00:00 2001
> From: Minchan Kim <minchan@google.com>
> Date: Thu, 10 Oct 2019 08:09:06 -0700
> Subject: [PATCH v2] mm: annotate refault stalls from swap_readpage
>
> If block device supports rw_page operation, it doesn't submit bio
> so annotation in submit_bio for refault stall doesn't work.
> It happens with zram in android, especially swap read path which
> could consume CPU cycle for decompress. It is also a problem for
> zswap which uses frontswap.
>
> Annotate swap_readpage() to account the synchronous IO overhead
> to prevent underreport memory pressure.
>
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Minchan Kim <minchan@google.com>

Reviewed-by: Shakeel Butt <shakeelb@google.com>

> ---
>  mm/page_io.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/mm/page_io.c b/mm/page_io.c
> index 24ee600f9131..18f1f8e1d27f 100644
> --- a/mm/page_io.c
> +++ b/mm/page_io.c
> @@ -22,6 +22,7 @@
>  #include <linux/writeback.h>
>  #include <linux/frontswap.h>
>  #include <linux/blkdev.h>
> +#include <linux/psi.h>
>  #include <linux/uio.h>
>  #include <linux/sched/task.h>
>  #include <asm/pgtable.h>
> @@ -354,10 +355,20 @@ int swap_readpage(struct page *page, bool synchronous)
>         struct swap_info_struct *sis = page_swap_info(page);
>         blk_qc_t qc;
>         struct gendisk *disk;
> +       unsigned long pflags;
>
>         VM_BUG_ON_PAGE(!PageSwapCache(page) && !synchronous, page);
>         VM_BUG_ON_PAGE(!PageLocked(page), page);
>         VM_BUG_ON_PAGE(PageUptodate(page), page);
> +
> +       /*
> +        * Count submission time as memory stall. When the device is
> +        * congested, the submitting cgroup IO-throttled, or backing
> +        * device works synchronously(e.g., zram), submission can be
> +        * a significant part of overall IO time.
> +        */
> +       psi_memstall_enter(&pflags);
> +
>         if (frontswap_load(page) == 0) {
>                 SetPageUptodate(page);
>                 unlock_page(page);
> @@ -371,7 +382,7 @@ int swap_readpage(struct page *page, bool synchronous)
>                 ret = mapping->a_ops->readpage(swap_file, page);
>                 if (!ret)
>                         count_vm_event(PSWPIN);
> -               return ret;
> +               goto out;
>         }
>
>         ret = bdev_read_page(sis->bdev, swap_page_sector(page), page);
> @@ -382,7 +393,7 @@ int swap_readpage(struct page *page, bool synchronous)
>                 }
>
>                 count_vm_event(PSWPIN);
> -               return 0;
> +               goto out;
>         }
>
>         ret = 0;
> @@ -418,6 +429,7 @@ int swap_readpage(struct page *page, bool synchronous)
>         bio_put(bio);
>
>  out:
> +       psi_memstall_leave(&pflags);
>         return ret;
>  }
>
> --
> 2.23.0.581.g78d2f28ef7-goog
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: annotate refault stalls from swap_readpage
  2019-10-10 19:17 ` Johannes Weiner
  2019-10-10 22:11   ` Minchan Kim
@ 2019-10-11 21:32   ` Andrew Morton
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2019-10-11 21:32 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: Minchan Kim, linux-mm, LKML, Sahkeel Butt, Minchan Kim

On Thu, 10 Oct 2019 15:17:47 -0400 Johannes Weiner <hannes@cmpxchg.org> wrote:

> On Thu, Oct 10, 2019 at 08:21:34AM -0700, Minchan Kim wrote:
> > From: Minchan Kim <minchan@google.com>
> > 
> > If block device supports rw_page operation, it doesn't submit bio
> > so annotation in submit_bio for refault stall doesn't work.
> > It happens with zram in android, especially swap read path which
> > could consume CPU cycle for decompress. It is also a problem for
> > zswap which uses frontswap.
> > 
> > Annotate swap_readpage() to account the synchronous IO overhead
> > to prevent underreport memory pressure.
> > 
> > Cc: Johannes Weiner <hannes@cmpxchg.org>
> > Signed-off-by: Minchan Kim <minchan@google.com>
> 
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> 
> Can you please add a comment to the caller? Lifted from submit_bio():
> 
> 	/*
> 	 * Count submission time as memory stall. When the device is
> 	 * congested, or the submitting cgroup IO-throttled,
> 	 * submission can be a significant part of overall IO time.
> 	 */

This?

--- a/mm/page_io.c~mm-annotate-refault-stalls-from-swap_readpage-fix
+++ a/mm/page_io.c
@@ -361,6 +361,11 @@ int swap_readpage(struct page *page, boo
 	VM_BUG_ON_PAGE(!PageLocked(page), page);
 	VM_BUG_ON_PAGE(PageUptodate(page), page);
 
+	/*
+	 * Count submission time as memory stall. When the device is congested,
+	 * or the submitting cgroup IO-throttled, submission can be a
+	 * significant part of overall IO time.
+	 */
 	psi_memstall_enter(&pflags);
 
 	if (frontswap_load(page) == 0) {
_


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-11 21:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-10 15:21 [PATCH] mm: annotate refault stalls from swap_readpage Minchan Kim
2019-10-10 19:17 ` Johannes Weiner
2019-10-10 22:11   ` Minchan Kim
2019-10-11 17:32     ` Shakeel Butt
2019-10-11 21:32   ` Andrew Morton

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).