Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp282072pxb; Fri, 15 Jan 2021 12:59:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9roR/i9Q5RpCqe0MD5pkTf4ToD1y4Gpj15B9IyY80yd3RrXpg0uCrND5CVJu3t/ub4mDc X-Received: by 2002:aa7:d803:: with SMTP id v3mr5510197edq.153.1610744387677; Fri, 15 Jan 2021 12:59:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610744387; cv=none; d=google.com; s=arc-20160816; b=hLIUf9cjf7YI40meeXgZp9TT7ydGxWlozkhy0Fja/7JtubK7K+oq7me7/EVqheocxy jYC3q0C6c4WAoxLGCN2ac6myu2r34viBowmyx9EoNvtkAYVvGpP6NF+OEMLXxR5S8Phw ErOnmOgbZutFJUZfIiWknHbjGldStSir22rMN5EFOG2mxZzDdLe1+HscggO6srp/Boa0 Yn8Iw6k1wARzf0drtoWisOd53JsTaBy5C9aoEvHXkp47gBb9YTY33oAFkYMBGuVYoVQh vDsus2vcGsJEmITR6JtQKGwCiuhKad5UQGpe6xcXzm7c8qpEIRJ7Or43W58iAPNJPNKq S8Hg== 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=SlNlvcKcVOLSQ+6ubVv+zQmNdKKd35YVKlEcU4lZbR0=; b=w3n4+KQxAxwRlKBQEs70qpSMydtnQSmJ+g9m9uY5uX1DGLPRjkugSV6e5emJ8Onfa3 hHk8pOrpcg6R518+iW/jbhUn1mz9cZOsLXvMyUG5kkEz7TEqVfaA4nceUqpBIy9bOBSq cJbBMcTbWDwBc02LDwniQ/wV/4VPn0/mERpPHUjaZYyv0cPuxud+buPaq9AR1LLY38ea CU+bQjrmiQO77DMRrSHVy1rJ0LEvDiRypSG276GJ0veduF2dBmsyWK54cFjdxHXDVdoW KHDvLBjGOtYvtTSSklEzF1D1A8Dg8iHKIZ8+pPjt7mV4oyVOk50ABHTeEuALl5wDoAvU lw+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=08diUBE1; 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 lc24si926518ejb.11.2021.01.15.12.59.22; Fri, 15 Jan 2021 12:59:47 -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=08diUBE1; 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 S1729312AbhAOU4W (ORCPT + 99 others); Fri, 15 Jan 2021 15:56:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726286AbhAOU4T (ORCPT ); Fri, 15 Jan 2021 15:56:19 -0500 Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E14DC0613D3 for ; Fri, 15 Jan 2021 12:55:39 -0800 (PST) Received: by mail-qt1-x82c.google.com with SMTP id z20so7053043qtq.3 for ; Fri, 15 Jan 2021 12:55:39 -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=SlNlvcKcVOLSQ+6ubVv+zQmNdKKd35YVKlEcU4lZbR0=; b=08diUBE1TRDu8jkonn5T7HGIPR4ggImv2F40SdRk2Vj2uUcUYhKHWt3hXjiCtm3yKM ktR2KdE6uaQ1EEo4scHUcpcm3q/u8L3zD02rEv+YWZ+/RjgfnSCX4igqLCJNqbP8JkhD wuai1GglPwLSYmuoHuc7NqKeNnvJ1fFTjed821X7BinBBXs30qDK83vV98QDudCTf35I B+3ADJAZ0QlHeLaozMOEt0o3EiMZpPbbLotoxVgV/V9yQv0oW9G4KO4F/FfwPOppPk8E Mq/xHc64yoKMTsKPSzaN74uXJU7RrcYKPM1MYdxLZUTxaZ/NPHUWglckARwnmnDXyPCl 4wIg== 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=SlNlvcKcVOLSQ+6ubVv+zQmNdKKd35YVKlEcU4lZbR0=; b=L0vU8cZo/1a3bEyq+ZcaMxWnrAwJL//OmG5hPK/ylr8snnfrj0iCfnifmiYOA3yrEb X/BzcxrxzElZqFBO5J6iyvL9+390zVgkrI/6LbfTwQC7NaVqAEjaByEevVfIRVNsKUF8 /n05wFq5IO3tcG8gVTBA4IcRiVYZVsrNvHtahDfu5EYzaB1yyikJAEcX84ioLapVqynW vK+TZkJlPnW7D8lxB3uVg3R7Fbju8XAGPrWzFG8zoaioKJmhgXpemhT2EuzbLS4tqqbi sgEkZwqSqg5++izM8yPJ8u05wj/ZyP2ueKaETgG1mEAr2nONRbB2zpCSIRhndaPMStYy M6ag== X-Gm-Message-State: AOAM532YW3GwBFLozgag7sz09QZRepZSxjZHvg5bCKRjVJH7CXbH3278 zQXzEgixn7X4ZBMcS9U0Excx8pKJOwrZ3A== X-Received: by 2002:ac8:45d7:: with SMTP id e23mr13629017qto.149.1610744138477; Fri, 15 Jan 2021 12:55:38 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:dbed]) by smtp.gmail.com with ESMTPSA id 190sm5870540qkf.61.2021.01.15.12.55.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 12:55:37 -0800 (PST) Date: Fri, 15 Jan 2021 15:55:36 -0500 From: Johannes Weiner To: Roman Gushchin Cc: Michal Hocko , Andrew Morton , Tejun Heo , 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> <20210113144654.GD22493@dhcp22.suse.cz> <20210115170341.GA631549@carbon.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210115170341.GA631549@carbon.dhcp.thefacebook.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 15, 2021 at 09:03:41AM -0800, Roman Gushchin wrote: > On Fri, Jan 15, 2021 at 11:20:50AM -0500, Johannes Weiner wrote: > > On Wed, Jan 13, 2021 at 03:46:54PM +0100, Michal Hocko wrote: > > > On Tue 12-01-21 11:30:11, 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. > > > > > > I can see that you have provided some more details in follow up replies > > > but I do not see any explicit argument why an excessive time for writer > > > is an actual problem. Could you be more specific? > > > > Our writer isn't necessarily time sensitive, but there is a difference > > between a) the write taking a few seconds to reclaim down the > > requested delta and b) the writer essentially turning into kswapd for > > the workload and busy-spinning inside the kernel indefinitely. > > > > We've seen the writer stuck in this function for minutes, long after > > the requested delta has been reclaimed, consuming alarming amounts of > > CPU cycles - CPU time that should really be accounted to the workload, > > not the system software performing the write. > > > > Obviously, we could work around it using timeouts and signals. In > > fact, we may have to until the new kernel is deployed everywhere. But > > this is the definition of an interface change breaking userspace, so > > I'm a bit surprised by your laid-back response. > > > > > > Fixes: 536d3bf261a2 ("mm: memcontrol: avoid workload stalls when lowering memory.high") > > > > Cc: # 5.8+ > > > > > > Why is this worth backporting to stable? The behavior is different but I > > > do not think any of them is harmful. > > > > The referenced patch changed user-visible behavior in a way that is > > causing real production problems for us. From stable-kernel-rules: > > > > - It must fix a real bug that bothers people (not a, "This could be a > > problem..." type thing). > > > > > > Reported-by: Tejun Heo > > > > Signed-off-by: Johannes Weiner > > > > > > I am not against the patch. The existing interface doesn't provide any > > > meaningful feedback to the userspace anyway. User would have to re check > > > to see the result of the operation. So how hard we try is really an > > > implementation detail. > > > > Yeah, I wish it was a bit more consistent from an interface POV. > > > > Btw, if you have noticed, Roman's patch to enforce memcg->high *after* > > trying to reclaim went into the tree at the same exact time as Chris's > > series "mm, memcg: reclaim harder before high throttling" (commit > > b3ff92916af3b458712110bb83976a23471c12fa). It's likely they overlap. > > > > Chris's patch changes memory.high reclaim on the allocation side from > > > > reclaim once, sleep if there is still overage > > > > to > > > > reclaim the overage as long as you make forward progress; > > sleep after 16 no-progress loops if there is still overage > > > > Roman's patch describes a problem where allocating threads go to sleep > > when memory.high is lowered by a wider step. This is exceedingly > > unlikely after Chris's change. > > > > Because after Chris's change, memory.high is reclaimed on the > > allocation side as aggressively as memory.max. The only difference is > > that upon failure, one sleeps and the other OOMs. > > > > If Roman's issue were present after Chris's change, then we'd also see > > premature OOM kills when memory.max is lowered by a large step. And I > > have never seen that happening. > > > > So I suggest instead of my fix here, we revert Roman's patch instead, > > as it should no longer be needed. Thoughts? > > Chris's patch was merged way earlier than mine into the kernel tree which > was used when I observed the problem in the production. So likely it was there. Chris's patch was in the tree earlier, but the first release containing it was tagged a day before you put in your change, so I doubt it was on the production system where you observed the issue. As per above, it'd be very surprising to see premature sleeps when lowering memory.high, when allocation-side reclaim keeps going until the cgroup meets the definition of OOM. > I think it makes sense to try to reclaim memory first before putting > all processes in the cgroup into reclaim mode. Even without artificial delays > it creates some latency and btw doesn't make the reclaim process more efficient. It's not obvious that this is a practical problem. It certainly isn't for memory.max, and there should be a good reason why the two should be different aside from the documented OOM vs sleep behavior. Absent any concrete evidence to the contrary, I'd make the behavior the same again for those two.