Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1255639pxa; Thu, 20 Aug 2020 06:54:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCn4RpCzReGe1HAWW89Bf9RFk+BBQhCaPcVt3k74ZcaVqD4OX9Wz9RKz9n7PnERIZdz6se X-Received: by 2002:aa7:d145:: with SMTP id r5mr2868779edo.323.1597931643847; Thu, 20 Aug 2020 06:54:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597931643; cv=none; d=google.com; s=arc-20160816; b=SqHnj9z6Cana11rqp9i659o+S7EbWQx3Ao2mlZk8Wz5sO0zpZ2Ma9FIARHWs8WrI7n oPfz56PdkFXpaTc8cU+e+AVf+02Yr1n1NvAkDzDwl6hBDk+6iGFTlsiAFTO3qOy48epG 1TbovxhcAuX0cVusxFO8w1MTeNjO/zklTwh6ajz53BFBlRAYpWILRnfDsqFAnYPP+2hO M4HaLqF2qt5LJurGPkPDLSYoZuY6jd+Q3dGOEZVgPOZlo1x/Pqw4pLxdkzPEwzSacnRJ Oe94ql/ITSr62w0VYI7VHvVHaFELfOGYUhhoRu88GRfQvWip4F9VTmZ1rD1tumuB3mPR BBBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=j9gsnxSAwlN0LOXX0rsACw9CepbwXBwxjgdf6LSVvIk=; b=xf1+njK+B/CNmQpL+iaWdG3n/d734OeccSLrw0kWrG7OZeVKdG9mueqGNfYXMirrnb mD/n7UMaTDGNCkGwp4VO/jQlYyETb5yl5Lq7vU0ukyWHdnqR8SSim7KS+Z94bKAqYt+D zKKB4ARWfm+TTuxWVUVjksuBrlsdHTKNn+9ivUBwkfGoyu0wfdfZVeTPCh0rj0v3hb4X b5ZETc4NpkeG4/EJ04AfK7e4/du43v74T45+IONEUU/aT/CGGCJQH+VDpqCbQgd0uVo5 +fJelA2Kqts41acU/KJYwRN6tTb8t3vuyhipdfE+0FNmYqLX0NXqwr5OTpIK4PPPVeq4 sW7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zFhdPhAo; 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 f16si1433651edv.411.2020.08.20.06.53.40; Thu, 20 Aug 2020 06:54:03 -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=zFhdPhAo; 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 S1728679AbgHTNuC (ORCPT + 99 others); Thu, 20 Aug 2020 09:50:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:36966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727977AbgHTJ1Z (ORCPT ); Thu, 20 Aug 2020 05:27:25 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 F14BE22B4B; Thu, 20 Aug 2020 09:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915644; bh=EqcsjBxJ0kSJGRNSqRm07UoiqBAOeV5Df6CJ64YjXug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zFhdPhAo5r/hNJLAIIp859lVEhZKOdOJK6aaclwkK827PhjRpOov6OTgwNhJkgsEN JLabNVJxD5rC7jny6atP507y1bbiEeArKOCuq0ryylvkXwEVpOWgIWxLer91DTL3I2 LbFrk3IBeM+V9AmltToce07Gxu2dqpP9y6Am0jUo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Michal=20Koutn=C3=BD?= , Michal Hocko , Andrew Morton , Roman Gushchin , Johannes Weiner , Tejun Heo , Linus Torvalds Subject: [PATCH 5.8 085/232] mm/page_counter.c: fix protection usage propagation Date: Thu, 20 Aug 2020 11:18:56 +0200 Message-Id: <20200820091616.934865239@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michal Koutný commit a6f23d14ec7d7d02220ad8bb2774be3322b9aeec upstream. When workload runs in cgroups that aren't directly below root cgroup and their parent specifies reclaim protection, it may end up ineffective. The reason is that propagate_protected_usage() is not called in all hierarchy up. All the protected usage is incorrectly accumulated in the workload's parent. This means that siblings_low_usage is overestimated and effective protection underestimated. Even though it is transitional phenomenon (uncharge path does correct propagation and fixes the wrong children_low_usage), it can undermine the intended protection unexpectedly. We have noticed this problem while seeing a swap out in a descendant of a protected memcg (intermediate node) while the parent was conveniently under its protection limit and the memory pressure was external to that hierarchy. Michal has pinpointed this down to the wrong siblings_low_usage which led to the unwanted reclaim. The fix is simply updating children_low_usage in respective ancestors also in the charging path. Fixes: 230671533d64 ("mm: memory.low hierarchical behavior") Signed-off-by: Michal Koutný Signed-off-by: Michal Hocko Signed-off-by: Andrew Morton Acked-by: Michal Hocko Acked-by: Roman Gushchin Cc: Johannes Weiner Cc: Tejun Heo Cc: [4.18+] Link: http://lkml.kernel.org/r/20200803153231.15477-1-mhocko@kernel.org Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/page_counter.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/mm/page_counter.c +++ b/mm/page_counter.c @@ -72,7 +72,7 @@ void page_counter_charge(struct page_cou long new; new = atomic_long_add_return(nr_pages, &c->usage); - propagate_protected_usage(counter, new); + propagate_protected_usage(c, new); /* * This is indeed racy, but we can live with some * inaccuracy in the watermark. @@ -116,7 +116,7 @@ bool page_counter_try_charge(struct page new = atomic_long_add_return(nr_pages, &c->usage); if (new > c->max) { atomic_long_sub(nr_pages, &c->usage); - propagate_protected_usage(counter, new); + propagate_protected_usage(c, new); /* * This is racy, but we can live with some * inaccuracy in the failcnt. @@ -125,7 +125,7 @@ bool page_counter_try_charge(struct page *fail = c; goto failed; } - propagate_protected_usage(counter, new); + propagate_protected_usage(c, new); /* * Just like with failcnt, we can live with some * inaccuracy in the watermark.