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 EF1A0C433FE for ; Wed, 5 Oct 2022 15:56:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48AA56B0072; Wed, 5 Oct 2022 11:56:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 412EE6B0073; Wed, 5 Oct 2022 11:56:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 264996B0074; Wed, 5 Oct 2022 11:56:11 -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 0DA6C6B0072 for ; Wed, 5 Oct 2022 11:56:11 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AF5C71602DB for ; Wed, 5 Oct 2022 15:56:10 +0000 (UTC) X-FDA: 79987347300.05.F70D56C Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by imf24.hostedemail.com (Postfix) with ESMTP id C2E1618001E for ; Wed, 5 Oct 2022 15:56:09 +0000 (UTC) Received: by mail-wm1-f41.google.com with SMTP id r3-20020a05600c35c300b003b4b5f6c6bdso1282116wmq.2 for ; Wed, 05 Oct 2022 08:56:09 -0700 (PDT) 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; bh=7a/LoYvpCfoolYwQAKh6JCAxVB7pDgsUOT/7iK/WTWA=; b=oatM/DuzZqdzxPdmhesMOJTCOHkKQGc14RUqIgdihrzrd6CfHIa6r3nXHN+2iKe9vp OpQRH9oRNrvvfa/zRsB+qWD7adGbskLl31VKTezR6LLg0nXT4E+A38BspZ5G28RYbjAY YEknG8XvaPZVXP9b7yZWVEH9n/QH2kV6NNeZ7r23NalWKjpkqnkC0hGd2qk1A4LGcI8H cipvVTQP2t4nhsfBCwM/xQqdfgR+2y3CskyIfMkGozej8NdY/6qtdpXGosCcGYrTkds/ a+NTULObkeiYlG3d3ptMyOijxKdy1su6oiVirLzBOhKN5aQj1mBQapv9WNEd1Ent93l9 vd2g== 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; bh=7a/LoYvpCfoolYwQAKh6JCAxVB7pDgsUOT/7iK/WTWA=; b=rDCRT9SrFTf01ZyJNgev29wgGO9CBi7W4j8AlRFYWcsm4SzPByFoF+2MzZgAJwkNaw oKdzPILCxyOyCMZwYc1Jti7Yj0UGpqh7sG2UjXQtr2f2+wC3HByNZ7UrsUsFrkdfbLug v/rCD4NcrrIOD49tsD8i7EtJPViJHhV9fQDqgZli0grmW1v/m2Jhudts8532pYDK5dJY L8PRdATrV/SrTfkKlghtUia45Vm57YDqMcmFgORLj1dL+z97BuDsLTDcp5StI2H4tRSW qLcT//DAba0HBrpoD+V5eRkh2pufdH/BDTMo2mQ1NXyN2wCXuG3lsNV/u4blX7QiXEWN ZTHw== X-Gm-Message-State: ACrzQf3FutBIvUPxKBMg0e1QUyADMF5LMlnTAAtwR/xKc95vIajh7uhd 5U6xrEhR9VD32jzf3bajMt6cDiyB4gBfIpm/VFKQ7g== X-Google-Smtp-Source: AMsMyM4NzpApVCSaeSrqVfB0BIHl7CGUiDtHyAfG/+pwqTtYM8YfYREzw1B3JoiHg4VRqpRqwJ4ihZLf4SQ9abKcq28= X-Received: by 2002:a7b:ce97:0:b0:3b3:4136:59fe with SMTP id q23-20020a7bce97000000b003b3413659femr199314wmj.24.1664985368254; Wed, 05 Oct 2022 08:56:08 -0700 (PDT) MIME-Version: 1.0 References: <20221004233446.787056-1-yosryahmed@google.com> In-Reply-To: From: Yosry Ahmed Date: Wed, 5 Oct 2022 08:55:31 -0700 Message-ID: Subject: Re: [PATCH] mm/vmscan: check references from all memcgs for swapbacked memory To: Johannes Weiner Cc: Andrew Morton , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Greg Thelen , David Rientjes , Cgroups , Linux-MM Content-Type: text/plain; charset="UTF-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664985369; 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=7a/LoYvpCfoolYwQAKh6JCAxVB7pDgsUOT/7iK/WTWA=; b=4GriI5EmWjFRRfV6iYdtWllJD2jjeKjKdYMj+1Bi1uTA6O51TtGIILzstSsZd/1FOp1Myf 2S50ogptc3ftcWESjXrkslGXuQyoZUskUCTnNVdCX05YsDfibp4uqvmkJRfZQqeaGLm1fB /OfGjE+MBh8xbEg1EBdyeVKvO8k+2FU= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="oatM/Duz"; spf=pass (imf24.hostedemail.com: domain of yosryahmed@google.com designates 209.85.128.41 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664985369; a=rsa-sha256; cv=none; b=2BTM1UUDjJ71nJvmXUB7hjcHKPfG5bWLyrXwgnP0pkD2UqWePA5nf5IZnRkL9+FWlKSzmk 4aX4jvV94HKAMJoQCE1T10iVmJfRETKZs3/LUcJFOlA3//LOW+xD53CmrIy2CfQ1kDMA5J vkPqrLG3HLWgIOvQXJIDjudvJc7IUz0= X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="oatM/Duz"; spf=pass (imf24.hostedemail.com: domain of yosryahmed@google.com designates 209.85.128.41 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: gpz5bq36cmoj95ef69sxa6zppwnfffx6 X-Rspamd-Queue-Id: C2E1618001E X-Rspamd-Server: rspam02 X-HE-Tag: 1664985369-789195 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 5, 2022 at 8:51 AM Johannes Weiner wrote: > > 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++; > } Thanks for clarifying. Will send v2 later today :)