From patchwork Tue Apr 4 00:13:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13198933 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 C8D5AC77B62 for ; Tue, 4 Apr 2023 00:14:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4627E900004; Mon, 3 Apr 2023 20:14:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EC29900002; Mon, 3 Apr 2023 20:14:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2654C900004; Mon, 3 Apr 2023 20:14:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0ABF3900002 for ; Mon, 3 Apr 2023 20:14:05 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D61161C61A9 for ; Tue, 4 Apr 2023 00:14:04 +0000 (UTC) X-FDA: 80641786008.17.5D98DF1 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf22.hostedemail.com (Postfix) with ESMTP id ED65DC000F for ; Tue, 4 Apr 2023 00:14:02 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=W5WukSX7; spf=pass (imf22.hostedemail.com: domain of 3yWsrZAoKCHYsimlsUbgYXaiiafY.Wigfchor-ggepUWe.ila@flex--yosryahmed.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3yWsrZAoKCHYsimlsUbgYXaiiafY.Wigfchor-ggepUWe.ila@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=1680567243; 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=QYyKpmgAe3S55Nk5FWRs2dH0UIocesat7xjNxdFTU4k=; b=MJGhdWYfUfpnAHooGMQvzVuGqWW3SYC3YluA2tTHHHunuGQbDCLQtKERs8mfyW6FdCpcIc jc32MkFS2nIeFS5pH9lVnzeJaf+Jp+cEjTLxdHh7cPpBuCUXz/M9wSvwklVoL72Ht6kxhZ 4WbBJKviyn/kl58TSxXV+uEBZOC0iC0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=W5WukSX7; spf=pass (imf22.hostedemail.com: domain of 3yWsrZAoKCHYsimlsUbgYXaiiafY.Wigfchor-ggepUWe.ila@flex--yosryahmed.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3yWsrZAoKCHYsimlsUbgYXaiiafY.Wigfchor-ggepUWe.ila@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680567243; a=rsa-sha256; cv=none; b=PdCRavqt8om4BBYJm/4QEIRKvTptMlIYchT51TF5U0sFjw2FPY+eyrD54D0m+fpc6Aot7X 0B32YCVSGGhJGL72NSg/Dv8g1v8RaPdXqoiVDnTFRWXxRhxY+PrTNabic+2Ktmx79/srlo 5uWSWcqNgMyaXA14c6FCN5hseEvKyMo= Received: by mail-pf1-f202.google.com with SMTP id y15-20020a62f24f000000b00627dd180a30so13896551pfl.6 for ; Mon, 03 Apr 2023 17:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680567242; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QYyKpmgAe3S55Nk5FWRs2dH0UIocesat7xjNxdFTU4k=; b=W5WukSX7xVU0/vv5ALD+tup9Pddeb9Iipi9kb8kJt/jBn+TQTiZoJyEWgKO/OQ61Jh 2tDeM9kRzvnDYGPtmMlhz5iVehjZJg/jQ63YFUQ7WbbPKq0AY2cM2cHrwogahpd+PgEG XwtqC+dGnvs0z0/3t8FCcMDB2O7fMVf3H3E2qFVcjwb9hPLZO3zgEa2XrTMXRi9MFCHf WEtCE6c9sD8f7AqxvmgV8c+yt8qmrF2I9lAqEvjVuhsI1HciUBrepOGZet31fNCDDW8P oX+wUwY7aO9vBuigwgimgUP/rKThFLYxYAVKIiGShyp9evKm8iqS6ChI4jTiXqDaT7MQ ct3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680567242; 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=QYyKpmgAe3S55Nk5FWRs2dH0UIocesat7xjNxdFTU4k=; b=S8FrFVy11jgkXcQ5QsS+mWquzaboQalWpH1bjnYDY2M24lyiBIQHokdoc91SbOOYSz EqkPr6f2zZ50WxDXzvysClTAK8mK5boXFYRvTXrFbIB7nWTKuBH9EPJU2LcbMWwBJhPg IGMHJeXc+9kPsIaBBz9qPF+Vtyra9p95b+nkHx/v/uuvn9U+hJ0PDUqfZKPCqUj8ZPLe jgSJ9QI9asCyhc0qsHc518+elCJm6XMDDad260YG4L9JoeDTXIy9CsWgwlsOZijIgpfA E/dyGYOeHNeyfIzjCYA/Ogu3CSxlF77fEjYmuPQNPtVqgFm8vZ4AAVsWpimZfZs0T+k4 sI0Q== X-Gm-Message-State: AAQBX9cP/xyR7iZW+b8z8PHSFNLrdmKJOQgeQr5J+YnqA1/WK/6vbuOt R7d26KA1sXnIUyn20aVcRRwMgrSxAY5tEB4S X-Google-Smtp-Source: AKy350a8jpmup3Y0AoRXTeOyKKcgC2LVL+csu37K+C5/P3dMmovoTexr82+Hd4O52pTXV8PmQrABJAtIr5EvWJJc X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a05:6a00:2e14:b0:627:e6d5:ba2d with SMTP id fc20-20020a056a002e1400b00627e6d5ba2dmr223605pfb.6.1680567241767; Mon, 03 Apr 2023 17:14:01 -0700 (PDT) Date: Tue, 4 Apr 2023 00:13:53 +0000 In-Reply-To: <20230404001353.468224-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230404001353.468224-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230404001353.468224-4-yosryahmed@google.com> Subject: [PATCH v4 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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: ED65DC000F X-Stat-Signature: q7y8jcw7kn1eocnorcpnjy788byu5k7y X-HE-Tag: 1680567242-359231 X-HE-Meta: U2FsdGVkX1/bdgVrY9WanEp9Hm4Z0nNHwDTOh866htY7Bxz8q1BB492pfoLa/kL1qpAlsU25CJAkBElJ6xk5U7Wg2EGPKRMYxLeZZWL53ZGdvI3aDQN4RI0HjIYQrk7lxQF/bqdblKeTN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MwlIj8HqV+dNNFaf6PHsq59aimItLUVQ1ipWmwNon9HYobdWVA/4C+/vl5pifVrROUXMRTIj5XH5O8F/Min2iaqBAQVOTEMHsjAZrkP8iHuSeBx+xcgZt2JQOBoZS8SQP9jQYgCpTQscuHeIQoL2IoSqYB9Ix7RQKNPhlc8pzNpinFbUsfqvM7EGJgKCiSSrqhOQlU4p7/1ltE1++iDqBGGwgLd/Ght9CTamSq0sGO8R6mZulGxX5eGgraPSRio69DStGVMYcgqnRWWUR+BEryPsuF0oK/7kD5KqPXAhQyDS4+HtCXJMBQop0WpXvd7dNQ/UJCEaDymyA+Lg1cPmkAACiB6u18YGRUTW/nKzWXZ4c/wmCmKmwdzf/l2TyQ+wQzBWnlI6x/riUa4oBdoHfoKK+vo7N4WHx1Jp/7E1uLv9BW7YyXf8dknvBTI49mymt4O8O+UGrVHpgKQnwNRct/yz0sCzepPyybxS66z/Ek+n0MEKquaOVZ+JfeRl 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. Writing to memory.reclaim on the root memcg is considered as cgroup_reclaim(), but for this case we want to include any freed pages, so use the global_reclaim() check instead. 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 8f0e7c4e91ae3..049e39202e6ce 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -518,7 +518,35 @@ static void set_task_reclaim_state(struct task_struct *task, 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 global 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 && global_reclaim(sc)) { sc->nr_reclaimed += rs->reclaimed; rs->reclaimed = 0; }