2020-03-23 05:53:53

by Joonsoo Kim

[permalink] [raw]
Subject: [PATCH v4 5/8] mm/workingset: handle the page without memcg

From: Joonsoo Kim <[email protected]>

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 <[email protected]>
---
mm/workingset.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

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);
--
2.7.4


2020-03-23 16:51:50

by Johannes Weiner

[permalink] [raw]
Subject: Re: [PATCH v4 5/8] mm/workingset: handle the page without memcg

On Mon, Mar 23, 2020 at 02:52:09PM +0900, [email protected] wrote:
> From: Joonsoo Kim <[email protected]>
>
> 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 <[email protected]>

Acked-by: Johannes Weiner <[email protected]>