From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD980C433F5 for ; Thu, 31 Mar 2022 19:25:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240640AbiCaT1G (ORCPT ); Thu, 31 Mar 2022 15:27:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234433AbiCaT1D (ORCPT ); Thu, 31 Mar 2022 15:27:03 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37CDFDFFB8 for ; Thu, 31 Mar 2022 12:25:14 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id 1so393614qke.1 for ; Thu, 31 Mar 2022 12:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=vyEyFUKqryt9zBzJe2Z7xpXuyc7SpWk9id19kGwXgKM=; b=mEMZuaiSHC0FBEUUP25G6KwZkLY4fMTbC8nkggOHXCQ/rM2A8QlY/nhB4znsxN8X9w 0jeQiv+bQGLWX0qeKRehzPVnXaW+Q8ZCCepBvbNi3xIV8pEDnpbycgEhOGONjdxalGsx 9pYzWnpcjILDPK/VxTHTnMbiOIl/m/ZDNCyBhP+rCo6pD7FSWUgRr9B1F2mzbadBoEOq MENdNcglup1LzOJdJaWye2ZZlN3INJM9XB+m7+M5ya+XfHYGoDkDEbbJ6rdk+qi8Z+lS yUX/W/uL/945ytaEli3+xdaOUNHQdReLI2rZXgPFC7SQ7uLSX4in12E1YEzscjaqpQdU ZyDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=vyEyFUKqryt9zBzJe2Z7xpXuyc7SpWk9id19kGwXgKM=; b=AViUHxQFWLWNi8IlFyAMzOQyV58381nVpJQwaDIPqOpD+S9vkxki1c5vSgcXNk+A/h eG3w6lCOtJxH04OA6ClYec7LtlkHLeabwlhO+P/QARvSjgdCWexyeOtb7q3HseCiUiur nKjZzx/xUxZaja2KCWJ0GpfTh4OPnxnDv8mmOmbjoK4HhYCerRdoyy48MKNLsFUt8icp f/n8hCtRAo/I+K+f1ljAWlO/ZI9kTQhNwapGd3Ykx1qd42rjV8qTcuYICitWwOil7MI9 gMtCw8oZubi1hgoE7O0BeBvMZTqRVEn7hTmeJ0DvwOII4K+zpJibQk0r9nKa+b3mLOws eINQ== X-Gm-Message-State: AOAM5311rutozp0U5HcPGJwg3rYras5t7XDAY4/9oHvGgn6iP+9rpmr2 BUPs9tiEBgTiOSSTlrfwuGYcAg== X-Google-Smtp-Source: ABdhPJyzPs3CSu4BAynvB5YsY/AnOTZRmDgsGtbExxW+CfN83047fy7Y8GbQcqNJxNI7NWzQ7xeS0g== X-Received: by 2002:a37:c20b:0:b0:67b:3585:4687 with SMTP id i11-20020a37c20b000000b0067b35854687mr4363466qkm.280.1648754712603; Thu, 31 Mar 2022 12:25:12 -0700 (PDT) Received: from localhost (cpe-98-15-154-102.hvc.res.rr.com. [98.15.154.102]) by smtp.gmail.com with ESMTPSA id v3-20020a05622a014300b002e1dcd4cfa9sm173876qtw.64.2022.03.31.12.25.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 12:25:12 -0700 (PDT) Date: Thu, 31 Mar 2022 15:25:11 -0400 From: Johannes Weiner To: Yosry Ahmed Cc: Michal Hocko , Shakeel Butt , Andrew Morton , David Rientjes , Tejun Heo , Zefan Li , Roman Gushchin , cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Jonathan Corbet , Yu Zhao , Dave Hansen , Wei Xu , Greg Thelen Subject: Re: [PATCH resend] memcg: introduce per-memcg reclaim interface Message-ID: References: <20220331084151.2600229-1-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220331084151.2600229-1-yosryahmed@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 31, 2022 at 08:41:51AM +0000, Yosry Ahmed wrote: > From: Shakeel Butt > > Introduce an 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. > > > 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. > > 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 Thanks for compiling all the history and arguments around this change!