linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: <yang.yang29@zte.com.cn>
To: <akpm@linux-foundation.org>, <hannes@cmpxchg.org>
Cc: <linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
	<iamjoonsoo.kim@lge.com>, <yang.yang29@zte.com.cn>,
	<willy@infradead.org>
Subject:  [PATCH linux-next] mm: workingset: simplify the calculation of workingset size
Date: Thu, 16 Mar 2023 17:23:05 +0800 (CST)	[thread overview]
Message-ID: <202303161723055514455@zte.com.cn> (raw)

From: Yang Yang <yang.yang29@zte.com.cn>

After we implemented workingset detection for anonymous LRU[1],
the calculation of workingset size is a little complex. Actually there is
no need to call mem_cgroup_get_nr_swap_pages() if refault page is
anonymous page, since we are doing swapping then should always
give pressure to NR_ACTIVE_ANON.
So avoid using mem_cgroup_get_nr_swap_pages() when handling
swapin in workingset_refault(). This also give us a chance to refactor
the code to make it simpler and more understandable.

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

Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
Reviewed-by: Wang Yong <wang.yong12@zte.com.cn>
Reviewed-by: Xiaokai Ran <ran.xiaokai@zte.com.cn>
---
 mm/workingset.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/mm/workingset.c b/mm/workingset.c
index 00c6f4d9d9be..a304e8571d54 100644
--- a/mm/workingset.c
+++ b/mm/workingset.c
@@ -466,22 +466,23 @@ void workingset_refault(struct folio *folio, void *shadow)
 	/*
 	 * Compare the distance to the existing workingset size. We
 	 * don't activate pages that couldn't stay resident even if
-	 * all the memory was available to the workingset. Whether
-	 * workingset competition needs to consider anon or not depends
-	 * on having swap.
+	 * all the memory was available to the workingset. For page
+	 * cache whether workingset competition needs to consider
+	 * anon or not depends on having swap.
 	 */
 	workingset_size = lruvec_page_state(eviction_lruvec, NR_ACTIVE_FILE);
+	/* For anonymous page */
 	if (!file) {
+		workingset_size += lruvec_page_state(eviction_lruvec,
+						     NR_ACTIVE_ANON);
 		workingset_size += lruvec_page_state(eviction_lruvec,
 						     NR_INACTIVE_FILE);
-	}
-	if (mem_cgroup_get_nr_swap_pages(eviction_memcg) > 0) {
+	/* For page cache */
+	} else if (mem_cgroup_get_nr_swap_pages(eviction_memcg) > 0) {
 		workingset_size += lruvec_page_state(eviction_lruvec,
 						     NR_ACTIVE_ANON);
-		if (file) {
-			workingset_size += lruvec_page_state(eviction_lruvec,
+		workingset_size += lruvec_page_state(eviction_lruvec,
 						     NR_INACTIVE_ANON);
-		}
 	}
 	if (refault_distance > workingset_size)
 		goto out;
-- 
2.25.1


             reply	other threads:[~2023-03-16  9:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-16  9:23 yang.yang29 [this message]
2023-03-16 13:14 ` Matthew Wilcox
2023-03-16 14:30 ` Johannes Weiner
     [not found]   ` <20230317015903.16978-1-yang.yang29@zte.com.cn>
2023-03-17 14:09     ` Johannes Weiner

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=202303161723055514455@zte.com.cn \
    --to=yang.yang29@zte.com.cn \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.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