From patchwork Thu Mar 9 09:31:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13167120 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 D0C0CC6FD1F for ; Thu, 9 Mar 2023 09:31:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66198280004; Thu, 9 Mar 2023 04:31:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 610526B0078; Thu, 9 Mar 2023 04:31:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D81B280004; Thu, 9 Mar 2023 04:31:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3F0E36B0075 for ; Thu, 9 Mar 2023 04:31:39 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 085BCA0652 for ; Thu, 9 Mar 2023 09:31:39 +0000 (UTC) X-FDA: 80548842318.12.6939E7A Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf25.hostedemail.com (Postfix) with ESMTP id 517D8A0015 for ; Thu, 9 Mar 2023 09:31:36 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Ze5OIdzu; spf=pass (imf25.hostedemail.com: domain of 3d6cJZAoKCBQI8CBIu16yx08805y.w86527EH-664Fuw4.8B0@flex--yosryahmed.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3d6cJZAoKCBQI8CBIu16yx08805y.w86527EH-664Fuw4.8B0@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=1678354296; 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=LEwBMGSn5GpbGlanBqXFsfdHu3Z53NaeJ1a3nMwnQiU=; b=kRu2Cj2Iduke9VWWL3Ix3OHdHbFPIzLMnbSkgl+U1pFyIAZX4ofH23RKL2xa5pQVkhTcoS s3L+/8BVXSUBpa0J7sMqdKyjTPoAGaXLhZFpB7fZ6kWbrP2xz0iixXjSykqUbw3bCndv6i nQSDwyRekwxKQG7rZUYvYaVKwWtJZQo= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Ze5OIdzu; spf=pass (imf25.hostedemail.com: domain of 3d6cJZAoKCBQI8CBIu16yx08805y.w86527EH-664Fuw4.8B0@flex--yosryahmed.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3d6cJZAoKCBQI8CBIu16yx08805y.w86527EH-664Fuw4.8B0@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678354296; a=rsa-sha256; cv=none; b=bqyoZtMyuV7J5Skd651ouFiNxseQC+uZ7yhjAifW+qU4ZoRg0oyAH/C6CRm9UfLpL+JxeI 9noVY2LbMnLbROVcwlufmygsGRzwh7ZZNMwCoAXGIdcRyC0u1obE6NmrqbWBzwtU0cD01L 0n8dAsPPTG11ffT5fve3DfrX6inJV94= Received: by mail-pl1-f201.google.com with SMTP id s15-20020a170902ea0f00b0019d0c7a83dfso821415plg.14 for ; Thu, 09 Mar 2023 01:31:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678354295; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LEwBMGSn5GpbGlanBqXFsfdHu3Z53NaeJ1a3nMwnQiU=; b=Ze5OIdzu8ujFo9cbq83YqFk9GJOpYr3a3BQKfOSfr4rWI6Yo1wqOYG0VZvkRQl/DgU ONZDb780V2AJLPqQWE3i1IZDOj2DrlnYx2p9SESApSRJk73I5fI+TzBG7cY4phGhOfvE fsxBi+Mbo+Sti9UuMrxl9QnG0QjPUVEa7+s1cz+Q3wYagCiAWB2+bxT6WbOhwW63YCyL vx4QV8MkTkeQi+EJ1ehIcECB6ITq43CvVn8IyyqwmqR4ySJXDiat0u00fzVgzef7Kjx0 9ui6RevSQ/etQzip+tetVSB6hNPcbI8D0n9SoMlj9xGPz0n+yHL+qWibozRsuDEXX+zi /5CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678354295; 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=LEwBMGSn5GpbGlanBqXFsfdHu3Z53NaeJ1a3nMwnQiU=; b=EGs+S0pwpyvdmzu4tlS5F6SRgflL5TPhjwfnUKbGsG28tw40b9hoUA5SuW08gra+fp Zq6zWTo0ZCK4KrGo3da+VHfBkKkLyOSfnd7SjyCGMUpsgPvdD4TYrnsGWp653JKh5biB hx3v9p1nPaLpIL30qHTfPku34g/3XZXPgdmxijk+c/kHNlBmGPzAQgUgpLtOyQcYauDN d2deCvW0JCWxnuhVd7SEAcnY9B2KVkce5x2UVx/00/xgoNcykRnQbIeFOLpFyXaniBo5 3jgit4m/B4cDA18IgIYMkMFoOQPM5mn7vTy2SEBspYXcmEhICD/waubKAhs58eapu9eN 36SA== X-Gm-Message-State: AO0yUKWA0JlNAWtYBNpAHzlX6NW+3JxUg5Z9daBKcw9V++25snJIg9VM eU31GjrskvIX1+tcjTTTUBHcSUiNOTvDe5kJ X-Google-Smtp-Source: AK7set/0zSElUk4SV6Jx9e5eK8m600vzb0RCF1MUNHWJepBbU4SjCTMuv6lVZNxTeTFxx/o7bLiMKSNeOfppeLHP X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a63:2953:0:b0:502:ecb9:4f23 with SMTP id bu19-20020a632953000000b00502ecb94f23mr7361890pgb.5.1678354295295; Thu, 09 Mar 2023 01:31:35 -0800 (PST) Date: Thu, 9 Mar 2023 09:31:09 +0000 In-Reply-To: <20230309093109.3039327-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230309093109.3039327-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230309093109.3039327-4-yosryahmed@google.com> Subject: [PATCH v2 3/3] mm: vmscan: ignore non-LRU-based reclaim in memcg reclaim From: Yosry Ahmed To: 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 Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 517D8A0015 X-Stat-Signature: un4jc8i4sjnbux3dbw1biw6hsetcas9p X-HE-Tag: 1678354296-872574 X-HE-Meta: U2FsdGVkX1/rn7lg8sL3fHe+I4+WKjNzqJmitSSbntTINzp3dh5+rLTLY1G6PTx5E0Qf2fMawbqskzFB98P0UgPaXz9jq6mcR+PuNFNl747y1VZ5Nmky2rLnkibNlpH5DOPTFTJ7fy7RkW7KlLWB8NJw6OFZNRL1oLb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B+nrTe4zUOVV7RkwpTSRTyZWFjCyS2dc9KNM9qx2DTGbPcq3KruTTkpflbN23PrNaWLeZpBQ14MET2Xf1o8B1X0xMb79r5/ApqfsqEZXarTC3h1ld38Y8Gjg4I+46J7maBOfMVW0YS5CnJ5ujTYz2WD33gCBrw+hB5ZbH4d5Xpr6iGjGr/e1eaxaNwCaYcE83LElE44rjdeX2rcbdkrejMKp7E8JffwBPD8j2hrpcbxZy/nRdDNs5qoYRMGZ1AUr7Wo7oA6edsl/AkpC/p2QTdTtDMew9P9O5/+u20s8UqrM9nKaEa07+gtqFib+HW+Ky/L3RbZ0wlYD2qrtZfT0CBId4UEcqS3/y6XX6kEWZS1NL4ZM6YBNcIPf8EQy2EhJfniDwZWHov8Aa2pN2fN+An1Og1S9b/ZgdSrdLPKlPfE2PDkN4eKrVRmmn3HW5MDodbS3GI2qKRgelkBgCQi+mHM27O/PU7yJCWp1tMjHPEL5YgmyqO 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 a3e38851b34a..bf9d8e175e92 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; }