Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3331782pxb; Tue, 12 Jan 2021 11:51:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJIx15xGiu/FN80fv+atRjYv1S0YdrzqFXb7gWzYBsVJRDIIg5lk+C4OqyUKojbeIDL/NF X-Received: by 2002:a05:6402:1516:: with SMTP id f22mr599990edw.382.1610481086721; Tue, 12 Jan 2021 11:51:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610481086; cv=none; d=google.com; s=arc-20160816; b=qH81hSLcur/pm08W3+lQvUB0ovUczlqTzQF9oIWECnqzYMvgMDmpWhQtT07nAHy7Xk X5mmTQERN9pmiLXjMYeKM5dDp2bEOuRq2pGTPt/NP3okLksIljzVG5JVbcYdHqKlT5kC JkpxuYHLgxz+Qo+th3AXnvUsKQcUI94hq2LYeKOb5hK0GDoPwY5iw9x+LY1jds+TedFP UDuX0eZ0qMLzL09EdELI3lquRWhGUOyZ/4oLSc6Rufo4EdCnGfnODojo9wF8bCkNsscF 4eKoFkok8X+JLCBKC9UXHxo7Cg31rPQrkVzPDo+gfzxBBVblqSuijWE/uweUO3kGtdR4 mqLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=uREbXCwcyfpXNTx7ee7MudJLRW7UlYdjL+1cYZJdpQ8=; b=0fHvAn/+lCX1F8jse1UePLOIWQtgzCY+2eCBe0t/e8JonDpeeTCirKL6YvBRa2mTbl pfH4AIkko8iECWS0OXSTBrEavLvozdhBf/RRZuoiPlcebRSZPohghziyIe8r1EFJHyEb dyOPRb9yU6G201h/Nk7E+LbMVta01gU0AjK4EiNmQqVd9CEEVeoJOtO3cBfvY6Do3k2Q NcF2MmBokOWJWt4VpUp7rxN9iyrhx/fBY3zA1R/9gf38wLSGryTsO2d9xVxHDzbnCk9X ylC9g+F3rPhLUESDrOvJc0S7LPhcTWasIMMXpbac218byCCIP8SNhMUKmzVsSkjrLo5V mJyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=VBloEoCX; 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=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d13si1477824ejz.583.2021.01.12.11.51.02; Tue, 12 Jan 2021 11:51:26 -0800 (PST) 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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=VBloEoCX; 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=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393127AbhALTsv (ORCPT + 99 others); Tue, 12 Jan 2021 14:48:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389021AbhALTsu (ORCPT ); Tue, 12 Jan 2021 14:48:50 -0500 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED160C061786 for ; Tue, 12 Jan 2021 11:48:09 -0800 (PST) Received: by mail-qv1-xf30.google.com with SMTP id h1so1455736qvy.12 for ; Tue, 12 Jan 2021 11:48:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=uREbXCwcyfpXNTx7ee7MudJLRW7UlYdjL+1cYZJdpQ8=; b=VBloEoCXCTkXhKEoW6IimofV0vg//Z0tXPoFnD6d5P94UevYTSdCMdq3LpxHSjRomX ProBumOzdn1ADj+XaPlwbnPOszyLly/YhmI79DIYyxrOnUUuUEIrgwOtFG/dBOIWi9eF nuu6nW0Kp+46ypeKukLzOpH4mqYWonf7ji/d8eKn2HKwUDNi3LvuEUx7bZ5qsL0ufKE9 kSKZSUtMg7qij3kLitiVEy4DBY9dlt1HQH5VoIJpNulRRXo3lS6k1zM7hv/mprTcH1yc /cR1A7M9TdQkuMaB97kg9iAXvPsf4HOydPsIsA0bpAvS0JcziMziwUg/xSDNVJ1CSY9l 6pMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=uREbXCwcyfpXNTx7ee7MudJLRW7UlYdjL+1cYZJdpQ8=; b=is8OeecvnUZ5mJI1Vi78Ogyj19QBlGPWrUQFApBomnqGuzXfoi+5Yxc7uqqvV0rMeT 0kB/JgHa86Yfq0dm6Q94Yy+NzRvazhyJCMpsQ6lxuyDCDHuQzhs5U1ZobdlCXcdvbpf7 3cWUcGLBwTDM/03EgXmfgqz12Gkrp58/sU4S4KI3eH/R+qQnfYbJaVk7xeq5CLPMgdl2 gn92HnoZ+kXA0kkP/Atus7LxNSRz3MMaPKbatGpdJ8kYjVgN3xanQH0O8IxcOoptIilL E/3IVRm0p9bnIDM92c6ZzEXXDf4U+RA0NANBrma50EDZ8iY91e86jTXvZxaQqGHK6xTf 93yA== X-Gm-Message-State: AOAM5310HxH7quY4Kgv8muED39qcWkIdGOL3rJ2oZXDCjNNw+HfeiBbt iicJW6qtyz7yoLEJGu6LSOhkwg== X-Received: by 2002:a0c:ac43:: with SMTP id m3mr1099634qvb.37.1610480889261; Tue, 12 Jan 2021 11:48:09 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:1fb4]) by smtp.gmail.com with ESMTPSA id y9sm1709017qtm.96.2021.01.12.11.48.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 11:48:08 -0800 (PST) Date: Tue, 12 Jan 2021 14:45:43 -0500 From: Johannes Weiner To: Roman Gushchin Cc: Andrew Morton , Tejun Heo , Michal Hocko , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH] mm: memcontrol: prevent starvation when writing memory.high Message-ID: References: <20210112163011.127833-1-hannes@cmpxchg.org> <20210112170322.GA99586@carbon.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210112170322.GA99586@carbon.dhcp.thefacebook.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 12, 2021 at 09:03:22AM -0800, Roman Gushchin wrote: > On Tue, Jan 12, 2021 at 11:30:11AM -0500, Johannes Weiner wrote: > > 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 > > --- > > 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--) > > Shouldn't it be (!reclaimed || !nr_retries) instead? > > If reclaimed == 0, it probably doesn't make much sense to retry. We usually allow nr_retries worth of no-progress reclaim cycles to make up for intermittent reclaim failures. The difference to OOMs/memory.max is that we don't want to loop indefinitely on forward progress, but we should allow the usual number of no-progress loops.