From patchwork Thu Jul 20 07:08:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13319870 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 1D41CEB64DC for ; Thu, 20 Jul 2023 07:08:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 59A9A2800C1; Thu, 20 Jul 2023 03:08:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4AE7728004C; Thu, 20 Jul 2023 03:08:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3004F2800C1; Thu, 20 Jul 2023 03:08:42 -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 168BC28004C for ; Thu, 20 Jul 2023 03:08:42 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D3396801A7 for ; Thu, 20 Jul 2023 07:08:41 +0000 (UTC) X-FDA: 81031112442.29.13D65C6 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf28.hostedemail.com (Postfix) with ESMTP id 11FA8C0006 for ; Thu, 20 Jul 2023 07:08:39 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=oBM+gyrv; spf=pass (imf28.hostedemail.com: domain of 3d924ZAoKCEI2swv2elqihksskpi.gsqpmry1-qqozego.svk@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3d924ZAoKCEI2swv2elqihksskpi.gsqpmry1-qqozego.svk@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=1689836920; 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=YhI2s0e+GIGqReCnHtRMQPrzSnIqjbw1XBQvBPYjKY0=; b=UalIofI8VJRD7tk9+FUreVDaWdcTvr6FmJYbnnlJ6s3Xdr80LS/LAr02gkPHATXgiLcPd2 WUaJnlQzGw5UnKIhWgJJO0nPj7/gc464kExxpf2IPsWIiqxa6kUQcE6JGFxBedZlJO4yi4 TU/brGufLmJ6C9bcIJ7GJCLGZ0h8Ucg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689836920; a=rsa-sha256; cv=none; b=ekEgAVlN7cE4vrExkUMt9uNRBCRGZSKz1E03Ln6R/0NuuGdQfRqLfVWPPpv1RAH3vjGV3u TcSh8M1Y8THxIzhjFXaIPlGTOBQopxtFNSxrRfunbaSPn4eqeE499hQhy1X08nBICr55pc BETeCe2I+qmNwLBgJmJ18wlqj2AiuKg= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=oBM+gyrv; spf=pass (imf28.hostedemail.com: domain of 3d924ZAoKCEI2swv2elqihksskpi.gsqpmry1-qqozego.svk@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3d924ZAoKCEI2swv2elqihksskpi.gsqpmry1-qqozego.svk@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-cac213f9264so458663276.3 for ; Thu, 20 Jul 2023 00:08:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689836919; x=1692428919; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YhI2s0e+GIGqReCnHtRMQPrzSnIqjbw1XBQvBPYjKY0=; b=oBM+gyrvc4kZmfzCDqqW014mddb+6ng6aUJcvm1PGzKPmmatk8vBmxnaO+jvawg8Cc cf0h8c+uRGKv+PpUjZOjju465YCs/RMkGS7FOfpfBg905u8KA48PZPv9pv5l5xU64hAu RRIbJwf2dG4G9KtiFyA18EerxfR/ghn9NkJLcaUskUA8yTC4t3T0XaugdSZxINO7vhKx oM7NXvmkzb7JDGBaiO8CTn60src/z33GmAEJWb+ZSh6IMofXorSGDhYJD6lnOVdfNi/O 3BRMWtylTLjUhnMgpCj7SaSMPCTWyEH1d0Cr6gcddMeYKbX7Wxwr5jKmhdVPpppLRUDQ nHOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689836919; x=1692428919; 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=YhI2s0e+GIGqReCnHtRMQPrzSnIqjbw1XBQvBPYjKY0=; b=fRcKK/GjIUWKOLtqdMJ3SySbwJf2LXFRYcSjexycwWWSXFKV42QAuC79Ug42WjnH/q dwgPrsnXlFRZMfyo6cWy+zVVFmfgcYCE3ESZW9OuFETaIAyuHGcsFkyQBvv5KmPcMhRa FcIglJhgiT+iF8hZo41/V/InBpxjL8Msmpzb2pJsiA2xIxOjU5Q3YyTgIKj2RVIBvdMf RX+z+T0Sun4MSI0HURtRGRyEKvnjSIU3sxaSJGrD8LpoxVTBs9VNuBpecfiq8xoeLIrm niNob31Z//o/rX2ba+f2ZjHND9wdUj5vHO4Glt3RBvLkpSdfg3nT2LyNCnr6p24OT2lH ZJxA== X-Gm-Message-State: ABy/qLYkMEY1rdU4Q1w4QXo+MrePHWsyuwW7+Eleo3KjPUbrd8WWa6pI T+SrATbSmETZd6ToSj/WK4+TCFq7s0M3L6FD X-Google-Smtp-Source: APBJJlF2n+4mQLRSUDirJE55LlRkKhJrzGh/hC5rHcN/nPwLMBMZVZTXUQayuWTk1KX2FFq+vwWoN66wVm+m0JP7 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a25:ab04:0:b0:bfe:ea69:91b4 with SMTP id u4-20020a25ab04000000b00bfeea6991b4mr36455ybi.4.1689836919167; Thu, 20 Jul 2023 00:08:39 -0700 (PDT) Date: Thu, 20 Jul 2023 07:08:23 +0000 In-Reply-To: <20230720070825.992023-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230720070825.992023-1-yosryahmed@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230720070825.992023-7-yosryahmed@google.com> Subject: [RFC PATCH 6/8] memcg: add stats for offline memcgs recharging From: Yosry Ahmed To: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt Cc: Muchun Song , "Matthew Wilcox (Oracle)" , Tejun Heo , Zefan Li , Yu Zhao , Luis Chamberlain , Kees Cook , Iurii Zaikin , "T.J. Mercier" , Greg Thelen , linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, Yosry Ahmed X-Rspamd-Queue-Id: 11FA8C0006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 4ubi74f97cy9sj9i4uwndgfuqkjsgis4 X-HE-Tag: 1689836919-560650 X-HE-Meta: U2FsdGVkX18Z9t3qdv5Et/2d0bGpJg8k7oJ6IS9MeDleD2cTuzalc0dU3FnB5HZAwNZg6m1iE1srSqD/CbYC1FIu58wex8qT65I110hNgPOj6jz9qumUV07GLJ5ykDbCurdPGdiudLUwX2fM5MUhPky39LiVgG5wTSx/ogW6XXCO1ZO9gIdE3PEflREdBCo2HOVTj5OCKCDFecGpezYbU6YrsQb+BQr9l5QwGPklDbwhtoa2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6K0WpirS/k80T0RY1u+fTZXWbtY1qORNnw/p/AA5XYTLnr3G2tin9QrDsw6DVsOvs6cPAzvelli5XCKrjbOOBXBsoHxwqRAx6wFcq2sG6rOvTh3aUHH9GaoGowEQXwZlevafun+v08ZYo80ZJSTwnV1ViCCZuIK/65t4BAzFVA3lKw9CYJCl3Saj/1WqjKLN7LHDSUdr4AO31PcJkEZ4SDo7xZlQXeLMEZPZibUp8b9meBOUvRW72C3LAkgu1QoHK5UDXnOA8lJ7KXSx42fp6q5nHZBbmxfggzk9EfraqC1RnqVHSRq/FUk+9KR0= 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: Add vm events for scanning pages for recharge, successfully recharging pages, and cancelling a recharge due to failure to charge the target memcg. Signed-off-by: Yosry Ahmed --- include/linux/vm_event_item.h | 5 +++++ mm/memcontrol.c | 6 ++++++ mm/vmstat.c | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h index 8abfa1240040..cd80c00c50c2 100644 --- a/include/linux/vm_event_item.h +++ b/include/linux/vm_event_item.h @@ -60,6 +60,11 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, PAGEOUTRUN, PGROTATED, DROP_PAGECACHE, DROP_SLAB, OOM_KILL, +#ifdef CONFIG_MEMCG + RECHARGE_PGSCANNED, + RECHARGE_PGMOVED, + RECHARGE_PGCANCELLED, +#endif #ifdef CONFIG_NUMA_BALANCING NUMA_PTE_UPDATES, NUMA_HUGE_PTE_UPDATES, diff --git a/mm/memcontrol.c b/mm/memcontrol.c index cf9fb51ecfcc..2fe9c6f1be80 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6394,6 +6394,8 @@ static bool mem_cgroup_recharge_folio(struct folio *folio, old_memcg, new_memcg); cancel_charge(err ? new_memcg : old_memcg, nr_pages); out: + count_vm_events(err ? RECHARGE_PGCANCELLED : RECHARGE_PGMOVED, + nr_pages); return err == 0; } @@ -6469,6 +6471,7 @@ static bool memcg_recharge_lruvec_list(struct lruvec *lruvec, int isolated_idx = NR_ISOLATED_ANON + is_file_lru(lru); struct mem_cgroup *memcg = lruvec_memcg(lruvec); unsigned long *nr_recharged = arg; + unsigned long nr_scanned = 0; unsigned long nr_staged = 0; LIST_HEAD(folios_skipped); LIST_HEAD(folios_staged); @@ -6505,6 +6508,7 @@ static bool memcg_recharge_lruvec_list(struct lruvec *lruvec, continue; } + nr_scanned += folio_nr_pages(folio); if (unlikely(!folio_try_get(folio))) { list_move(&folio->lru, &folios_skipped); continue; @@ -6543,6 +6547,7 @@ static bool memcg_recharge_lruvec_list(struct lruvec *lruvec, } mem_cgroup_end_move_charge(memcg); mod_lruvec_state(lruvec, isolated_idx, -nr_staged); + count_vm_events(RECHARGE_PGSCANNED, nr_scanned); return false; } @@ -6679,6 +6684,7 @@ void folio_memcg_deferred_recharge(struct folio *folio) if (unlikely(!memcg_recharge_wq)) return; + count_vm_events(RECHARGE_PGSCANNED, folio_nr_pages(folio)); if (unlikely(!folio_try_get(folio))) return; diff --git a/mm/vmstat.c b/mm/vmstat.c index b731d57996c5..e425a1aa7890 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1303,7 +1303,11 @@ const char * const vmstat_text[] = { "drop_pagecache", "drop_slab", "oom_kill", - +#ifdef CONFIG_MEMCG + "recharge_pgs_scanned", + "recharge_pgs_moved", + "recharge_pgs_cancelled", +#endif #ifdef CONFIG_NUMA_BALANCING "numa_pte_updates", "numa_huge_pte_updates",