linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Alex Shi <alex.shi@linux.alibaba.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@suse.com>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	Shakeel Butt <shakeelb@google.com>,
	Matthew Wilcox <willy@infradead.org>, Qian Cai <cai@lca.pw>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH 1/5] ksm: reinstate memcg charge on copied pages
Date: Sun, 30 Aug 2020 13:59:35 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LSU.2.11.2008301358020.5954@eggly.anvils> (raw)
In-Reply-To: <alpine.LSU.2.11.2008301343270.5954@eggly.anvils>

In 5.8 some instances of memcg charging in do_swap_page() and unuse_pte()
were removed, on the understanding that swap cache is now already charged
at those points; but a case was missed, when ksm_might_need_to_copy() has
decided it must allocate a substitute page: such pages were never charged.
Fix it inside ksm_might_need_to_copy().

This was discovered by Alex Shi's prospective commit "mm/memcg: warning
on !memcg after readahead page charged".

But there is a another surprise: this also fixes some rarer uncharged
PageAnon cases, when KSM is configured in, but has never been activated.
ksm_might_need_to_copy()'s anon_vma->root and linear_page_index() check
sometimes catches a case which would need to have been copied if KSM
were turned on.  Or that's my optimistic interpretation (of my own old
code), but it leaves some doubt as to whether everything is working as
intended there - might it hint at rare anon ptes which rmap cannot find?
A question not easily answered: put in the fix for missed memcg charges.

Fixes: 4c6355b25e8b ("mm: memcontrol: charge swapin pages on instantiation")
Signed-off-by: Hugh Dickins <hughd@google.com>
Cc: stable@vger.kernel.org # v5.8
---

 mm/ksm.c |    4 ++++
 1 file changed, 4 insertions(+)

--- 5.9-rc2/mm/ksm.c	2020-08-16 17:32:50.645506940 -0700
+++ linux/mm/ksm.c	2020-08-28 17:42:07.967278385 -0700
@@ -2582,6 +2582,10 @@ struct page *ksm_might_need_to_copy(stru
 		return page;		/* let do_swap_page report the error */
 
 	new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address);
+	if (new_page && mem_cgroup_charge(new_page, vma->vm_mm, GFP_KERNEL)) {
+		put_page(new_page);
+		new_page = NULL;
+	}
 	if (new_page) {
 		copy_user_highpage(new_page, page, address, vma);
 

  reply	other threads:[~2020-08-30 21:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-30 20:57 [PATCH 0/5] mm: fixes to past from future testing Hugh Dickins
2020-08-30 20:59 ` Hugh Dickins [this message]
2020-08-31 14:40   ` [PATCH 1/5] ksm: reinstate memcg charge on copied pages Shakeel Butt
2020-09-01 15:01   ` Johannes Weiner
2020-08-30 21:01 ` [PATCH 2/5] mm: migration of hugetlbfs page skip memcg Hugh Dickins
2020-08-31 14:40   ` Shakeel Butt
2020-09-01 15:02   ` Johannes Weiner
2020-08-30 21:08 ` [PATCH 4/5] mm: fix check_move_unevictable_pages() on THP Hugh Dickins
2020-08-31 14:44   ` Shakeel Butt
2020-09-01  2:04   ` Alex Shi
2020-09-01  3:59     ` Hugh Dickins
2020-09-01 15:57   ` Yang Shi
2020-08-30 21:09 ` [PATCH 5/5] mlock: fix unevictable_pgs event counts " Hugh Dickins
2020-08-31 14:45   ` Shakeel Butt
2020-09-01 15:41   ` Yang Shi
2020-09-01  2:28 ` [PATCH 0/5] mm: fixes to past from future testing Alex Shi
2020-09-01  4:08   ` Hugh Dickins

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=alpine.LSU.2.11.2008301358020.5954@eggly.anvils \
    --to=hughd@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.shi@linux.alibaba.com \
    --cc=cai@lca.pw \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=mike.kravetz@oracle.com \
    --cc=shakeelb@google.com \
    --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;
as well as URLs for NNTP newsgroup(s).