All of lore.kernel.org
 help / color / mirror / Atom feed
* + filemap-make-the-accounting-of-thrashing-more-consistent.patch added to mm-unstable branch
@ 2022-08-11 21:52 Andrew Morton
  2022-08-12  2:20 ` Joonsoo Kim
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2022-08-11 21:52 UTC (permalink / raw)
  To: mm-commits, willy, iamjoonsoo.kim, david, corbet, cgel.zte,
	bsingharora, yang.yang29, akpm


The patch titled
     Subject: filemap: make the accounting of thrashing more consistent
has been added to the -mm mm-unstable branch.  Its filename is
     filemap-make-the-accounting-of-thrashing-more-consistent.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/filemap-make-the-accounting-of-thrashing-more-consistent.patch

This patch will later appear in the mm-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days

------------------------------------------------------
From: Yang Yang <yang.yang29@zte.com.cn>
Subject: filemap: make the accounting of thrashing more consistent
Date: Fri, 5 Aug 2022 03:38:39 +0000

Once upon a time, we only support accounting thrashing of page cache. 
Then Joonsoo introduced workingset detection for anonymous pages and we
gained the ability to account thrashing of them[1].

So let delayacct account both the thrashing of page cache and anonymous
pages, this could make the codes more consistent and simpler.

[1] commit aae466b0052e ("mm/swap: implement workingset detection for anonymous LRU")

Link: https://lkml.kernel.org/r/20220805033838.1714674-1-yang.yang29@zte.com.cn
Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
Signed-off-by: CGEL ZTE <cgel.zte@gmail.com>
Cc: Balbir Singh <bsingharora@gmail.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Yang Yang <yang.yang29@zte.com.cn>
Cc: David Hildenbrand <david@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 Documentation/accounting/delay-accounting.rst |    2 -
 mm/filemap.c                                  |   18 +++-------------
 2 files changed, 5 insertions(+), 15 deletions(-)

--- a/Documentation/accounting/delay-accounting.rst~filemap-make-the-accounting-of-thrashing-more-consistent
+++ a/Documentation/accounting/delay-accounting.rst
@@ -13,7 +13,7 @@ a) waiting for a CPU (while being runnab
 b) completion of synchronous block I/O initiated by the task
 c) swapping in pages
 d) memory reclaim
-e) thrashing page cache
+e) thrashing
 f) direct compact
 g) write-protect copy
 
--- a/mm/filemap.c~filemap-make-the-accounting-of-thrashing-more-consistent
+++ a/mm/filemap.c
@@ -1221,15 +1221,11 @@ static inline int folio_wait_bit_common(
 	struct wait_page_queue wait_page;
 	wait_queue_entry_t *wait = &wait_page.wait;
 	bool thrashing = false;
-	bool delayacct = false;
 	unsigned long pflags;
 
 	if (bit_nr == PG_locked &&
 	    !folio_test_uptodate(folio) && folio_test_workingset(folio)) {
-		if (!folio_test_swapbacked(folio)) {
-			delayacct_thrashing_start();
-			delayacct = true;
-		}
+		delayacct_thrashing_start();
 		psi_memstall_enter(&pflags);
 		thrashing = true;
 	}
@@ -1329,8 +1325,7 @@ repeat:
 	finish_wait(q, wait);
 
 	if (thrashing) {
-		if (delayacct)
-			delayacct_thrashing_end();
+		delayacct_thrashing_end();
 		psi_memstall_leave(&pflags);
 	}
 
@@ -1378,17 +1373,13 @@ void migration_entry_wait_on_locked(swp_
 	struct wait_page_queue wait_page;
 	wait_queue_entry_t *wait = &wait_page.wait;
 	bool thrashing = false;
-	bool delayacct = false;
 	unsigned long pflags;
 	wait_queue_head_t *q;
 	struct folio *folio = page_folio(pfn_swap_entry_to_page(entry));
 
 	q = folio_waitqueue(folio);
 	if (!folio_test_uptodate(folio) && folio_test_workingset(folio)) {
-		if (!folio_test_swapbacked(folio)) {
-			delayacct_thrashing_start();
-			delayacct = true;
-		}
+		delayacct_thrashing_start();
 		psi_memstall_enter(&pflags);
 		thrashing = true;
 	}
@@ -1435,8 +1426,7 @@ void migration_entry_wait_on_locked(swp_
 	finish_wait(q, wait);
 
 	if (thrashing) {
-		if (delayacct)
-			delayacct_thrashing_end();
+		delayacct_thrashing_end();
 		psi_memstall_leave(&pflags);
 	}
 }
_

Patches currently in -mm which might be from yang.yang29@zte.com.cn are

mm-vmscan-define-macros-for-refaults-in-struct-lruvec.patch
filemap-make-the-accounting-of-thrashing-more-consistent.patch


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

* Re: + filemap-make-the-accounting-of-thrashing-more-consistent.patch added to mm-unstable branch
  2022-08-11 21:52 + filemap-make-the-accounting-of-thrashing-more-consistent.patch added to mm-unstable branch Andrew Morton
@ 2022-08-12  2:20 ` Joonsoo Kim
  2022-08-12  3:48   ` CGEL
  0 siblings, 1 reply; 5+ messages in thread
From: Joonsoo Kim @ 2022-08-12  2:20 UTC (permalink / raw)
  To: LKML
  Cc: mm-commits, Matthew Wilcox, Joonsoo Kim, David Hildenbrand,
	corbet, cgel.zte, bsingharora, yang.yang29, Andrew Morton

Hello, Yang.

2022년 8월 12일 (금) 오전 7:10, Andrew Morton <akpm@linux-foundation.org>님이 작성:
>
>
> The patch titled
>      Subject: filemap: make the accounting of thrashing more consistent
> has been added to the -mm mm-unstable branch.  Its filename is
>      filemap-make-the-accounting-of-thrashing-more-consistent.patch
>
> This patch will shortly appear at
>      https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/filemap-make-the-accounting-of-thrashing-more-consistent.patch
>
> This patch will later appear in the mm-unstable branch at
>     git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
>
> Before you just go and hit "reply", please:
>    a) Consider who else should be cc'ed
>    b) Prefer to cc a suitable mailing list as well
>    c) Ideally: find the original patch on the mailing list and do a
>       reply-to-all to that, adding suitable additional cc's
>
> *** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
>
> The -mm tree is included into linux-next via the mm-everything
> branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> and is updated there every 2-3 working days
>
> ------------------------------------------------------
> From: Yang Yang <yang.yang29@zte.com.cn>
> Subject: filemap: make the accounting of thrashing more consistent
> Date: Fri, 5 Aug 2022 03:38:39 +0000
>
> Once upon a time, we only support accounting thrashing of page cache.
> Then Joonsoo introduced workingset detection for anonymous pages and we
> gained the ability to account thrashing of them[1].
>
> So let delayacct account both the thrashing of page cache and anonymous
> pages, this could make the codes more consistent and simpler.
>
> [1] commit aae466b0052e ("mm/swap: implement workingset detection for anonymous LRU")
>
> Link: https://lkml.kernel.org/r/20220805033838.1714674-1-yang.yang29@zte.com.cn
> Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
> Signed-off-by: CGEL ZTE <cgel.zte@gmail.com>
> Cc: Balbir Singh <bsingharora@gmail.com>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: Yang Yang <yang.yang29@zte.com.cn>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
>
>  Documentation/accounting/delay-accounting.rst |    2 -
>  mm/filemap.c                                  |   18 +++-------------
>  2 files changed, 5 insertions(+), 15 deletions(-)
>
> --- a/Documentation/accounting/delay-accounting.rst~filemap-make-the-accounting-of-thrashing-more-consistent
> +++ a/Documentation/accounting/delay-accounting.rst
> @@ -13,7 +13,7 @@ a) waiting for a CPU (while being runnab
>  b) completion of synchronous block I/O initiated by the task
>  c) swapping in pages
>  d) memory reclaim
> -e) thrashing page cache
> +e) thrashing
>  f) direct compact
>  g) write-protect copy
>
> --- a/mm/filemap.c~filemap-make-the-accounting-of-thrashing-more-consistent
> +++ a/mm/filemap.c
> @@ -1221,15 +1221,11 @@ static inline int folio_wait_bit_common(
>         struct wait_page_queue wait_page;
>         wait_queue_entry_t *wait = &wait_page.wait;
>         bool thrashing = false;
> -       bool delayacct = false;
>         unsigned long pflags;
>
>         if (bit_nr == PG_locked &&
>             !folio_test_uptodate(folio) && folio_test_workingset(folio)) {
> -               if (!folio_test_swapbacked(folio)) {
> -                       delayacct_thrashing_start();
> -                       delayacct = true;
> -               }
> +               delayacct_thrashing_start();
>                 psi_memstall_enter(&pflags);
>                 thrashing = true;
>         }

I think that a better place to measure swap thrashing is swap_readpage().
For some cases, like a zram, swap_readpage() is called directly rather than
loading the page onto the swap cache. Your code would miss that case.

Thanks.

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

* Re: + filemap-make-the-accounting-of-thrashing-more-consistent.patch added to mm-unstable branch
  2022-08-12  2:20 ` Joonsoo Kim
@ 2022-08-12  3:48   ` CGEL
  2022-08-12  6:45     ` Joonsoo Kim
  0 siblings, 1 reply; 5+ messages in thread
From: CGEL @ 2022-08-12  3:48 UTC (permalink / raw)
  To: Joonsoo Kim
  Cc: LKML, mm-commits, Matthew Wilcox, Joonsoo Kim, David Hildenbrand,
	corbet, bsingharora, yang.yang29, Andrew Morton

We have discussed related question before. See:
https://lore.kernel.org/all/Yio17pXawRuuVJFO@cmpxchg.org/
The problem is that there is no suitable place to measure pagecache thrashing
in fs level likes swap_readpage(). We have to measure it in folio_wait_bit_common().

If we measure swap thrashing just in swap_readpage(), we will miss pagecache
thrashing. If we measure swap thrashing in swap_readpage(), and measure 
pagecache thrashing in folio_wait_bit_common(), it will be rerpeated calculation.

So this patch is not perfect and it works. If one day we solve the problem of
measure thrashing in folio_wait_bit_common(), we may improve this patch correspond.

Thanks.

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

* Re: + filemap-make-the-accounting-of-thrashing-more-consistent.patch added to mm-unstable branch
  2022-08-12  3:48   ` CGEL
@ 2022-08-12  6:45     ` Joonsoo Kim
  2022-08-12  7:24       ` CGEL
  0 siblings, 1 reply; 5+ messages in thread
From: Joonsoo Kim @ 2022-08-12  6:45 UTC (permalink / raw)
  To: CGEL
  Cc: LKML, mm-commits, Matthew Wilcox, Joonsoo Kim, David Hildenbrand,
	corbet, bsingharora, yang.yang29, Andrew Morton

2022년 8월 12일 (금) 오후 12:48, CGEL <cgel.zte@gmail.com>님이 작성:
>
> We have discussed related question before. See:
> https://lore.kernel.org/all/Yio17pXawRuuVJFO@cmpxchg.org/
> The problem is that there is no suitable place to measure pagecache thrashing
> in fs level likes swap_readpage(). We have to measure it in folio_wait_bit_common().
>
> If we measure swap thrashing just in swap_readpage(), we will miss pagecache
> thrashing. If we measure swap thrashing in swap_readpage(), and measure
> pagecache thrashing in folio_wait_bit_common(), it will be rerpeated calculation.

Maybe, repeated calculation issue could be easily solved by
re-entrance detection on
delayacct_thrashing_start().

Thanks.

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

* Re: + filemap-make-the-accounting-of-thrashing-more-consistent.patch added to mm-unstable branch
  2022-08-12  6:45     ` Joonsoo Kim
@ 2022-08-12  7:24       ` CGEL
  0 siblings, 0 replies; 5+ messages in thread
From: CGEL @ 2022-08-12  7:24 UTC (permalink / raw)
  To: Joonsoo Kim
  Cc: LKML, mm-commits, Matthew Wilcox, Joonsoo Kim, David Hildenbrand,
	corbet, bsingharora, yang.yang29, Andrew Morton

On Fri, Aug 12, 2022 at 03:45:09PM +0900, Joonsoo Kim wrote:
> 2022년 8월 12일 (금) 오후 12:48, CGEL <cgel.zte@gmail.com>님이 작성:
> >
> > We have discussed related question before. See:
> > https://lore.kernel.org/all/Yio17pXawRuuVJFO@cmpxchg.org/
> > The problem is that there is no suitable place to measure pagecache thrashing
> > in fs level likes swap_readpage(). We have to measure it in folio_wait_bit_common().
> >
> > If we measure swap thrashing just in swap_readpage(), we will miss pagecache
> > thrashing. If we measure swap thrashing in swap_readpage(), and measure
> > pagecache thrashing in folio_wait_bit_common(), it will be rerpeated calculation.
> 
> Maybe, repeated calculation issue could be easily solved by
> re-entrance detection on
> delayacct_thrashing_start().
>
If no other suggestion from others, I will commit another patch
to realize this.

And I think this patch will not conflict with the later patch.

Thanks.

> Thanks.

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

end of thread, other threads:[~2022-08-12  7:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-11 21:52 + filemap-make-the-accounting-of-thrashing-more-consistent.patch added to mm-unstable branch Andrew Morton
2022-08-12  2:20 ` Joonsoo Kim
2022-08-12  3:48   ` CGEL
2022-08-12  6:45     ` Joonsoo Kim
2022-08-12  7:24       ` CGEL

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.