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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0617FC433F5 for ; Thu, 6 Oct 2022 15:38:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84B308E0001; Thu, 6 Oct 2022 11:38:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D3516B0073; Thu, 6 Oct 2022 11:38:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 625818E0001; Thu, 6 Oct 2022 11:38:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 462B66B0072 for ; Thu, 6 Oct 2022 11:38:27 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DF14716026C for ; Thu, 6 Oct 2022 15:38:26 +0000 (UTC) X-FDA: 79990931412.05.BF14A9A Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) by imf23.hostedemail.com (Postfix) with ESMTP id 491D3140028 for ; Thu, 6 Oct 2022 15:38:26 +0000 (UTC) Received: by mail-qv1-f52.google.com with SMTP id df9so1391321qvb.9 for ; Thu, 06 Oct 2022 08:38:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Y7iXEKlC7ORkC5fIeVI8VUWR9YmQGA/IC0j91wyTvOo=; b=Ibn8EfDwMvxYMsRoVhxKHuyL+MtidtjMV4enUQTaLRlqQyD9+02pjXr458YQB1HQd0 itgKq2OGEHMvH8G0c/aJnF755R4oOgYSTbIrMs6P7zNYjTln/UbfVtKP5BAeSQIhSHEY jeKIyeR596uaOwAewNRxVngJWDmOoZ2m2KOlTpfLgO82ozmEI2HyrqFkTHq9AL6CyPK+ 7q35D7vTKhHa28c1NamTL5YqEt1t4lUZShD/uV2M4KI9BRWIdjifaNzHqqK2u8TThMk1 dGEKx51g0cQYI1/Os5WIQw8ntMgg4o2S9GCyqu4xQd4ho2GTPYT0TTzH6gY+LgR6xMYA zJsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Y7iXEKlC7ORkC5fIeVI8VUWR9YmQGA/IC0j91wyTvOo=; b=NCf9AcnSp8KUSr3hhvgsOpFNuK8gt9xeJ58RmGgwpa80UeZ5KNqU1bOKp2kF0eEN8R 0pavyjHlnQxuGqNLf4XBdOBvTG4SAMyhfkvy0H9wj0Wg603wRm71dwVD9UdFskDGwTNM XMnbdfaXAeQ3DGSHuGE4I/SctfrQCo5XdOLg9bBqY0d5s4T+aYwWIdnhwNoUnYMAjG71 xfbwvnNq8NihdH+5nHYEtfcVwprXyjADFL3qxpit1YqbH+WEwkpLxkZaSSNDVFeCRgq5 Cfge4U78ZkgLZaBBdo+F8KaLBrbNsy1h8OaC2y1m/keE8nU9v9p1mLcGEynUpFqxCeZV jr6Q== X-Gm-Message-State: ACrzQf3M/d0w3S4rDhOdPOFZpHmGXmBh8hcviPkQDxJ4dATb6A3tV3Rg JEI4eb/QK+jKkuxh/TEF+KSLcQ== X-Google-Smtp-Source: AMsMyM56LtWrM8IQa7LsdUejJGh7UboSwXWgtDOhbFWVuzHshqi7IZcwV2wzUzdG+TJCfmusPg42nw== X-Received: by 2002:a0c:e552:0:b0:4b1:86f0:89d5 with SMTP id n18-20020a0ce552000000b004b186f089d5mr217218qvm.97.1665070705379; Thu, 06 Oct 2022 08:38:25 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::8a16]) by smtp.gmail.com with ESMTPSA id v19-20020a05622a131300b0031e9ab4e4cesm18027419qtk.26.2022.10.06.08.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 08:38:24 -0700 (PDT) Date: Thu, 6 Oct 2022 11:38:23 -0400 From: Johannes Weiner To: Yu Zhao Cc: Yosry Ahmed , Andrew Morton , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Greg Thelen , David Rientjes , Cgroups , Linux-MM Subject: Re: [PATCH v2] mm/vmscan: check references from all memcgs for swapbacked memory Message-ID: References: <20221005173713.1308832-1-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665070706; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Y7iXEKlC7ORkC5fIeVI8VUWR9YmQGA/IC0j91wyTvOo=; b=d+8WXB1Xh6bgYli97RZqL9+G2PAKssyqWoEoBFpwoz6Nkkb44X8pgTsfBG+e7SnJdVaDPM uEdIYXdLcIHoZ5BJ9CcjfYGj1kEgSz9rHqe1dLh2PvqqBM68I5seAoWJuYdhgMWrMdax1P 0lOFWD7EtjaBGvKp42hQjWFL/fp7Zkw= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=Ibn8EfDw; spf=pass (imf23.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.52 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665070706; a=rsa-sha256; cv=none; b=dFRdWdyDj1KIfN9UQboLaTGA2HLvLBxQa9ensfsXOCwOgQP+UJ7rS9oD2at8FNDpFM/8Co 7CVOrMoow3ihioRsVfOcKURwjxJUR1yNbLC4RKBlLfbDvVxZdM2jVilT0jIsvQPopluiKo FISuvvc9Z/nSB8/JPzaU1O7MJbi2+Lk= X-Stat-Signature: nysi9ymg18s78ibatqhnoiuftpibjhn7 X-Rspamd-Queue-Id: 491D3140028 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=Ibn8EfDw; spf=pass (imf23.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.52 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org X-Rspamd-Server: rspam07 X-Rspam-User: X-HE-Tag: 1665070706-883433 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Oct 05, 2022 at 11:10:37PM -0600, Yu Zhao wrote: > On Wed, Oct 5, 2022 at 10:19 PM Johannes Weiner wrote: > > > > On Wed, Oct 05, 2022 at 03:13:38PM -0600, Yu Zhao wrote: > > > On Wed, Oct 5, 2022 at 3:02 PM Yosry Ahmed wrote: > > > > > > > > On Wed, Oct 5, 2022 at 1:48 PM Yu Zhao wrote: > > > > > > > > > > On Wed, Oct 5, 2022 at 11:37 AM Yosry Ahmed wrote: > > > > > > > > > > > > During page/folio reclaim, we check if a folio is referenced using > > > > > > folio_referenced() to avoid reclaiming folios that have been recently > > > > > > accessed (hot memory). The rationale is that this memory is likely to be > > > > > > accessed soon, and hence reclaiming it will cause a refault. > > > > > > > > > > > > For memcg reclaim, we currently only check accesses to the folio from > > > > > > processes in the subtree of the target memcg. This behavior was > > > > > > originally introduced by commit bed7161a519a ("Memory controller: make > > > > > > page_referenced() cgroup aware") a long time ago. Back then, refaulted > > > > > > pages would get charged to the memcg of the process that was faulting them > > > > > > in. It made sense to only consider accesses coming from processes in the > > > > > > subtree of target_mem_cgroup. If a page was charged to memcg A but only > > > > > > being accessed by a sibling memcg B, we would reclaim it if memcg A is > > > > > > is the reclaim target. memcg B can then fault it back in and get charged > > > > > > for it appropriately. > > > > > > > > > > > > Today, this behavior still makes sense for file pages. However, unlike > > > > > > file pages, when swapbacked pages are refaulted they are charged to the > > > > > > memcg that was originally charged for them during swapping out. Which > > > > > > means that if a swapbacked page is charged to memcg A but only used by > > > > > > memcg B, and we reclaim it from memcg A, it would simply be faulted back > > > > > > in and charged again to memcg A once memcg B accesses it. In that sense, > > > > > > accesses from all memcgs matter equally when considering if a swapbacked > > > > > > page/folio is a viable reclaim target. > > > > > > > > > > > > Modify folio_referenced() to always consider accesses from all memcgs if > > > > > > the folio is swapbacked. > > > > > > > > > > It seems to me this change can potentially increase the number of > > > > > zombie memcgs. Any risk assessment done on this? > > > > > > > > Do you mind elaborating the case(s) where this could happen? Is this > > > > the cgroup v1 case in mem_cgroup_swapout() where we are reclaiming > > > > from a zombie memcg and swapping out would let us move the charge to > > > > the parent? > > > > > > The scenario is quite straightforward: for a page charged to memcg A > > > and also actively used by memcg B, if we don't ignore the access from > > > memcg B, we won't be able to reclaim it after memcg A is deleted. > > > > This patch changes the behavior of limit-induced reclaim. There is no > > limit reclaim on A after it's been deleted. And parental/global > > reclaim has always recognized outside references. > > We use memory.reclaim to scrape memcgs right before rmdir so that they > are unlikely to stick around. Otherwise our job scheduler would see > less available memory and become less eager to increase load. This in > turn reduces the chance of global reclaim, and deleted memcgs would > stick around even longer. Thanks for the context. It's not great that we have to design reclaim policy around this implementation detail of past-EOF-pins. But such is life until we get rid of them.