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 AA555C433F5 for ; Wed, 5 Oct 2022 19:49:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E85A76B0072; Wed, 5 Oct 2022 15:49:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E34E86B0073; Wed, 5 Oct 2022 15:49:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD8546B0074; Wed, 5 Oct 2022 15:49:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id BD5326B0072 for ; Wed, 5 Oct 2022 15:49:50 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7678D805AB for ; Wed, 5 Oct 2022 19:49:50 +0000 (UTC) X-FDA: 79987936140.24.05E93C1 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf05.hostedemail.com (Postfix) with ESMTP id E8DF810001A for ; Wed, 5 Oct 2022 19:49:49 +0000 (UTC) Received: by mail-qk1-f170.google.com with SMTP id t7so293506qkt.10 for ; Wed, 05 Oct 2022 12:49:49 -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=KTsXqBLMJ7z5zDaMVeB3mFtjBOaAR2nLT0zyd4+BXeg=; b=rL48SW7QvdXgLHL74fCHo4SV8KfIpBhdqZiIQkFNh26QO0TTK/n2jD7rLs5fjZNgXX yqzl+73lIDTO9Wo+L+sKEUh5VTyKcrOARmxgyzCkLnBzZGOYGKz1LMCzJrk8y5VEvrXl SL9TmligGaKXnhQ7moybwxP0quMm54chKS1ExXoghqPYamj7omGSHq8jkHq0MYM5geLn 7RLi84RADnmvjggV2xnJHWsRaTXaqRCHbsd+hBNFTax2A3pXm2Lxz0alAp1GkgBPI9f6 phptnuyHdseoFF1K7kCZfEqfVIJxshHn4QPHCyLp5ZcLGdzlRzgkd9J+CROfJfxgtMrv 7s2w== 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=KTsXqBLMJ7z5zDaMVeB3mFtjBOaAR2nLT0zyd4+BXeg=; b=cjMeRIvtXS2xZRuF3/1f8+9ounYveQV2Ytzw4b8UuI8zgROcjuds9NJYAhoAX4qwXn cUtR9wqUgeF1VGUOr7gXOIFGVTJRaBdLVB3+UbBY/s/dl3XM5x08BF/st7NgvyBh+DTO yl/hnwuVk1lo6BwzfXUv7nxu9I8S+NmP1S0CYbPCsEqu6PvyCVBh7o+dipIDGlsGV4YX ylaqaunF579TsffBp27+xz2qTjTeSAqBZJA990z2wIGT5SMiYBqcLNPh03Hn5hqSJ4vk Kf3ePsxWv3DkG3WmDy/fiY5c5qyKYrMgT3wXddJRvu1Az5EG7NfWfYcmPnW7cQWKtSOW hB7Q== X-Gm-Message-State: ACrzQf0Z7TwWYziW1wQpDTFTLmyOCnKfXqvkOlBwTfJpq/kCTv6EuOTR mBMwT0W+liYT71o9GQDvJ/dxuQ== X-Google-Smtp-Source: AMsMyM64bYzTh2coBvcK6ApYP5+mCCGuTVoNmZIhCeEBPxWh6+64BAKzJyw6Jm+z60lU7vZXu19vSw== X-Received: by 2002:a05:620a:16cf:b0:6ce:4b65:db21 with SMTP id a15-20020a05620a16cf00b006ce4b65db21mr854017qkn.544.1664999389066; Wed, 05 Oct 2022 12:49:49 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::8a16]) by smtp.gmail.com with ESMTPSA id j3-20020a05620a410300b006b5bf5d45casm18608327qko.27.2022.10.05.12.49.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 12:49:48 -0700 (PDT) Date: Wed, 5 Oct 2022 15:49:47 -0400 From: Johannes Weiner To: Yosry Ahmed Cc: Andrew Morton , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Greg Thelen , David Rientjes , cgroups@vger.kernel.org, linux-mm@kvack.org 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: <20221005173713.1308832-1-yosryahmed@google.com> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664999390; 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=KTsXqBLMJ7z5zDaMVeB3mFtjBOaAR2nLT0zyd4+BXeg=; b=kFX0BeTeop953gV8g/h9YIZRgDuCASJ2+X6OysaCT08v3TK56vCMpr1C44liiWbL2m3Ldk A61hzvtYmxcruwRb8Yw5aidNdjY8ddR1oiriJMox06qZTzWK5k4fItmHItXAuHgRMDG5st dYZnafO12tQBBGdTI9JunbcI/X0VSFk= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=rL48SW7Q; spf=pass (imf05.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.170 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=1664999390; a=rsa-sha256; cv=none; b=N5JV9WxvK2c2Q7ACUE87WO3jH856ll+tOpIPPTGach+PG4hcLpxuXsmfFkDAMYA83sF2yI 8jewnYTFKvirGqXjV8g0HyJdm0B8GA4p39mjIfJMLP2o1J+VRhj7/CMnmFr4ZDAu6N3IRL 9LWGbYhAywY4/str3DrEMqK9VJadwpE= X-Rspamd-Queue-Id: E8DF810001A Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=rL48SW7Q; spf=pass (imf05.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.170 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org X-Rspamd-Server: rspam06 X-Rspam-User: X-Stat-Signature: rqc6m6ttz67ds7jwnw77damq96oja57w X-HE-Tag: 1664999389-385089 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 05:37:13PM +0000, 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. > > Signed-off-by: Yosry Ahmed Acked-by: Johannes Weiner