From patchwork Sun Aug 30 20:59:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 11745329 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E171113B1 for ; Sun, 30 Aug 2020 20:59:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A20A3206FA for ; Sun, 30 Aug 2020 20:59:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oRJZiql1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A20A3206FA Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DD24D6B0002; Sun, 30 Aug 2020 16:59:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D84AE6B0003; Sun, 30 Aug 2020 16:59:39 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C724B6B0005; Sun, 30 Aug 2020 16:59:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id AFAAC6B0002 for ; Sun, 30 Aug 2020 16:59:39 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 77905180AD811 for ; Sun, 30 Aug 2020 20:59:39 +0000 (UTC) X-FDA: 77208451278.15.skate61_0e000ed2708a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 4BE491814B0C1 for ; Sun, 30 Aug 2020 20:59:39 +0000 (UTC) X-Spam-Summary: 1,0,0,5c9482af6f33dc2a,d41d8cd98f00b204,hughd@google.com,,RULES_HIT:41:355:379:800:960:968:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:5007:6119:6261:6653:7875:7903:8957:10004:10400:11026:11473:11658:11914:12043:12297:12438:12517:12519:12555:12679:12740:12895:12986:13069:13311:13357:13439:14096:14097:14181:14394:14659:14721:21060:21080:21324:21433:21444:21451:21627:21740:21990:30003:30012:30041:30054:30070,0,RBL:209.85.167.194:@google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y851cknzdki1e9s4tm1izapbxcfocar3xr38jjs6jces8kf46js6can44c64j.3s7zhydxcxxdm79mc7deepqm7w5t9pa9xdi49x3yhxsjsewssnze97zin7g77w5.c-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: skate61_0e000ed2708a X-Filterd-Recvd-Size: 4997 Received: from mail-oi1-f194.google.com (mail-oi1-f194.google.com [209.85.167.194]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Sun, 30 Aug 2020 20:59:38 +0000 (UTC) Received: by mail-oi1-f194.google.com with SMTP id z195so5470651oia.6 for ; Sun, 30 Aug 2020 13:59:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=QBRmCzycKmVnu23sFsGovUalfChtQnjWcQWYwI41Axs=; b=oRJZiql1EBss2KvDcVmuLG7L3aCyu2+FBgk3j1giZZqACibEjKQb6SkstVBGYZU4QK bRrTWKp2d3YEVyAooD3KGlCqvmb6iSkk4Me6fnFWAAquDC1qrySjhUCG2z/DiQ3qN7qh mWKoNV40sLxpuJbCb8yMKMfwcLwJtPPdadVpvHiX/sUfeVrFocScInFqHGt2zKRCHjLD hXWib8afQ6yXkkv7yDORDIYjd42qidf6OqaPSyyRGcQIAXEIQPbSC17BKRwiURY+uoLm TiKpyPEFCFrS7VE1GQ1LnEdUuPjBlcxhYR5ZNIaPhWTWW8O252C6J+xMDzYWhX7KV7el PU9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=QBRmCzycKmVnu23sFsGovUalfChtQnjWcQWYwI41Axs=; b=l2PjJyke6x6XV0PVs+B4VNThmOvLGoTjklv5ioSa+5DMVjerdAGhkW+2J+gSO/jzwD D0R7+8plmY7xSRzpRg+qNpk/5EpNSVpT452gTsZaxHH12EeugwbhxcrhrDb2ruA2Baom X9K42jJmmwG5Sn37JZ91HVapO2I6vQDCV7hogGQBvU/CceFLGp0guFrkfhxw/fAR0FB2 eY6OssmEHtFfneJGoV/xzkvg/SnU84Tc8UhtiDOvfGYpY/kTYETDUPv56XKuKDjRtTv+ EcQyY43cw7JUdW11B4JRRAx8T30qo0rKHVVZI3zRFYbZfugTppuWL0T5IvRaCjOWJY7x WmfQ== X-Gm-Message-State: AOAM530F3qQ5OGNNCFm/ZLu6rWJm3yAvirYbp49sfuwfC95BwefsjrTf QTTHvGbzmL2SAAxGhw2uF7F4iw== X-Google-Smtp-Source: ABdhPJxxjozAFzN+mLHtGpaXsRTl7d/7QcyQjmZRGz/hgM/tIVGeTiFgtm4/XScrqZiVh2LIn3H+bg== X-Received: by 2002:aca:1904:: with SMTP id l4mr1911081oii.67.1598821178001; Sun, 30 Aug 2020 13:59:38 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id w136sm1256385oif.14.2020.08.30.13.59.36 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Sun, 30 Aug 2020 13:59:36 -0700 (PDT) Date: Sun, 30 Aug 2020 13:59:35 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: Alex Shi , Johannes Weiner , Michal Hocko , Mike Kravetz , Shakeel Butt , Matthew Wilcox , Qian Cai , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/5] ksm: reinstate memcg charge on copied pages In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 X-Rspamd-Queue-Id: 4BE491814B0C1 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Cc: stable@vger.kernel.org # v5.8 Reviewed-by: Shakeel Butt Acked-by: Johannes Weiner --- 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);