From patchwork Tue Jan 12 16:30:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 12014043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66237C433E0 for ; Tue, 12 Jan 2021 16:32:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D202422B2B for ; Tue, 12 Jan 2021 16:32:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D202422B2B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F0DDF8D00BE; Tue, 12 Jan 2021 11:32:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EBDFE6B02B1; Tue, 12 Jan 2021 11:32:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DADAA8D00BE; Tue, 12 Jan 2021 11:32:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id C66926B02B0 for ; Tue, 12 Jan 2021 11:32:39 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 88CB1180AD817 for ; Tue, 12 Jan 2021 16:32:39 +0000 (UTC) X-FDA: 77697666438.09.silk36_420060527516 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 6979E180AD807 for ; Tue, 12 Jan 2021 16:32:39 +0000 (UTC) X-HE-Tag: silk36_420060527516 X-Filterd-Recvd-Size: 4932 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 16:32:38 +0000 (UTC) Received: by mail-qk1-f179.google.com with SMTP id z11so2342259qkj.7 for ; Tue, 12 Jan 2021 08:32:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=aSfbgJHMgHLM9rzB5N8TPqwylQdBK6aN3u6pmU/8Jk4=; b=XRtRi+npxUhv1aIaFonEpF9d9xK4DvoowayUJ3B3qkBd1aLaEH2E7JKQzu/AV9pDOT fIETBbFsDj6lgUWnkEQOnMgb7rUD27wGjJ5x5wHlEWIAsCLQgmMLTbbFJKgO6jhO5aFm 4xwavol2Mz98x5eMv0tqfMrRy+KoNbmEtxmNcHHm2cFTepKbx9AmChWp/aH65taw8I7q MYxPRcAhTffnCW9cbjoc4FdWKHgpDC4bT+m0LLWJAmr4sKbd8tpTA4wO5kOY8VehxlL7 tABlka6b/ikymYrABypNGD7TfR74nzqfsrYHaT9I0xbrxyLhmu4wIAZH3UjsqchkNTx6 2fuA== 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=aSfbgJHMgHLM9rzB5N8TPqwylQdBK6aN3u6pmU/8Jk4=; b=cc3b0dT2K/YnDo3pLnP6fO8P44kI5ivjEjjzVzVViqqwIrVFDgzmZU6QKGOpy0q6qB kWgc/YXFZh0yA2M4WPxPtcMxGPni+1Li8Ihm+PenbLQrFyLv5mR1xaIZeg/75IOhN/zg 9Q39K53ysZD+PB5gk1lQLWIfoWh6BlpjPkNVbpp4tY8T+iVIQlsxYvVkEEZTlkLMKl25 wK+YALf5Oysjd3IXSWkOG0zgJgtu5ljOEKZBa0Rr2dBKuP/JHsRTxTtabHkGXKgnFk0Q r9xr5HjLZYFtxiWFc4AftG+pFj73CIcHXbtbUdy+osen3n8aiBVomDxtx15kn/s+kw9X JfBw== X-Gm-Message-State: AOAM531j2nHS9lNP6+vdcu9KZ8r4nv5nf+LAG5/OJezTn9J+tUSiKb43 JO56H479yjhbuGvE6IMTLCmezg== X-Google-Smtp-Source: ABdhPJxHrShkZ/TEBY6Kc+dwor37fO2ZPO8LEL1PAw3K5sR2T3rxsJacgtbo9WyiKHFNnedWpoGcog== X-Received: by 2002:a37:aace:: with SMTP id t197mr89781qke.175.1610469157955; Tue, 12 Jan 2021 08:32:37 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:1fb4]) by smtp.gmail.com with ESMTPSA id m190sm1530954qkb.42.2021.01.12.08.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 08:32:37 -0800 (PST) From: Johannes Weiner To: Andrew Morton Cc: Tejun Heo , Roman Gushchin , Michal Hocko , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH] mm: memcontrol: prevent starvation when writing memory.high Date: Tue, 12 Jan 2021 11:30:11 -0500 Message-Id: <20210112163011.127833-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 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 a value is written to a cgroup's memory.high control file, the write() context first tries to reclaim the cgroup to size before putting the limit in place for the workload. Concurrent charges from the workload can keep such a write() looping in reclaim indefinitely. In the past, a write to memory.high would first put the limit in place for the workload, then do targeted reclaim until the new limit has been met - similar to how we do it for memory.max. This wasn't prone to the described starvation issue. However, this sequence could cause excessive latencies in the workload, when allocating threads could be put into long penalty sleeps on the sudden memory.high overage created by the write(), before that had a chance to work it off. Now that memory_high_write() performs reclaim before enforcing the new limit, reflect that the cgroup may well fail to converge due to concurrent workload activity. Bail out of the loop after a few tries. Fixes: 536d3bf261a2 ("mm: memcontrol: avoid workload stalls when lowering memory.high") Cc: # 5.8+ Reported-by: Tejun Heo Signed-off-by: Johannes Weiner Reviewed-by: Shakeel Butt Reviewed-by: Michal Koutný Acked-by: Roman Gushchin --- mm/memcontrol.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 605f671203ef..63a8d47c1cd3 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6275,7 +6275,6 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, for (;;) { unsigned long nr_pages = page_counter_read(&memcg->memory); - unsigned long reclaimed; if (nr_pages <= high) break; @@ -6289,10 +6288,10 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, continue; } - reclaimed = try_to_free_mem_cgroup_pages(memcg, nr_pages - high, - GFP_KERNEL, true); + try_to_free_mem_cgroup_pages(memcg, nr_pages - high, + GFP_KERNEL, true); - if (!reclaimed && !nr_retries--) + if (!nr_retries--) break; }