Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1840891ybh; Tue, 14 Jul 2020 08:39:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrLGKVdlx0q7O2fnpsLrV3uLZfgHxJLtksqIiUyV/xNPXwp1hvFT4k3wJtFQG1mBSCEg3r X-Received: by 2002:aa7:d692:: with SMTP id d18mr5237181edr.73.1594741188720; Tue, 14 Jul 2020 08:39:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594741188; cv=none; d=google.com; s=arc-20160816; b=t/Hb5EDKDpbYK795K9Ammoh0xEQyA2MFLA1sWFj+AGOO6B+GSkFgnLbFWSuPp1drs3 EFOhpC38bpxyY1QeLuFBARtbuCJpFjNJG+VR2ffCS+5QV3CXY35O5hvkytxhNxHbBdxf 4x+ple9/q91dWER/HYusjHmv16Yc7EU9yX7UfoN0fw1tQi68oqCF0KeD0CeWL6ZYKuIi 21xTer/QdVViB4eU06iy2obXpBRm5xVYpvt6Q0MTWPvrytF5DOxePi7u5h5/QdJpwxQi UE9AMm6kzrgAM5FyeKjiaC9v7vghrqnDoehY/eUyY0BhVEsnQiR35kqpbekIQA4FjzVW MH2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=udaIJS0JTvOfLh22C6s5PXq+hAqCuMLbXynj9AvwNfw=; b=wqZXU+hL5PGN3PVjCBIuqoxYPN71roMVjwAO5Eq2/rboS2fJZBiPuYohHOr4LLe/v/ 2jJkHryj8sc7Wp2mJjO8flVWDmaoEj4J9c+yuv3KkhI0CUE2BHsDs0cA+Rbr0mCQe8EG LgcXpN+dh2sUKX+1aYSuJZMnMxHbCHtc/PKeAgk8ji9uYh8W1FElPHmo7BIOalBICFhw MLtfWtayqUX6W6RD6+vcvmNlBuG86yMDL8YNJYuggYIa/BbDlOH6lAIVzuNBPH1b6teg Ru+jVsVePqZ4NB3Q3yENR3uH68Vrkf8I4gZL+sml40aqbJORxf/kjNN46FF5C4rtgMNL Yahg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=t36hGhq6; 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 h12si11086512ejf.12.2020.07.14.08.39.24; Tue, 14 Jul 2020 08:39:48 -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; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=t36hGhq6; 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 S1726338AbgGNPjJ (ORCPT + 99 others); Tue, 14 Jul 2020 11:39:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725280AbgGNPjJ (ORCPT ); Tue, 14 Jul 2020 11:39:09 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4EDBC061755 for ; Tue, 14 Jul 2020 08:39:08 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id e11so15992422qkm.3 for ; Tue, 14 Jul 2020 08:39:08 -0700 (PDT) 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=udaIJS0JTvOfLh22C6s5PXq+hAqCuMLbXynj9AvwNfw=; b=t36hGhq6fYlBHr3reEL60xJ9Hsqz2Fh7uaCmdq4G7aSIKOJe29wosZHkhylqlO8iMu rEUj1WtiMn6zd2vO1VFwPwLC6alSQ2GNbrY4E9StreSKDQasc6/Rbn27Un3RDSeFMCjY GFsVNP2u8YW/HcTOxNyQ1Pfdta0FENBlljwec8KQsrk2jaJARDlUdeFLLpxS3V+w6N2+ 77W/AJFo+Oak5RIhf/dgVKowiHgAMf5exTiensoa5uRk/A/WsbFazxULX7O+KFL+nNEy PWtH/EmzaVyQTEj44kB/MBC7iRhZUoWr7RtxTcqQWlSaYPHiqcrdfbbAXvsv6rZVAVA4 rHfQ== 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=udaIJS0JTvOfLh22C6s5PXq+hAqCuMLbXynj9AvwNfw=; b=jVpNkoGVTv/a/y1j7KoTthgfB13S9oIdBlr7D1qluCpAMlIuF0WJeTwxW/3Ev9Av7b RbCcWjkkhg+ww3tFTBirWnFEcbloqVWAaR6CsLbAArULVQ0ijRbMF9tp0eZXlnkAsmuS BRCP2WAoSDkWzMQlgyRC50IyLZWVJG7dpAzaT0Rapg4pqfD7DNKD6LeQ8QV1DXPrVmbA miNV5bYQB1L1d3jpniictEXYpDWjvaJpOi6hpnZ6eWsNcHK6iJFI+uW+95qIQMRMFy5B drRmoz171u7Zpy7jCz8VD4NOsVwIIrieT74GwQxts+dh5cNncBjtCyRDQ7v6M4zO2743 6Q+g== X-Gm-Message-State: AOAM532Wmn5QBw51Drubz0stiravyLAUrnJ4esOnivpr3LwV9fPouZLf 03ccyo3JWsrgWmLtNVzyVm3pRA== X-Received: by 2002:a05:620a:2298:: with SMTP id o24mr5050638qkh.73.1594741147787; Tue, 14 Jul 2020 08:39:07 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:81a8]) by smtp.gmail.com with ESMTPSA id d14sm2791142qkl.9.2020.07.14.08.39.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2020 08:39:06 -0700 (PDT) Date: Tue, 14 Jul 2020 11:38:17 -0400 From: Johannes Weiner To: Shakeel Butt Cc: Roman Gushchin , Michal Hocko , Andrew Morton , Linux MM , Kernel Team , LKML , Domas Mituzas , Tejun Heo , Chris Down Subject: Re: [PATCH] mm: memcontrol: avoid workload stalls when lowering memory.high Message-ID: <20200714153817.GA215857@cmpxchg.org> References: <20200709194718.189231-1-guro@fb.com> <20200710122917.GB3022@dhcp22.suse.cz> <20200710184205.GB350256@carbon.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 10, 2020 at 12:19:37PM -0700, Shakeel Butt wrote: > On Fri, Jul 10, 2020 at 11:42 AM Roman Gushchin wrote: > > > > On Fri, Jul 10, 2020 at 07:12:22AM -0700, Shakeel Butt wrote: > > > On Fri, Jul 10, 2020 at 5:29 AM Michal Hocko wrote: > > > > > > > > On Thu 09-07-20 12:47:18, Roman Gushchin wrote: > > > > > Memory.high limit is implemented in a way such that the kernel > > > > > penalizes all threads which are allocating a memory over the limit. > > > > > Forcing all threads into the synchronous reclaim and adding some > > > > > artificial delays allows to slow down the memory consumption and > > > > > potentially give some time for userspace oom handlers/resource control > > > > > agents to react. > > > > > > > > > > It works nicely if the memory usage is hitting the limit from below, > > > > > however it works sub-optimal if a user adjusts memory.high to a value > > > > > way below the current memory usage. It basically forces all workload > > > > > threads (doing any memory allocations) into the synchronous reclaim > > > > > and sleep. This makes the workload completely unresponsive for > > > > > a long period of time and can also lead to a system-wide contention on > > > > > lru locks. It can happen even if the workload is not actually tight on > > > > > memory and has, for example, a ton of cold pagecache. > > > > > > > > > > In the current implementation writing to memory.high causes an atomic > > > > > update of page counter's high value followed by an attempt to reclaim > > > > > enough memory to fit into the new limit. To fix the problem described > > > > > above, all we need is to change the order of execution: try to push > > > > > the memory usage under the limit first, and only then set the new > > > > > high limit. > > > > > > > > Shakeel would this help with your pro-active reclaim usecase? It would > > > > require to reset the high limit right after the reclaim returns which is > > > > quite ugly but it would at least not require a completely new interface. > > > > You would simply do > > > > high = current - to_reclaim > > > > echo $high > memory.high > > > > echo infinity > memory.high # To prevent direct reclaim > > > > # allocation stalls > > > > > > > > > > This will reduce the chance of stalls but the interface is still > > > non-delegatable i.e. applications can not change their own memory.high > > > for the use-cases like application controlled proactive reclaim and > > > uswapd. > > > > Can you, please, elaborate a bit more on this? I didn't understand > > why. > > > > Sure. Do we want memory.high a CFTYPE_NS_DELEGATABLE type file? I > don't think so otherwise any job on a system can change their > memory.high and can adversely impact the isolation and memory > scheduling of the system. > > Next we have to agree that there are valid use-cases to allow > applications to reclaim from their cgroups and I think uswapd and > proactive reclaim are valid use-cases. Let's suppose memory.high is > the only way to trigger reclaim but the application can not write to > their top level memory.high, so, it has to create a dummy cgroup of > which it has write access to memory.high and has to move itself to > that dummy cgroup to use memory.high to trigger reclaim for > uswapd/proactive-reclaim. For what it's worth, for proactive reclaim driven by userspace, we're currently carrying a hacky memory.high.tmp in our private tree. It takes a limit and a timeout, so that in case the daemon crashes during a dip in memory consumption no unsafe limits are left behind. We haven't upstreamed it because it's not clear yet how exactly the interface should look like. The userspace daemon is still evolving. But I think we're going to need *some form* of a dedicated knob to make this operation safe. As far as permissions to self-pressurize go - I'm curious how you make that safe? How do you keep the reclaim daemon from accidentally putting excessive pressure on its own cgroup that may interfere with the very act of backing off the limit again? The way we do this right now is having the reclaimer daemon in a dedicated top-level cgroup with memory.min protection. This works well because we have a comprehensive cgroup setup anyway and need to protect this daemon (it's oomd - the proactive reclaimer, senpai, is a plugin) for other reasons as well. But it's probably a royal pain to use if you don't have all of that infrastructure. One possible idea to make this simpler would be to have a limit knob that has a psi/pressure blowout valve. This way you could specify your tolerances for paging and what constitutes "cold" memory, and the limit unsets itself when pressure moves into harmful territory. This would make it safe to use when the reclaimer becomes unresponsive or dies altogether, which makes it safe to use from within the cgroup. And being separate from max and high means we can delegate it.