Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2145889pxa; Mon, 3 Aug 2020 08:34:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqWW/92g+JqFA+6TYQCSthoHr0jdjdM+k/6dsQSaOElELTiToOmM+9kjfLelCIJPxotJER X-Received: by 2002:a17:906:a142:: with SMTP id bu2mr17919177ejb.277.1596468847531; Mon, 03 Aug 2020 08:34:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596468847; cv=none; d=google.com; s=arc-20160816; b=s+sg3FW6mBc1qmZsuNLMCCx95sqaOK3U+fAfDn6P3rUV8a7h7y1UW33mV/us/IJs+0 Ayoz8uxlQn9fT/JmvO9P6k6/s8PsA6NfxnPqZUrrPO4pFoeaKRlrKTXCNGfIgsyDLkST BWdg5D93WkeOHguwGPvhZKeQ1gMaNaQpsKcaGF3DdO/ibFKT6OEZHkWoS7lQHkF/bUQH U2Aal1fdu2e1W4w2yQldzdSFc5M0Bnt7XDzoczVGgYlWiMrMzFxciOHqnPp8bI0i1EOo fqnKQMwNMl+3tsdbNAsR3vX8k/ia6PDAyHOG2cxUyD1lKPZ9GKtZktL43IwiI3vC6HzW u/fA== 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 :message-id:date:subject:cc:to:from; bh=aAEEBYH/RNE6F6eih4Xf8kJGXqfcNHHmi9tjJ8DCSlI=; b=QPFwhwVo942rB9KQ7n13a12QYx4F2PXTIeFGMzsV0x0sEzzZGkNGBmiXXWoVCYG9T+ 0hX8PX6/nltAVvEpvFmtnFIzAqydTe/PrW+ciaFSrpv3AMy2PsyxGvOwP1ZQ/e6Pk5ve 1sMNplHzviluGv01O03hillRixZErY7uP8ty6BbnKx7e36wVv2BoJSbkJEE15vZuVSiA wTZNRpiLzdBcHReKO3TDHm8h+UTGmkiGxpzwscXXJwpFltq6XU2WauZZ8abmZ7aN8Bkc iIisOCf0etVsTm4+vZVIl+LWphPc7Dh1Qd7ice2kETkm0/lyhFAXemYqwzz486QKQIIX L7hQ== ARC-Authentication-Results: i=1; mx.google.com; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z8si10870416ejm.420.2020.08.03.08.33.45; Mon, 03 Aug 2020 08:34:07 -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; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726906AbgHCPcs (ORCPT + 99 others); Mon, 3 Aug 2020 11:32:48 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39501 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726130AbgHCPcq (ORCPT ); Mon, 3 Aug 2020 11:32:46 -0400 Received: by mail-wm1-f67.google.com with SMTP id q76so14630003wme.4 for ; Mon, 03 Aug 2020 08:32:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=aAEEBYH/RNE6F6eih4Xf8kJGXqfcNHHmi9tjJ8DCSlI=; b=ZHEu9jrEGD5jfkB7KwMAUjYGFHe6d0avoeArT8Q1YCmb7TBmz/19HUwWNCgjY/HNFE OIx1TArP5pGgr4hIj+O1waKxpcuzI1/+0RYXU/TM7MOIgmvff5PhS0sVC5/pGFW/HhjF qrupkkiunMVjcB7m9T7rYcs9a0lbH98G7LuBNdMhOAE+iYWQiIbID0qzz1RS4Q0VGvyM 2CF8moP78kRTnDvjUKSvz7/1kY8K1USjOZQHHIPOLK1SnMR3n9wsbQCcaMioM7B7w15j Mt5NIrA49jIMPDdkCPuDEO9zt7k3zYBBDJggms0pC70E2ZZU1qIAl7HQhfMs4ISSv/kh wNCA== X-Gm-Message-State: AOAM532MMB0VSPGx7eLyX7rzwxQywA0H4lKJ0MphW0RRd7u3btWNQC1Z DoJtrjo48NfXMX9yUDBmolY= X-Received: by 2002:a1c:ba83:: with SMTP id k125mr515975wmf.160.1596468764859; Mon, 03 Aug 2020 08:32:44 -0700 (PDT) Received: from tiehlicka.suse.cz (ip-37-188-169-187.eurotel.cz. [37.188.169.187]) by smtp.gmail.com with ESMTPSA id w1sm25562444wmc.18.2020.08.03.08.32.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 08:32:44 -0700 (PDT) From: Michal Hocko To: Johannes Weiner , Roman Gushchin , Andrew Morton , Michal Koutny Cc: Tejun Heo , , LKML , Michal Hocko Subject: [PATCH] mm: Fix protection usage propagation Date: Mon, 3 Aug 2020 17:32:31 +0200 Message-Id: <20200803153231.15477-1-mhocko@kernel.org> X-Mailer: git-send-email 2.27.0 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ý 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 indended protection unexpectedly. The fix is simply updating children_low_usage in respective ancestors also in the charging path. Fixes: 230671533d64 ("mm: memory.low hierarchical behavior") Cc: stable # 4.18+ Signed-off-by: Michal Koutný Acked-by: Michal Hocko --- Hi, I am sending this patch on behalf of Michal Koutny who is currently on vacation and didn't get to post it before he left. 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. I am adding my ack directly in this submission. mm/page_counter.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/page_counter.c b/mm/page_counter.c index c56db2d5e159..b4663844c9b3 100644 --- a/mm/page_counter.c +++ b/mm/page_counter.c @@ -72,7 +72,7 @@ void page_counter_charge(struct page_counter *counter, unsigned long nr_pages) 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_counter *counter, 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_counter *counter, *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. -- 2.27.0