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 8C724C433F5 for ; Wed, 5 Oct 2022 15:51:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 095B66B0072; Wed, 5 Oct 2022 11:51:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 044F16B0073; Wed, 5 Oct 2022 11:51:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E27E76B0074; Wed, 5 Oct 2022 11:51:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CE14A6B0072 for ; Wed, 5 Oct 2022 11:51:33 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8E6B6160B1C for ; Wed, 5 Oct 2022 15:51:33 +0000 (UTC) X-FDA: 79987335666.09.CE8F451 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by imf21.hostedemail.com (Postfix) with ESMTP id DE19E1C000F for ; Wed, 5 Oct 2022 15:51:32 +0000 (UTC) Received: by mail-qk1-f176.google.com with SMTP id g2so10431397qkk.1 for ; Wed, 05 Oct 2022 08:51:32 -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; bh=2AoFrEpz0B0RLbXAkzCCAczpNqzFmtnMjKTlufu6KsU=; b=WRGwEQZ1TNdFoAuwtXbuWLZNv41BDB32f4pY76uWbOKjuF0h37pCQt+Pwgr6xs+N2t D3Ce0vY+MNtiBU0bi16rH7EAwk2rwH6/Y9fr/aocmu4c85nzeYy8GCFbknxL3K4+qEzd 40IHJJuCITJXg9IsZmrkfcNRrfq2hWvPKTqK1YMX7Gb+hQUx5Q+z0BrtPgGU0BY54P94 gtlky2y6FXCCcmbRO3gE9nBlrZKwEMydG9XtAdUUXiytwyVJ7hjOOqF+itedleWm94fc 6aO36P0obqVLPwdYQkOJWbILzVJApg/HncfimKv9PUP2TTW2yVhWp+7bArcfWYq5JqDG nJ7w== 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; bh=2AoFrEpz0B0RLbXAkzCCAczpNqzFmtnMjKTlufu6KsU=; b=HA0IhHrE3H3isTIN/eA6nl2fzL6ETOub1VmxuCVDYIKRso5OI+20TuJr8eDHKyMc3j V8/iL/zv1y1tYnYZLAIjs77S3Ph1lQhXos5lTOtnAykwSHom4DSzVB8nhVns7u8WNTx+ 6CkDsK96U1+cCeZVZtKQRHVr5Yg5bF1pl9Zq7fW7QrlFAgHE1dfSKwpPaFgZUHgqREnA aMcLkMEp58wHg3E+nfa3+iYF3cTCk3fQl7S5P1gjosPE+oLGcHNHIBuKD/zYDfioPBbQ syvxltIU2Q+cmYpI+YvHT+hRm17CPY78tAIsHP1dmUIc3tlchTfpIm2kk4hF8aLSGiKD 8aZw== X-Gm-Message-State: ACrzQf0LhJZtHUzm/Mhx4nmLaVEmULUZ3FOpbw44IO6hQ61qrJCe7cft zq+np8svWklogRb6x2smqjXUng== X-Google-Smtp-Source: AMsMyM7kmrmQrnGNoUSK6tL7NkzT6Khbjks9LTKhC6g2EqFLqq5KoRDn+0j2GktmAwhMFEVPJPjy9w== X-Received: by 2002:a05:620a:2005:b0:6ce:3f31:e02d with SMTP id c5-20020a05620a200500b006ce3f31e02dmr161084qka.678.1664985092121; Wed, 05 Oct 2022 08:51:32 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::8a16]) by smtp.gmail.com with ESMTPSA id g12-20020a05620a40cc00b006ce3f1af120sm8869688qko.44.2022.10.05.08.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 08:51:31 -0700 (PDT) Date: Wed, 5 Oct 2022 11:51:30 -0400 From: Johannes Weiner To: Yosry Ahmed Cc: Andrew Morton , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Greg Thelen , David Rientjes , Cgroups , Linux-MM Subject: Re: [PATCH] mm/vmscan: check references from all memcgs for swapbacked memory Message-ID: References: <20221004233446.787056-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=1664985093; 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=2AoFrEpz0B0RLbXAkzCCAczpNqzFmtnMjKTlufu6KsU=; b=CKw6tjzbrUxudrw8VauEBnEHsZvO4A7GoQ4nl28/ko/pTRLyJw/qczB3x+cUFm8BvMrFSp T4zoEcxh8FnkRNCmYWeh/Nmmh1O7T+XVn54lCt/FyBMz7TLQeDBFe2FxCPAxUmRG9Vyun5 GAOfcBaEIqrfZTW6KcsfASMEUD4v8ec= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=WRGwEQZ1; spf=pass (imf21.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.176 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=1664985093; a=rsa-sha256; cv=none; b=15atQepyhZpsLol1SXlHXwtFwmUcE10L+pbRajShGizmwNsekvIAuQbn5Q63htCR63627s BDOr3GmVUpu1YJ9NShDkHIhb34wwRkd5HxK8R7fLCHLMDJ9P2c3TrwYx+WiYAC4NtN7E6h o8u6CxTHMOMcwUcpuMMN0CExsjp7Ubc= X-Stat-Signature: ooemc8zwepn49yoj75e1fszoeqt3nt5i X-Rspamd-Queue-Id: DE19E1C000F Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=WRGwEQZ1; spf=pass (imf21.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.176 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: 1664985092-479780 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 07:54:25AM -0700, Yosry Ahmed wrote: > On Wed, Oct 5, 2022 at 7:04 AM Johannes Weiner wrote: > > Would you mind moving this to folio_referenced() directly? There is > > already a comment and branch in there that IMO would extend quite > > naturally to cover the new exception: > > > > /* > > * If we are reclaiming on behalf of a cgroup, skip > > * counting on behalf of references from different > > * cgroups > > */ > > if (memcg) { > > rwc.invalid_vma = invalid_folio_referenced_vma; > > } > > > > That would keep the decision-making and doc in one place. > > Hi Johannes, > > Thanks for taking a look! > > I originally wanted to make the change in folio_referenced(). My only > concern was that it wouldn't be clear for people looking at reclaim > code in mm/vmscan.c. It would appear as if we are passing in the > target memcg to folio_referenced(), and only if you look within you > would realize that sometimes it ignores the passed memcg. > > It seemed to me that deciding whether we want to check references from > one memcg or all of them is a reclaim decision, while > folio_referenced() is just an rmap API that does what it is told: "if > I am passed a memcg, I only look at references coming from this > memcg". On the other hand, it looks like the doc has always lived in > folio_referenced()/page_referenced(), so I might be overthinking this > (I have been known to do this). I agree it would be nicer to have this policy in vmscan.c. OTOH it's a policy that applies to all folio_referenced() callers, and it's fragile to require them to opt into it individually. Vmscan is the only user of the function, so it's not the worst thing to treat it as an extension of the reclaim code. If it helps convince you, there is another, actually quite similar reclaim policy already encoded in folio_referenced(): if (ptep_clear_flush_young_notify(vma, address, pvmw.pte)) { /* * Don't treat a reference through * a sequentially read mapping as such. * If the folio has been used in another mapping, * we will catch it; if this other mapping is * already gone, the unmap path will have set * the referenced flag or activated the folio. */ if (likely(!(vma->vm_flags & VM_SEQ_READ))) referenced++; }