Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp956567pxw; Sat, 9 Apr 2022 06:27:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUfZch7T5ptNhJ1qakRaibRF1B+pMOALrFZDGKo5cbDn/3MzuPG4MkFAx/705ZLikiMgCD X-Received: by 2002:a17:902:74cb:b0:158:2f25:4051 with SMTP id f11-20020a17090274cb00b001582f254051mr5222623plt.29.1649510833974; Sat, 09 Apr 2022 06:27:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649510833; cv=none; d=google.com; s=arc-20160816; b=EySt/n9192MDp+2KPHvhhgl6LOpSjWJjcjgcUWoJRBW3y+gpDaAuZin6IKMw9abV3u CCIhHJuq9vqSqxY7r1bzcVmQQzGJoVoSXnfCejAC87+K0881WizMJHpVY5OlRx3yGruB 5uNDxb7M5m2MXJIj1htHvYoCByx5V1O1vkt8WFq21+ObQj7lwNo1a20C/YFd/leWj0XP 8lPa0PR3Vi/v8b+zmrZX6Ab80wHR2DCB5KBHbnYzdlGVgHLLG4yJil7qSKR5w3fpknCy SLtY2nJ4iCC8D3WERDnWnXG2kQ/V+oIzqXoYlfB+6co3InnU/7jYHg23Z8Zf0qrowfOM qXvA== 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:dkim-signature:date; bh=H//e2ty06NElxV3oXbEOWS2Nb6fAWBDWPPJzb55T3rY=; b=SiYb82ODwNciqrE0NmB4RLi2XH9LSZEzPVox3Tt1n34Ql83rDDtbUCI9ghionqMWmk Do8tzLKupC70UPd7x2cy2Ktlwb8LFnCMMcsNejW6Sn4CyBWOQG3B5a3zPxLmbwAohma3 OMQdbXgipdtTLyJA8MWkd1CysND7/5faKNGrkTsRFTdetYC1JzP9R84ekh4Q2cA2HBwA 4srkq7dwa/XG/mY1oyWYGWOYBhW2H1arpKplFy7IfSmw3LHBGfm93sEQ3L94V2Ar7PeG LhB2zp/NhUsAcZpr5L0+WLWztx2LkF7t/sn44jM1Ujlju4/NIR+pKIplnqG5sMgnvV6P ATWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=XapiOUYq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020a056a000cc500b004fdcc444adcsi4046381pfv.82.2022.04.09.06.26.59; Sat, 09 Apr 2022 06:27:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=XapiOUYq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234836AbiDIBPs (ORCPT + 99 others); Fri, 8 Apr 2022 21:15:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbiDIBPr (ORCPT ); Fri, 8 Apr 2022 21:15:47 -0400 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 146C5C0B; Fri, 8 Apr 2022 18:13:42 -0700 (PDT) Date: Fri, 8 Apr 2022 18:13:29 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1649466820; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=H//e2ty06NElxV3oXbEOWS2Nb6fAWBDWPPJzb55T3rY=; b=XapiOUYqHdDb2K9tAA0ftrN5h20ybKOWHg0Iy/mqlm/WVinf4DBP7ahmYtxacOGutc2mn+ /cfvwtisoA3IBAhwkTQzrE/nnr8q+0Iz01Zfw/1SaelKbAteprCeRQ3avIk7jvNtWWpjCs WFvmxmZYFGMacn8G4oNFAGXKJEkLHa8= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Yosry Ahmed Cc: Johannes Weiner , Michal Hocko , Shakeel Butt , Andrew Morton , David Rientjes , Tejun Heo , Zefan Li , Jonathan Corbet , Shuah Khan , Yu Zhao , Dave Hansen , Wei Xu , Greg Thelen , Chen Wandun , Vaibhav Jain , Michal =?iso-8859-1?Q?Koutn=FD?= , Tim Chen , cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Michal Hocko Subject: Re: [PATCH v3 1/4] memcg: introduce per-memcg reclaim interface Message-ID: References: <20220408045743.1432968-1-yosryahmed@google.com> <20220408045743.1432968-2-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220408045743.1432968-2-yosryahmed@google.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 08, 2022 at 04:57:40AM +0000, Yosry Ahmed wrote: > From: Shakeel Butt > > Introduce a memcg interface to trigger memory reclaim on a memory cgroup. > > Use case: Proactive Reclaim > --------------------------- > > A userspace proactive reclaimer can continuously probe the memcg to > reclaim a small amount of memory. This gives more accurate and > up-to-date workingset estimation as the LRUs are continuously > sorted and can potentially provide more deterministic memory > overcommit behavior. The memory overcommit controller can provide > more proactive response to the changing behavior of the running > applications instead of being reactive. > > A userspace reclaimer's purpose in this case is not a complete replacement > for kswapd or direct reclaim, it is to proactively identify memory savings > opportunities and reclaim some amount of cold pages set by the policy > to free up the memory for more demanding jobs or scheduling new jobs. > > A user space proactive reclaimer is used in Google data centers. > Additionally, Meta's TMO paper recently referenced a very similar > interface used for user space proactive reclaim: > https://dl.acm.org/doi/pdf/10.1145/3503222.3507731 > > Benefits of a user space reclaimer: > ----------------------------------- > > 1) More flexible on who should be charged for the cpu of the memory > reclaim. For proactive reclaim, it makes more sense to be centralized. > > 2) More flexible on dedicating the resources (like cpu). The memory > overcommit controller can balance the cost between the cpu usage and > the memory reclaimed. > > 3) Provides a way to the applications to keep their LRUs sorted, so, > under memory pressure better reclaim candidates are selected. This also > gives more accurate and uptodate notion of working set for an > application. > > Why memory.high is not enough? > ------------------------------ > > - memory.high can be used to trigger reclaim in a memcg and can > potentially be used for proactive reclaim. > However there is a big downside in using memory.high. It can potentially > introduce high reclaim stalls in the target application as the > allocations from the processes or the threads of the application can hit > the temporary memory.high limit. > > - Userspace proactive reclaimers usually use feedback loops to decide > how much memory to proactively reclaim from a workload. The metrics > used for this are usually either refaults or PSI, and these metrics > will become messy if the application gets throttled by hitting the > high limit. > > - memory.high is a stateful interface, if the userspace proactive > reclaimer crashes for any reason while triggering reclaim it can leave > the application in a bad state. > > - If a workload is rapidly expanding, setting memory.high to proactively > reclaim memory can result in actually reclaiming more memory than > intended. > > The benefits of such interface and shortcomings of existing interface > were further discussed in this RFC thread: > https://lore.kernel.org/linux-mm/5df21376-7dd1-bf81-8414-32a73cea45dd@google.com/ > > Interface: > ---------- > > Introducing a very simple memcg interface 'echo 10M > memory.reclaim' to > trigger reclaim in the target memory cgroup. > > The interface is introduced as a nested-keyed file to allow for future > optional arguments to be easily added to configure the behavior of > reclaim. > > Possible Extensions: > -------------------- > > - This interface can be extended with an additional parameter or flags > to allow specifying one or more types of memory to reclaim from (e.g. > file, anon, ..). > > - The interface can also be extended with a node mask to reclaim from > specific nodes. This has use cases for reclaim-based demotion in memory > tiering systens. > > - A similar per-node interface can also be added to support proactive > reclaim and reclaim-based demotion in systems without memcg. > > - Add a timeout parameter to make it easier for user space to call the > interface without worrying about being blocked for an undefined amount > of time. > > For now, let's keep things simple by adding the basic functionality. > > [yosryahmed@google.com: refreshed to current master, updated commit > message based on recent discussions and use cases] > Signed-off-by: Shakeel Butt > Signed-off-by: Yosry Ahmed > Acked-by: Johannes Weiner > Acked-by: Michal Hocko > Acked-by: Wei Xu Acked-by: Roman Gushchin Thank you for incorporating all the feedback! Nice work!