From patchwork Fri Mar 31 07:08:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13195318 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 7CE61C77B62 for ; Fri, 31 Mar 2023 07:08:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13D9E6B007D; Fri, 31 Mar 2023 03:08:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0ED926B007E; Fri, 31 Mar 2023 03:08:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E35F36B0080; Fri, 31 Mar 2023 03:08:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C1B1D6B007D for ; Fri, 31 Mar 2023 03:08:29 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8B7ED803AE for ; Fri, 31 Mar 2023 07:08:29 +0000 (UTC) X-FDA: 80628315138.13.1FB5EC7 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf13.hostedemail.com (Postfix) with ESMTP id A802C2000E for ; Fri, 31 Mar 2023 07:08:27 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=I416KE3j; spf=pass (imf13.hostedemail.com: domain of 36oYmZAoKCLkxnrqxZgldcfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=36oYmZAoKCLkxnrqxZgldcfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680246507; 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=h76ftpfDeW349+865+C5AwRuwTE+LoTxu1YkhFCOpyA=; b=R7vIK+lMnzUb0AFylqbH9EaRQ7+NDbJMGv2vfN6hs1AeLaMQ65dQBeBD+/+su85iKgWjm8 3VBCT1CuN3hbi3u+6rjT2lyj+A/4zZ4Ga6U96fYtoNWAREcpBTsIcf0kdauyofQ0WLcpT5 2irsps1csgqIXmYyUMLGfbfJNF67QEM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=I416KE3j; spf=pass (imf13.hostedemail.com: domain of 36oYmZAoKCLkxnrqxZgldcfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=36oYmZAoKCLkxnrqxZgldcfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680246507; a=rsa-sha256; cv=none; b=wpG4y7wlpN4rQ+q7oGNIxn5Zu7/5RUoA96MxM0Y/wwu272wQUKadalUzizVtwt3mApwWMW Y0AB8IO5ulQme8wV+CBtVNzceV8NBbL2GZ/aM3YpSOiN0qb4laiN9J1guz4kQPmExLqFqb mcvZGDv4jHHQxZVAhpEjRHLFEVG2HbQ= Received: by mail-yb1-f201.google.com with SMTP id i11-20020a256d0b000000b0086349255277so21216205ybc.8 for ; Fri, 31 Mar 2023 00:08:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680246507; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=h76ftpfDeW349+865+C5AwRuwTE+LoTxu1YkhFCOpyA=; b=I416KE3jHWRA3QMCGUkW1ivXoY9bfwY9Wzs6ajryoP118g2lYRPUBdBs95KIolJuD5 Ethf/48kB/t99e0lZyDxt6Gzswbs6SgDsOW6Io3pxcCrt46SeVq6PdqDGwpRXRm4mIIO 6/7VlzMrDBNDNFPKTqzatAKxYD7Ykdp+wnADaTixMb98ZnvPZpzngRlNsTbR1eAqMGin OVVTVCUinbAA7DzoMhdK0NIZtCVKH1xuFjJniN2MkWrVvFG9yuSRV9r8Ey4Yt6n+qENf XWcPXE7St5/tC16GieQD7BtKre3OtF+VNgjQao02pAU8vmXwS+dEsHk1Tc7dr9q0a6L7 3Wbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680246507; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=h76ftpfDeW349+865+C5AwRuwTE+LoTxu1YkhFCOpyA=; b=qX/PQwsrxe022awQ9wDM6wtSyDyIzMS5KD/2d/oGUrwNZ6wD/Pr0DSMC4nsTAQ7JWG +QCtrEHlKrgg7J5nGkNrxIEyiUrf7Zcq55DGzLjb7PoD9NIkohwPhXAyepqa4mqx8YDb gKUjBtwsJWDXMrCUmnmt/FOlYcfPKondxg+J6FYD7Y67rHrA2vypvZQ54B8gPHl2p5kI ckQDuMCRIvr7Tdc72c7DRPhVvzt3ko5AmRWC7UdPu6LkGA5hbl7qOWchCIPPR1qgzn23 sQEHC+yxFMcWfVCZUulsLZriS1HhKl9WGgCCDjddin0bxhxZty+84Vh4Ofo+E7DukEPf kr0A== X-Gm-Message-State: AAQBX9et2vLUdB9HENPcjnbF5c0USF8YeV4FqF5BK9h5nsGMHfTAZX5d CUXC/Gp/x2WegqhzzX8Fw/P+WwT+T9Dhly8O X-Google-Smtp-Source: AKy350Y8WGtJv5wxaytzfKnKlxt10iAfzKZBoBbyFn4WF437gd6aXmlYDb8KK6m+3I5auaqd4e3K7Ex+rHzIvu5H X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a81:b617:0:b0:541:7f69:aa8b with SMTP id u23-20020a81b617000000b005417f69aa8bmr12492986ywh.5.1680246506838; Fri, 31 Mar 2023 00:08:26 -0700 (PDT) Date: Fri, 31 Mar 2023 07:08:18 +0000 In-Reply-To: <20230331070818.2792558-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230331070818.2792558-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230331070818.2792558-4-yosryahmed@google.com> Subject: [PATCH v3 3/3] mm: vmscan: ignore non-LRU-based reclaim in memcg reclaim From: Yosry Ahmed To: Andrew Morton , Alexander Viro , "Darrick J. Wong" , Christoph Lameter , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, "Matthew Wilcox (Oracle)" , Miaohe Lin , David Hildenbrand , Johannes Weiner , Peter Xu , NeilBrown , Shakeel Butt , Michal Hocko , Yu Zhao , Dave Chinner Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A802C2000E X-Rspam-User: X-Stat-Signature: ct1efwz3mm69mo53a8pphrhtuy8nxxxe X-HE-Tag: 1680246507-827211 X-HE-Meta: U2FsdGVkX1+VX2MkW7HWx+Kjd3khq+bjEEg/QkCsF4vCPhn5a0cPmCNXJusAQZTNo9wZTs1YUwBiypCSVbbx3woCBD9DUcDO47QOi9bfkCQ/OOwwPtTnE1V75KnY+m+99HRkz9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9UOWHcxTepofSYzmCSfFYVSSSfT3L2XU+HWjRupOGuwQFIKJuhJyklCdd/8JeECKPxvd1EQhlZQC8KgYlYjoHT5pqGUcWABif4Ayyz6U/UwFXF3FIChmkDRsupmVwr+38HnSqblQFWdz2cpcOj1mBkpVAch9oAZ+XK0BKdcW+o/atEiplvMbt6zCw7i8dMTinnp2VOTRxutGbOmOZ4kiwklGPDWfiR5Bma/aqAJuAboe5m9l+bqug4W1myEZzbNevSWcbtAg4RGT/6hxBLV4lqiTA7dzHle+qqfqII4661oZYzR7o/LdQQ6EuFLfP02sYuc5vDxqbPj93EZdMA1pspmXuFdUOxIUAytzS3VntS85Ib1Ck6p/jzucLY7KwUDyFHzCm1FtBpQIyP4TA/+OYQeKHaF6faIZCEaOTZZy7cdjOgMj/8jIoOOK2D6HPg4NiSQY4BLPnIYJJd1RUIOxYcqU5O5IUy/ZEjaD49N98ePp+WnJKkVWn0oBjvLkk 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: We keep track of different types of reclaimed pages through reclaim_state->reclaimed, and we add them to the reported number of reclaimed pages. For non-memcg reclaim, this makes sense. For memcg reclaim, we have no clue if those pages are charged to the memcg under reclaim. Slab pages are shared by different memcgs, so a freed slab page may have only been partially charged to the memcg under reclaim. The same goes for clean file pages from pruned inodes (on highmem systems) or xfs buffer pages, there is no simple way to currently link them to the memcg under reclaim. Stop reporting those freed pages as reclaimed pages during memcg reclaim. This should make the return value of writing to memory.reclaim, and may help reduce unnecessary reclaim retries during memcg charging. Generally, this should make the return value of try_to_free_mem_cgroup_pages() more accurate. In some limited cases (e.g. freed a slab page that was mostly charged to the memcg under reclaim), the return value of try_to_free_mem_cgroup_pages() can be underestimated, but this should be fine. The freed pages will be uncharged anyway, and we can charge the memcg the next time around as we usually do memcg reclaim in a retry loop. Signed-off-by: Yosry Ahmed --- mm/vmscan.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index a3e38851b34ac..bf9d8e175e92a 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -533,7 +533,35 @@ EXPORT_SYMBOL(mm_account_reclaimed_pages); static void flush_reclaim_state(struct scan_control *sc, struct reclaim_state *rs) { - if (rs) { + /* + * Currently, reclaim_state->reclaimed includes three types of pages + * freed outside of vmscan: + * (1) Slab pages. + * (2) Clean file pages from pruned inodes. + * (3) XFS freed buffer pages. + * + * For all of these cases, we have no way of finding out whether these + * pages were related to the memcg under reclaim. For example, a freed + * slab page could have had only a single object charged to the memcg + * under reclaim. Also, populated inodes are not on shrinker LRUs + * anymore except on highmem systems. + * + * Instead of over-reporting the reclaimed pages in a memcg reclaim, + * only count such pages in system-wide reclaim. This prevents + * unnecessary retries during memcg charging and false positive from + * proactive reclaim (memory.reclaim). + * + * For uncommon cases were the freed pages were actually significantly + * charged to the memcg under reclaim, and we end up under-reporting, it + * should be fine. The freed pages will be uncharged anyway, even if + * they are not reported properly, and we will be able to make forward + * progress in charging (which is usually in a retry loop). + * + * We can go one step further, and report the uncharged objcg pages in + * memcg reclaim, to make reporting more accurate and reduce + * under-reporting, but it's probably not worth the complexity for now. + */ + if (rs && !cgroup_reclaim(sc)) { sc->nr_reclaimed += rs->reclaimed; rs->reclaimed = 0; }