Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3291041pxk; Mon, 21 Sep 2020 09:50:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2GR488C6DPypP1TgNV67BjuYCJWSmOH72vdvpYyWV4qGZOMyfZwn2C8A/QNnPvJmudbT4 X-Received: by 2002:a17:906:fccb:: with SMTP id qx11mr309589ejb.429.1600707013815; Mon, 21 Sep 2020 09:50:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600707013; cv=none; d=google.com; s=arc-20160816; b=Dh31WchIaxrx+lhRw+sdfIHshfObHHasZ1Yw9T1BDK9fopO7dbECmwcgPfpbGYlP25 SszXxrFzlBI8zUuxB9EbCHfDe9XrpntbsbSb2rbhuf3+ktXtDj9inzBRfy3UgwxXin38 Wq7PoeTAS/K9GV33bbr2wM4eNXk0RfVu5XcOpn6Hr1hUYGqCRqm2HfQ/HY55I2IZJZ3P H6DUx/ddLpQ/eQPscmQP1mMtn3baQdS+foEOvVyOTVsZxcq9x+ZmA/Nd20UWBv1imo24 YGvMf2kb+Qr+2tCZpbcvFlhl+i58a5/m/SCtlfadYI61cMXpn/J5xQ4VhvcOYCxfJngs 5Ijw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+F79T25F5dQNfUXaR6zWc10vRPSvfvDo6jTox907XvQ=; b=0gWH5vho/xqz2CY4Z4zoXCZjwIwM7LGtqip9rQ9BKZY47yjJM94cgt207wx5Dheufx nVwKb85ZjMYxKh4PWt7cyErhHhzi5Dqzx7DBEFOHG4X92NkcRyvow0heMt4irRIthc7y mS+HGNTNxmFNSoUoiTiTZa+q1phaHZaeQfOD+tTmX+9rbhEpKZAMBaiWA62FGvdeDAnJ HGGVtivuR4Kqy5gfgO+nkkgMJeiY3Myq7nc/Ga+OFImYujkgbPvsv1vSanBkwz4WEoSq lZLXS+ehOD433nT/lSzu+1aLYLuW1F1gRbVRtN551YSmYsI4o+VbG/8mSpGf4y4mhNNM bL5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CtNTOnDo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t27si8629200edc.436.2020.09.21.09.49.50; Mon, 21 Sep 2020 09:50:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CtNTOnDo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729212AbgIUQqy (ORCPT + 99 others); Mon, 21 Sep 2020 12:46:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:53272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727231AbgIUQqs (ORCPT ); Mon, 21 Sep 2020 12:46:48 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 456192388B; Mon, 21 Sep 2020 16:46:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706808; bh=JPG2gxzH8/PmMe7MPg6i78jrQ21xF4EspNNevikwD7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CtNTOnDoC1sohP+qx+UQ9fNuLVJAWWW/DyfM0hSt5Ex7m3/6pyKeKBomtZzCExeRA CmQcB+cjXnY3bLbMpFfIAWvlgdRWw7/n8Gm5HoFGWA2PZq3zBvjXgpDGO3xbIW4gZ5 PIn6SkAQcSkO7Kg/nhRFzfNtNaNPRa/HjrjKVoJA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hugh Dickins , Andrew Morton , Shakeel Butt , Johannes Weiner , Alex Shi , Michal Hocko , Mike Kravetz , Qian Cai , Linus Torvalds Subject: [PATCH 5.8 103/118] ksm: reinstate memcg charge on copied pages Date: Mon, 21 Sep 2020 18:28:35 +0200 Message-Id: <20200921162041.161799840@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162036.324813383@linuxfoundation.org> References: <20200921162036.324813383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hugh Dickins commit 62fdb1632bcbed30c40f6bd2b58297617e442658 upstream. Patch series "mm: fixes to past from future testing". Here's a set of independent fixes against 5.9-rc2: prompted by testing Alex Shi's "warning on !memcg" and lru_lock series, but I think fit for 5.9 - though maybe only the first for stable. This patch (of 5): 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. Cc; Matthew Wilcox Fixes: 4c6355b25e8b ("mm: memcontrol: charge swapin pages on instantiation") Signed-off-by: Hugh Dickins Signed-off-by: Andrew Morton Reviewed-by: Shakeel Butt Acked-by: Johannes Weiner Cc: Alex Shi Cc: Michal Hocko Cc: Mike Kravetz Cc: Qian Cai Cc: [5.8] Link: http://lkml.kernel.org/r/alpine.LSU.2.11.2008301343270.5954@eggly.anvils Link: http://lkml.kernel.org/r/alpine.LSU.2.11.2008301358020.5954@eggly.anvils Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/ksm.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2585,6 +2585,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);