Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8134807rwb; Wed, 23 Nov 2022 16:12:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf6jfKYkhBfvjXyPUq4pho5Yr6T/6eaiGKn23wWDzRDk7180DVbDW/Pr4VPQuF9Dub5zCNUj X-Received: by 2002:a05:6402:520a:b0:459:4c7b:e852 with SMTP id s10-20020a056402520a00b004594c7be852mr14931573edd.347.1669248770303; Wed, 23 Nov 2022 16:12:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669248770; cv=none; d=google.com; s=arc-20160816; b=EaAcNAHAA+fGE24OzJhdCezwJnFk6J3Y/PDn9NCoSlPUDKKhfLvHOVV16wRxpJgxAD 94g7J4RmoV4xOi19RwqdTyTKtAfUIE0pgRVMaqX8p1cb+H4FgnPfe5kOF75pJ3mQcL71 bgfFG0UpOmEuXIiAdjfd+ottIkl+hE3WSxKgdh4efPhirCCY6UZpvDEaDw+v7CSGSBN/ 7KMlhpwSqwdCbWiQxumFFK8B8YOl1b9NlDg31ih4KZQ2K2iV/4SMBDA3PmM2QNjOyh7J YdK+gs9ZwJ1NYWkAesa35mXfDaLBenuRrjN3NdUnUHom2iYNLeVd9ROs2fXwbJZNgtjn 0+Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=We3Y4AOZ212dC6RjyR8844fCrDkxjUuq7q5okkncMT8=; b=Et8d4lRc1TrGs0rbKuzvAWrZvB0uxDAi1QoBiMZv3Ew1aQK0K/uQWkkeTn+UxgWdPd 9P4O26JaUrx/7uToDYYeyBnoVLFjStoGYsbQy9IaoxAvUWklnnFG7x2CGUeuY8TBlacL wHf8cMnpEdW5UL+yHJkPsuoCZvycvrZgXAl4J7iSmJdh5/QXB3qRLXDiX2GELaCjZlfR 3ZVtFce8MSBX80LSadC9srzjh2UwcZZ2k+thl2O6McJ4CuVf18DsGilOsv0vr322VMwK DBiJZUEbEGXZqa2fuk6204gMuO6VmbiSbzphqEPFBkRsMjYmk7D2utGecPxB68HmCs1y n7SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=D3A4jBtc; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y20-20020a17090668d400b007ae165c79c8si3467127ejr.940.2022.11.23.16.12.29; Wed, 23 Nov 2022 16:12:50 -0800 (PST) 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=@google.com header.s=20210112 header.b=D3A4jBtc; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229978AbiKWXsf (ORCPT + 88 others); Wed, 23 Nov 2022 18:48:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbiKWXsd (ORCPT ); Wed, 23 Nov 2022 18:48:33 -0500 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48978623B0 for ; Wed, 23 Nov 2022 15:48:32 -0800 (PST) Received: by mail-io1-xd2d.google.com with SMTP id z3so241336iof.3 for ; Wed, 23 Nov 2022 15:48:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=We3Y4AOZ212dC6RjyR8844fCrDkxjUuq7q5okkncMT8=; b=D3A4jBtc/8G4S2epmN4p4OBwn93F+sxWYPAoCVbH/9mMsTOa3iNam1TtPGm/mDMZqw qycXacXDoml97DjlmC/gx5ZecVJyzeEZqJC0UhjN4h7m3dd2Pw3PH2Z/BhD1EfjDHSw0 /py9dp1lT1Lss7qS0ktvB5GO79cSzYxJNB22atbGbjS3/mSs3aga4jNzTp1XgcCwf5BB NMLH0au3WHG6WLbgiYYvOvIXbmWf4YFFHqSlbERVV8IWj++EORDDiK0RAevn4EywEG5W dmgDpYpIXg1kRUUoOyUNv/9VjvNwq26+nmylbg08OlADp1vrPqk45OuVdg3uq9DJ/UaQ T3OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=We3Y4AOZ212dC6RjyR8844fCrDkxjUuq7q5okkncMT8=; b=B1NPVPdDSGS+cG8KTQJ/Ywho35X7/uV/mtcDm9WZwS4NXHv+ZyUQ3M+whWfigdpw8I zOaihPyRezNUe6nub6nYYyP+p/2TCcDPV/hhdNyLj7TK8ysqHh2ePPFDdvB9pcsCmfya MhGL3lKwLDR2vuOYUQkrqsPl53WWA2Q5MTDB03f2IZePKVrKLj1qX3zUCuhQ92e8ppbW AlqisZsYPfrYG33Zk/5FCgqT34MMAcjC7ylnCdm2XhmPFIDPdf/zGRJzzhgv6039B1jr Zt93c0vGxW8MmiyqUL3aZIWKBFXas40VqsA/epxCRPs+JZAXT+j/pc156XaNM552S69y P5HQ== X-Gm-Message-State: ANoB5pk4bl+/cjMzC4JUyFYr2i3YKvgqWERNXlvbv39zf9scibyaUHEg 1+w5F3R8+6VCyl0pkftJzJUidluSJvn9y2RO2MH0eg== X-Received: by 2002:a6b:4409:0:b0:6de:bd7d:ee08 with SMTP id r9-20020a6b4409000000b006debd7dee08mr5396357ioa.0.1669247311479; Wed, 23 Nov 2022 15:48:31 -0800 (PST) MIME-Version: 1.0 References: <20221122203850.2765015-1-almasrymina@google.com> In-Reply-To: From: Yosry Ahmed Date: Wed, 23 Nov 2022 15:47:55 -0800 Message-ID: Subject: Re: [RFC PATCH V1] mm: Disable demotion from proactive reclaim To: Johannes Weiner Cc: Mina Almasry , Huang Ying , Yang Shi , Tim Chen , weixugc@google.com, shakeelb@google.com, gthelen@google.com, fvdl@google.com, Michal Hocko , Roman Gushchin , Muchun Song , Andrew Morton , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Wed, Nov 23, 2022 at 2:30 PM Johannes Weiner wrote: > > On Wed, Nov 23, 2022 at 01:35:13PM -0800, Yosry Ahmed wrote: > > On Wed, Nov 23, 2022 at 1:21 PM Mina Almasry wrote: > > > > > > On Wed, Nov 23, 2022 at 10:00 AM Johannes Weiner wrote: > > > > > > > > Hello Mina, > > > > > > > > On Tue, Nov 22, 2022 at 12:38:45PM -0800, Mina Almasry wrote: > > > > > Since commit 3f1509c57b1b ("Revert "mm/vmscan: never demote for memcg > > > > > reclaim""), the proactive reclaim interface memory.reclaim does both > > > > > reclaim and demotion. This is likely fine for us for latency critical > > > > > jobs where we would want to disable proactive reclaim entirely, and is > > > > > also fine for latency tolerant jobs where we would like to both > > > > > proactively reclaim and demote. > > > > > > > > > > However, for some latency tiers in the middle we would like to demote but > > > > > not reclaim. This is because reclaim and demotion incur different latency > > > > > costs to the jobs in the cgroup. Demoted memory would still be addressable > > > > > by the userspace at a higher latency, but reclaimed memory would need to > > > > > incur a pagefault. > > > > > > > > > > To address this, I propose having reclaim-only and demotion-only > > > > > mechanisms in the kernel. There are a couple possible > > > > > interfaces to carry this out I considered: > > > > > > > > > > 1. Disable demotion in the memory.reclaim interface and add a new > > > > > demotion interface (memory.demote). > > > > > 2. Extend memory.reclaim with a "demote=" flag to configure the demotion > > > > > behavior in the kernel like so: > > > > > - demote=0 would disable demotion from this call. > > > > > - demote=1 would allow the kernel to demote if it desires. > > > > > - demote=2 would only demote if possible but not attempt any > > > > > other form of reclaim. > > > > > > > > Unfortunately, our proactive reclaim stack currently relies on > > > > memory.reclaim doing both. It may not stay like that, but I'm a bit > > > > wary of changing user-visible semantics post-facto. > > > > > > > > In patch 2, you're adding a node interface to memory.demote. Can you > > > > add this to memory.reclaim instead? This would allow you to control > > > > demotion and reclaim independently as you please: if you call it on a > > > > node with demotion targets, it will demote; if you call it on a node > > > > without one, it'll reclaim. And current users will remain unaffected. > > > > > > Hello Johannes, thanks for taking a look! > > > > > > I can certainly add the "nodes=" arg to memory.reclaim and you're > > > right, that would help in bridging the gap. However, if I understand > > > the underlying code correctly, with only the nodes= arg the kernel > > > will indeed attempt demotion first, but the kernel will also merrily > > > fall back to reclaiming if it can't demote the full amount. I had > > > hoped to have the flexibility to protect latency sensitive jobs from > > > reclaim entirely while attempting to do demotion. > > > > > > There are probably ways to get around that in the userspace. I presume > > > the userspace can check if there is available memory on the node's > > > demotion targets, and if so, the kernel should demote-only. But I feel > > > that wouldn't be reliable as the demotion logic may change across > > > kernel versions. The userspace may think the kernel would demote but > > > instead demotion failed due to whatever heuristic introduced into the > > > new kernel version. > > > > > > The above is just one angle of the issue. Another angle (which Yosry > > > would care most about I think) is that at Google we call > > > memory.reclaim mainly when memory.current is too close to memory.max > > > and we expect the memory usage of the cgroup to drop as a result of a > > > success memory.reclaim call. I suspect once we take in commit > > > 3f1509c57b1b ("Revert "mm/vmscan: never demote for memcg reclaim""), > > > we would run into that regression, but I defer to Yosry here, he may > > > have a solution for that in mind already. > > > > We don't exactly rely on memory.current, but we do have a separate > > proactive reclaim policy today from demotion, and we do expect > > memory.reclaim to reclaim memory and not demote it. So it is important > > that we can control reclaim vs. demotion separately. Having > > memory.reclaim do demotions by default is not ideal for our current > > setup, so at least having a demote= argument to control it (no > > demotions, may demote, only demote) is needed. > > With a nodemask you should be able to only reclaim by specifying > terminal memory tiers that do that, and leave out higher tiers that > demote. > > That said, it would actually be nice if reclaim policy wouldn't have > to differ from demotion policy longer term. Ultimately it comes down > to mapping age to memory tier, right? Such that hot pages are in RAM, > warm pages are in CXL, cold pages are in storage. If you apply equal > presure on all tiers, it's access frequency that should determine > which RAM pages to demote, and which CXL pages to reclaim. If RAM > pages are hot and refuse demotion, and CXL pages are cold in > comparison, CXL should clear out. If RAM pages are warm, they should > get demoted to CXL but not reclaimed further from there (and rotate > instead). > > Do we know what's preventing this from happening today? What's the > reason you want to control them independently? The motivation was giving user space more flexibility to design their policies. However, as you point out, the current behavior of falling back to reclaiming when we cannot demote is not ideal, and maybe we should not design policies around it. We can always revisit this if a use case arises where a clear distinction needs to be drawn between reclaiming and demotion policies.