diff mbox series

[v4,5/8] mm/workingset: handle the page without memcg

Message ID 1584942732-2184-6-git-send-email-iamjoonsoo.kim@lge.com (mailing list archive)
State New, archived
Headers show
Series workingset protection/detection on the anonymous LRU list | expand

Commit Message

Joonsoo Kim March 23, 2020, 5:52 a.m. UTC
From: Joonsoo Kim <iamjoonsoo.kim@lge.com>

When implementing workingset detection for anonymous page, I found
some swapcache pages with NULL memcg. They are brought in by swap
readahead and nobody has touched it.

The idea behind the workingset code is to tell on page fault time
whether pages have been previously used or not. Since this page
hasn't been used, don't store a shadow entry for it; when it later
faults back in, we treat it as the new page that it is.

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
 mm/workingset.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Johannes Weiner March 23, 2020, 4:51 p.m. UTC | #1
On Mon, Mar 23, 2020 at 02:52:09PM +0900, js1304@gmail.com wrote:
> From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> 
> When implementing workingset detection for anonymous page, I found
> some swapcache pages with NULL memcg. They are brought in by swap
> readahead and nobody has touched it.
> 
> The idea behind the workingset code is to tell on page fault time
> whether pages have been previously used or not. Since this page
> hasn't been used, don't store a shadow entry for it; when it later
> faults back in, we treat it as the new page that it is.
> 
> Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>

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

Patch

diff --git a/mm/workingset.c b/mm/workingset.c
index 59415e0..8b192e8 100644
--- a/mm/workingset.c
+++ b/mm/workingset.c
@@ -257,6 +257,19 @@  void *workingset_eviction(struct page *page, struct mem_cgroup *target_memcg)
 	VM_BUG_ON_PAGE(page_count(page), page);
 	VM_BUG_ON_PAGE(!PageLocked(page), page);
 
+	/*
+	 * A page can be without a cgroup here when it was brought in by
+	 * swap readahead and nobody has touched it since.
+	 *
+	 * The idea behind the workingset code is to tell on page fault
+	 * time whether pages have been previously used or not. Since
+	 * this page hasn't been used, don't store a shadow entry for it;
+	 * when it later faults back in, we treat it as the new page
+	 * that it is.
+	 */
+	if (!page_memcg(page))
+		return NULL;
+
 	advance_inactive_age(page_memcg(page), pgdat, file);
 
 	lruvec = mem_cgroup_lruvec(target_memcg, pgdat);