From patchwork Sat Mar 12 07:16:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 12778754 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F95FC433F5 for ; Sat, 12 Mar 2022 07:16:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C65E8D0006; Sat, 12 Mar 2022 02:16:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B3128D0001; Sat, 12 Mar 2022 02:16:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 305468D0006; Sat, 12 Mar 2022 02:16:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by kanga.kvack.org (Postfix) with ESMTP id 1EF0D8D0001 for ; Sat, 12 Mar 2022 02:16:47 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id CC20E181CC1B4 for ; Sat, 12 Mar 2022 07:16:46 +0000 (UTC) X-FDA: 79234876812.20.780B41A Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by imf18.hostedemail.com (Postfix) with ESMTP id 69B9D1C0021 for ; Sat, 12 Mar 2022 07:16:46 +0000 (UTC) Received: by mail-ej1-f45.google.com with SMTP id d10so23420193eje.10 for ; Fri, 11 Mar 2022 23:16:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6eF3CkGTMOIQmVHUtkEwTATvUD+GDDg0zGlDrlu3cRs=; b=LJ8fzFe6HkpMjK3dAG/kkCB3VwjmJ5YokqYQBqn6mRELFnmoDR4ND2YGflHHQEY3cw cHN2GmvSaxTqzUyKiaZ6G8mHq8RfzREKBl/YpsSReGoKIicDRHevo1QbIm1z64ki9ydZ pRhNKC3UotSGcN2JnVtD+VJ7gz7fnGndetV6M4+7G3pGlRMVUfOdoBLqqjJonINME7Lz X1wG7JfWG67Nm3dD3p8y7Vmt+mZiOjMmF9XwDF/9Z2bTX6XZJ88FXOTMfvYNrcmzXyuH UKAMGTiXg31ZO88PFlisMM/+EvoJVtJ60F3IWXVXj7eWcyg3PQBPDPcLj8gastjMjOZT hXMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6eF3CkGTMOIQmVHUtkEwTATvUD+GDDg0zGlDrlu3cRs=; b=Kj9891V33TslFO+RoZdBiJDmfgbKz3smYKeAWqJd1g03XZXbRLllYvZbI/TrM+XB5k zL9rBIh7csoI60A74Sal7Db+STJSmHU+T6sKq2IcsG0xy44vaSlGPvq2dKq46qoq9xqv lhhiwEKaS597BV/y1vIXRh9nV4GbSQPiUEGEXWyVbqqq77Oo2htpVJCkRG4yrNTmwJ60 s8r1N0etZPSeNVepnfviyBkXliM+y7yjW9pxYowMJEiQ1P+DZHeg2v3jlogDAPm7bKFt syywcwHDiksXS0yuoyfrfglUMUB/C/VkoGIHcJUX9PyH0EdRVslHUnUIC4qNEKfv/uiU GI7Q== X-Gm-Message-State: AOAM531AFAMD3epvCde/o2Kq7Lkrj7tPANiQhIPPYafmFg+WDGrqc5Fg 2g9y19lwoexe40rBP5aAMDA= X-Google-Smtp-Source: ABdhPJwqMXsfiaLvKKPLz6WsxVosaOPmy5L2VlCKhaMPJ2MZj7Bkc+bVrRx/4xwJMxKmu3vU7/oliw== X-Received: by 2002:a17:907:6296:b0:6da:745b:7b40 with SMTP id nd22-20020a170907629600b006da745b7b40mr11567649ejc.750.1647069405200; Fri, 11 Mar 2022 23:16:45 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id s18-20020a170906779200b006dbb2c2a847sm1148528ejm.125.2022.03.11.23.16.44 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Mar 2022 23:16:44 -0800 (PST) From: Wei Yang To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, Wei Yang Subject: [Patch v2 3/3] mm/memcg: add next_mz back to soft limit tree if not reclaimed yet Date: Sat, 12 Mar 2022 07:16:23 +0000 Message-Id: <20220312071623.19050-3-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220312071623.19050-1-richard.weiyang@gmail.com> References: <20220312071623.19050-1-richard.weiyang@gmail.com> X-Rspamd-Queue-Id: 69B9D1C0021 X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LJ8fzFe6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com X-Stat-Signature: g375m8y6e7moxoketcpju19iu13b4ku6 X-Rspamd-Server: rspam04 X-HE-Tag: 1647069406-630700 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: When memory reclaim failed for a maximum number of attempts and we bail out of the reclaim loop, we forgot to put the target mem_cgroup chosen for next reclaim back to the soft limit tree. This prevented pages in the mem_cgroup from being reclaimed in the future even though the mem_cgroup exceeded its soft limit. Let's say there are two mem_cgroup and both of them exceed the soft limit, while the first one is more active then the second. Since we add a mem_cgroup to soft limit tree every 1024 event, the second one just get a rare chance to be put on soft limit tree even it exceeds the limit. As time goes on, the first mem_cgroup was kept close to its soft limit due to reclaim activities, while the memory usage of the second mem_cgroup keeps growing over the soft limit for a long time due to its relatively rare occurrence. This patch adds next_mz back to prevent this sceanrio. Signed-off-by: Wei Yang Acked-by: Michal Hocko --- mm/memcontrol.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 344a7e891bc5..e803ff02aae2 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3493,8 +3493,13 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, loop > MEM_CGROUP_MAX_SOFT_LIMIT_RECLAIM_LOOPS)) break; } while (!nr_reclaimed); - if (next_mz) + if (next_mz) { + spin_lock_irq(&mctz->lock); + excess = soft_limit_excess(next_mz->memcg); + __mem_cgroup_insert_exceeded(next_mz, mctz, excess); + spin_unlock_irq(&mctz->lock); css_put(&next_mz->memcg->css); + } return nr_reclaimed; }